Skip to content

Commit 6b2463f

Browse files
authored
feat: support multiple languages (conwnet#616)
1 parent e5f22e9 commit 6b2463f

19 files changed

Lines changed: 140 additions & 51 deletions

.github/workflows/test-wtih-vscode-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
node-version: ${{ matrix.node-version }}
2727

2828
- run: npm install && cd vscode-web && npm install
29-
- run: cd vscode-web && npm run clone && npm run build
30-
- run: npm run link & npm run build
29+
- run: cd vscode-web && npm run build
30+
- run: npm run link && npm run build
3131
- uses: microsoft/playwright-github-action@v1
3232
- run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} npm run test:ci

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"license": "ISC",
3131
"devDependencies": {
3232
"@cloudflare/workers-types": "^4.20250109.0",
33-
"@github1s/vscode-web": "^0.23.1",
33+
"@github1s/vscode-web": "0.23.2",
3434
"chokidar": "^4.0.3",
3535
"clean-css": "^5.3.3",
3636
"copy-webpack-plugin": "^12.0.2",

scripts/build.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import path from 'path';
44
import fs from 'fs-extra';
55
import cp from 'child_process';
6-
import { PROJECT_ROOT } from './utils.js';
6+
import { executeCommand, PROJECT_ROOT } from './utils.js';
77

88
const main = () => {
99
for (const extension of fs.readdirSync('extensions')) {
1010
const extensionPath = path.join(PROJECT_ROOT, 'extensions', extension);
1111
if (fs.existsSync(path.join(extensionPath, 'package.json'))) {
12-
cp.spawnSync('npm', ['run', 'compile'], { cwd: extensionPath, stdio: 'inherit' });
12+
executeCommand('npm', ['run', 'compile'], extensionPath);
1313
}
1414
}
15-
cp.spawnSync('npx', ['webpack', '--mode=production'], { cwd: PROJECT_ROOT, stdio: 'inherit' });
15+
executeCommand('npx', ['webpack', '--mode=production'], PROJECT_ROOT);
1616
};
1717

1818
main();

scripts/link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import path from 'path';
44
import cp from 'child_process';
5-
import { PROJECT_ROOT } from './utils.js';
5+
import { executeCommand, PROJECT_ROOT } from './utils.js';
66

77
const main = () => {
88
const distPath = path.join(PROJECT_ROOT, 'vscode-web/dist');
9-
cp.spawnSync('npm', ['link'], { cwd: distPath, stdio: 'inherit' });
10-
cp.spawnSync('npm', ['link', '@github1s/vscode-web'], { cwd: PROJECT_ROOT, stdio: 'inherit' });
9+
executeCommand('npm', ['link'], distPath);
10+
executeCommand('npm', ['link', '@github1s/vscode-web'], PROJECT_ROOT);
1111
};
1212

1313
main();

scripts/postinstall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import path from 'path';
44
import fs from 'fs-extra';
55
import cp from 'child_process';
6-
import { PROJECT_ROOT } from './utils.js';
6+
import { executeCommand, PROJECT_ROOT } from './utils.js';
77

88
const main = () => {
99
const extensions = fs.readdirSync(path.join(PROJECT_ROOT, 'extensions'));
1010
for (const extension of extensions) {
1111
const extensionPath = path.join(PROJECT_ROOT, 'extensions', extension);
12-
cp.spawnSync('npm', ['install', '--no-save'], { cwd: extensionPath, stdio: 'inherit' });
12+
executeCommand('npm', ['install', '--no-save'], extensionPath);
1313
}
1414
};
1515

scripts/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import path from 'path';
2+
import cp from 'child_process';
23

34
export const PROJECT_ROOT = path.join(import.meta.dirname, '..');
5+
6+
export const executeCommand = (command, args, cwd) => {
7+
const result = cp.spawnSync(command, args, { stdio: 'inherit', cwd });
8+
if (result.error) {
9+
throw result.error;
10+
}
11+
};

src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare const DEV_VSCODE: boolean;
1010
declare const GITHUB_ORIGIN: string;
1111
declare const GITLAB_ORIGIN: string;
1212
declare const GITHUB1S_EXTENSIONS: string;
13+
declare const AVAILABLE_LANGUAGES: string[];
1314

1415
/* eslint-disable no-var */
1516
declare var dynamicImport: (url: string) => Promise<any>;

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ globalThis._VSCODE_WEB = {
5858

5959
if (!DEV_VSCODE) {
6060
const linkElement = document.createElement('link');
61-
linkElement.rel = 'stylesheet';
62-
linkElement.href = resolveVscodeUrl('vs/workbench/workbench.web.main.css');
61+
linkElement.setAttribute('rel', 'stylesheet');
62+
linkElement.setAttribute('href', resolveVscodeUrl('vs/workbench/workbench.web.main.css'));
6363
document.head.appendChild(linkElement);
6464

65+
const languageId = document.cookie.match(/(^| )vscode.nls.locale=([^;]+)/)?.[2] || '';
66+
const nlsUrl = AVAILABLE_LANGUAGES.includes(languageId)
67+
? resolveVscodeUrl(`../nls/${languageId}/nls.messages.js`)
68+
: resolveVscodeUrl('nls.messages.js');
6569
const scriptElement = document.createElement('script');
66-
scriptElement.type = 'text/javascript';
67-
scriptElement.src = resolveVscodeUrl('nls.messages.js');
70+
scriptElement.setAttribute('src', nlsUrl);
6871
document.body.appendChild(scriptElement);
6972
}
7073

vscode-web/index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
6-
<title>VSCode Web</title>
7-
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
8-
<link rel="stylesheet" href="/vscode/vs/workbench/workbench.web.main.css" />
6+
<title>VSCode Web</title>
7+
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
8+
<link rel="stylesheet" href="/vscode/vs/workbench/workbench.web.main.css" />
99
</head>
1010
<body>
1111
<script src="/vscode/nls.messages.js"></script>
12-
<script>
13-
globalThis._VSCODE_FILE_ROOT = new URL('/vscode/', window.location.origin).toString();
14-
</script>
15-
<script type="module">
16-
import { create, URI } from '/vscode/vs/workbench/workbench.web.main.internal.js';
17-
create(document.body, {
18-
webviewEndpoint: '/vscode/vs/workbench/contrib/webview/browser/pre',
19-
workspaceProvider: {
20-
workspace: { workspaceUri: URI.from({ scheme: 'tmp', path: '/default.code-workspace' }) },
21-
},
22-
});
23-
</script>
12+
<script>
13+
globalThis._VSCODE_FILE_ROOT = new URL('/vscode/', window.location.origin).toString();
14+
</script>
15+
<script type="module">
16+
import { create, URI } from '/vscode/vs/workbench/workbench.web.main.internal.js';
17+
create(document.body, {
18+
webviewEndpoint: '/vscode/vs/workbench/contrib/webview/browser/pre',
19+
workspaceProvider: {
20+
workspace: { workspaceUri: URI.from({ scheme: 'tmp', path: '/default.code-workspace' }) },
21+
},
22+
});
23+
</script>
2424
</body>
2525
</html>

0 commit comments

Comments
 (0)