mirror of https://github.com/coder/code-server.git
Load language bundles on the client
This commit is contained in:
parent
45ad7f020a
commit
83f86a45b6
|
@ -119,8 +119,9 @@ Our changes include:
|
||||||
- Change a regular expression used for mnemonics so it works on Firefox.
|
- Change a regular expression used for mnemonics so it works on Firefox.
|
||||||
- Make it possible for us to load code on the client.
|
- Make it possible for us to load code on the client.
|
||||||
- Modify the build process to include our code.
|
- 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.
|
- Fix an issue displaying extension contributions.
|
||||||
|
- Make changing the display language work.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
[MIT](LICENSE)
|
[MIT](LICENSE)
|
||||||
|
|
|
@ -174,15 +174,40 @@ index 5b06636edb..60b508079a 100644
|
||||||
<!-- Require our AMD loader -->
|
<!-- Require our AMD loader -->
|
||||||
<script src="./out/vs/loader.js"></script>
|
<script src="./out/vs/loader.js"></script>
|
||||||
diff --git a/src/vs/code/browser/workbench/workbench.js b/src/vs/code/browser/workbench/workbench.js
|
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
|
--- a/src/vs/code/browser/workbench/workbench.js
|
||||||
+++ b/src/vs/code/browser/workbench/workbench.js
|
+++ b/src/vs/code/browser/workbench/workbench.js
|
||||||
@@ -7,21 +7,26 @@
|
@@ -7,21 +7,52 @@
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
+ const basePath = window.location.pathname.replace(/\/+$/, '');
|
+ const basePath = window.location.pathname.replace(/\/+$/, '');
|
||||||
+ const base = window.location.origin + basePath;
|
+ 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({
|
require.config({
|
||||||
- baseUrl: `${window.location.origin}/out`,
|
- baseUrl: `${window.location.origin}/out`,
|
||||||
+ baseUrl: `${base}/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-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`,
|
- '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`,
|
- 'semver-umd': `${window.location.origin}/node_modules/semver-umd/lib/semver-umd.js`,
|
||||||
|
- }
|
||||||
+ 'vscode-textmate': `${base}/node_modules/vscode-textmate/release/main`,
|
+ 'vscode-textmate': `${base}/node_modules/vscode-textmate/release/main`,
|
||||||
+ 'onigasm-umd': `${base}/node_modules/onigasm-umd/release/main`,
|
+ 'onigasm-umd': `${base}/node_modules/onigasm-umd/release/main`,
|
||||||
+ 'xterm': `${base}/node_modules/xterm/lib/xterm.js`,
|
+ 'xterm': `${base}/node_modules/xterm/lib/xterm.js`,
|
||||||
+ 'xterm-addon-search': `${base}/node_modules/xterm-addon-search/lib/xterm-addon-search.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`,
|
+ '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`,
|
+ 'semver-umd': `${base}/node_modules/semver-umd/lib/semver-umd.js`,
|
||||||
}
|
+ },
|
||||||
|
+ 'vs/nls': nlsConfig
|
||||||
});
|
});
|
||||||
|
|
||||||
require(['vs/workbench/workbench.web.api'], function (api) {
|
require(['vs/workbench/workbench.web.api'], function (api) {
|
||||||
|
|
|
@ -443,8 +443,12 @@ export class MainServer extends Server {
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
switch (base) {
|
switch (base) {
|
||||||
case "/": return this.getRoot(request, parsedUrl);
|
case "/": return this.getRoot(request, parsedUrl);
|
||||||
|
case "/resources":
|
||||||
case "/vscode-resources":
|
case "/vscode-resources":
|
||||||
if (requestPath === "/fetch") {
|
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
|
// 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.
|
// correctly. We'll look through what's available and try to find it.
|
||||||
for (let value in parsedUrl.query) {
|
for (let value in parsedUrl.query) {
|
||||||
|
|
Loading…
Reference in New Issue