From 83f86a45b6e2f5e5d44fe2e71638dcdd091a0ac8 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 14 Aug 2019 10:25:31 -0500 Subject: [PATCH] Load language bundles on the client --- README.md | 3 ++- scripts/vscode.patch | 33 ++++++++++++++++++++++++++++++--- src/server.ts | 4 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2fd7f299..c02663ab 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,9 @@ Our changes include: - Change a regular expression used for mnemonics so it works on Firefox. - Make it possible for us to load code on the client. - Modify the build process to include our code. -- Fix a CSP issue within a webview. +- Fix a CSP issue within webviews. - Fix an issue displaying extension contributions. +- Make changing the display language work. ## License [MIT](LICENSE) diff --git a/scripts/vscode.patch b/scripts/vscode.patch index a6642940..8be77375 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -174,15 +174,40 @@ index 5b06636edb..60b508079a 100644 diff --git a/src/vs/code/browser/workbench/workbench.js b/src/vs/code/browser/workbench/workbench.js -index 65fae7c82d..9a9b8bbe3b 100644 +index 65fae7c82d..a1974cd941 100644 --- a/src/vs/code/browser/workbench/workbench.js +++ b/src/vs/code/browser/workbench/workbench.js -@@ -7,21 +7,26 @@ +@@ -7,21 +7,52 @@ (function () { + const basePath = window.location.pathname.replace(/\/+$/, ''); + const base = window.location.origin + basePath; ++ ++ let nlsConfig; ++ try { ++ nlsConfig = JSON.parse(document.getElementById('vscode-remote-nls-configuration').getAttribute('data-settings')); ++ if (nlsConfig._resolvedLanguagePackCoreLocation) { ++ const bundles = Object.create(null); ++ nlsConfig.loadBundle = (bundle, language, cb) => { ++ let result = bundles[bundle]; ++ if (result) { ++ return cb(undefined, result); ++ } ++ // FIXME: Only works if path separators are /. ++ const path = nlsConfig._resolvedLanguagePackCoreLocation ++ + '/' + bundle.replace(/\//g, '!') + '.nls.json'; ++ fetch(`${base}/resources/fetch?u=${JSON.stringify({ path })}`) ++ .then((response) => response.json()) ++ .then((json) => { ++ bundles[bundle] = json; ++ cb(undefined, json); ++ }) ++ .catch(cb); ++ }; ++ } ++ } catch (error) { /* Probably fine. */ } ++ require.config({ - baseUrl: `${window.location.origin}/out`, + baseUrl: `${base}/out`, @@ -196,13 +221,15 @@ index 65fae7c82d..9a9b8bbe3b 100644 - 'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`, - 'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`, - 'semver-umd': `${window.location.origin}/node_modules/semver-umd/lib/semver-umd.js`, +- } + 'vscode-textmate': `${base}/node_modules/vscode-textmate/release/main`, + 'onigasm-umd': `${base}/node_modules/onigasm-umd/release/main`, + 'xterm': `${base}/node_modules/xterm/lib/xterm.js`, + 'xterm-addon-search': `${base}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`, + 'xterm-addon-web-links': `${base}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`, + 'semver-umd': `${base}/node_modules/semver-umd/lib/semver-umd.js`, - } ++ }, ++ 'vs/nls': nlsConfig }); require(['vs/workbench/workbench.web.api'], function (api) { diff --git a/src/server.ts b/src/server.ts index f853c21a..48fbb334 100644 --- a/src/server.ts +++ b/src/server.ts @@ -443,8 +443,12 @@ export class MainServer extends Server { ): Promise { switch (base) { case "/": return this.getRoot(request, parsedUrl); + case "/resources": case "/vscode-resources": if (requestPath === "/fetch") { + if (typeof parsedUrl.query.u === "string") { + return this.getResource(JSON.parse(parsedUrl.query.u).path); + } // For some reason VS Code encodes the = so the query doesn't parse // correctly. We'll look through what's available and try to find it. for (let value in parsedUrl.query) {