Skip to content

Commit 83f86a4

Browse files
committed
Load language bundles on the client
1 parent 45ad7f0 commit 83f86a4

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ Our changes include:
119119
- Change a regular expression used for mnemonics so it works on Firefox.
120120
- Make it possible for us to load code on the client.
121121
- Modify the build process to include our code.
122-
- Fix a CSP issue within a webview.
122+
- Fix a CSP issue within webviews.
123123
- Fix an issue displaying extension contributions.
124+
- Make changing the display language work.
124125

125126
## License
126127
[MIT](LICENSE)

scripts/vscode.patch

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,40 @@ index 5b06636edb..60b508079a 100644
174174
<!-- Require our AMD loader -->
175175
<script src="./out/vs/loader.js"></script>
176176
diff --git a/src/vs/code/browser/workbench/workbench.js b/src/vs/code/browser/workbench/workbench.js
177-
index 65fae7c82d..9a9b8bbe3b 100644
177+
index 65fae7c82d..a1974cd941 100644
178178
--- a/src/vs/code/browser/workbench/workbench.js
179179
+++ b/src/vs/code/browser/workbench/workbench.js
180-
@@ -7,21 +7,26 @@
180+
@@ -7,21 +7,52 @@
181181

182182
(function () {
183183

184184
+ const basePath = window.location.pathname.replace(/\/+$/, '');
185185
+ const base = window.location.origin + basePath;
186+
+
187+
+ let nlsConfig;
188+
+ try {
189+
+ nlsConfig = JSON.parse(document.getElementById('vscode-remote-nls-configuration').getAttribute('data-settings'));
190+
+ if (nlsConfig._resolvedLanguagePackCoreLocation) {
191+
+ const bundles = Object.create(null);
192+
+ nlsConfig.loadBundle = (bundle, language, cb) => {
193+
+ let result = bundles[bundle];
194+
+ if (result) {
195+
+ return cb(undefined, result);
196+
+ }
197+
+ // FIXME: Only works if path separators are /.
198+
+ const path = nlsConfig._resolvedLanguagePackCoreLocation
199+
+ + '/' + bundle.replace(/\//g, '!') + '.nls.json';
200+
+ fetch(`${base}/resources/fetch?u=${JSON.stringify({ path })}`)
201+
+ .then((response) => response.json())
202+
+ .then((json) => {
203+
+ bundles[bundle] = json;
204+
+ cb(undefined, json);
205+
+ })
206+
+ .catch(cb);
207+
+ };
208+
+ }
209+
+ } catch (error) { /* Probably fine. */ }
210+
+
186211
require.config({
187212
- baseUrl: `${window.location.origin}/out`,
188213
+ baseUrl: `${base}/out`,
@@ -196,13 +221,15 @@ index 65fae7c82d..9a9b8bbe3b 100644
196221
- 'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
197222
- 'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
198223
- 'semver-umd': `${window.location.origin}/node_modules/semver-umd/lib/semver-umd.js`,
224+
- }
199225
+ 'vscode-textmate': `${base}/node_modules/vscode-textmate/release/main`,
200226
+ 'onigasm-umd': `${base}/node_modules/onigasm-umd/release/main`,
201227
+ 'xterm': `${base}/node_modules/xterm/lib/xterm.js`,
202228
+ 'xterm-addon-search': `${base}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
203229
+ 'xterm-addon-web-links': `${base}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
204230
+ 'semver-umd': `${base}/node_modules/semver-umd/lib/semver-umd.js`,
205-
}
231+
+ },
232+
+ 'vs/nls': nlsConfig
206233
});
207234

208235
require(['vs/workbench/workbench.web.api'], function (api) {

src/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ export class MainServer extends Server {
443443
): Promise<Response> {
444444
switch (base) {
445445
case "/": return this.getRoot(request, parsedUrl);
446+
case "/resources":
446447
case "/vscode-resources":
447448
if (requestPath === "/fetch") {
449+
if (typeof parsedUrl.query.u === "string") {
450+
return this.getResource(JSON.parse(parsedUrl.query.u).path);
451+
}
448452
// For some reason VS Code encodes the = so the query doesn't parse
449453
// correctly. We'll look through what's available and try to find it.
450454
for (let value in parsedUrl.query) {

0 commit comments

Comments
 (0)