diff --git a/patches/display-language.patch b/patches/display-language.patch index 95c9a2197..7fcfb4621 100644 --- a/patches/display-language.patch +++ b/patches/display-language.patch @@ -84,10 +84,29 @@ Index: sagemaker-code-editor/vscode/src/vs/code/browser/workbench/workbench.html + - -@@ -37,6 +40,47 @@ + +@@ -25,6 +28,6 @@ + + + +- ++ + + + +@@ -32,18 +35,61 @@ + + + + ++ ++ + +- +- +- +- +- ++ ++ ++ + Index: sagemaker-code-editor/vscode/src/vs/platform/environment/common/environmentService.ts =================================================================== @@ -186,7 +214,124 @@ Index: sagemaker-code-editor/vscode/src/vs/platform/languagePacks/browser/langua + return this.languagePackService.getInstalledLanguages() } } +Index: sagemaker-code-editor/vscode/src/vs/server/node/remoteLanguagePacks.ts +=================================================================== +--- sagemaker-code-editor.orig/vscode/src/vs/server/node/remoteLanguagePacks.ts ++++ sagemaker-code-editor/vscode/src/vs/server/node/remoteLanguagePacks.ts +@@ -1,38 +1,80 @@ + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + import { FileAccess } from '../../base/common/network.js'; +-import { join } from '../../base/common/path.js'; +-import type { INLSConfiguration } from '../../nls.js'; +-import { resolveNLSConfiguration } from '../../base/node/nls.js'; +-import { Promises } from '../../base/node/pfs.js'; +-import product from '../../platform/product/common/product.js'; +- +-const nlsMetadataPath = join(FileAccess.asFileUri('').fsPath); +-const defaultMessagesFile = join(nlsMetadataPath, 'nls.messages.json'); +-const nlsConfigurationCache = new Map>(); +- +-export async function getNLSConfiguration(language: string, userDataPath: string): Promise { +- if (!product.commit || !(await Promises.exists(defaultMessagesFile))) { +- return { +- userLocale: 'en', +- osLocale: 'en', +- resolvedLanguage: 'en', +- defaultMessagesFile, +- +- // NLS: below 2 are a relic from old times only used by vscode-nls and deprecated +- locale: 'en', +- availableLanguages: {} +- }; +- } +- +- const cacheKey = `${language}||${userDataPath}`; +- let result = nlsConfigurationCache.get(cacheKey); +- if (!result) { +- result = resolveNLSConfiguration({ userLocale: language, osLocale: language, commit: product.commit, userDataPath, nlsMetadataPath }); +- nlsConfigurationCache.set(cacheKey, result); +- } +- +- return result; +-} ++import * as fs from 'fs'; ++import * as path from '../../base/common/path.js'; ++import * as lp from '../../base/node/languagePacks.js'; ++ ++const metaData = path.join(FileAccess.asFileUri('').fsPath, 'nls.metadata.json'); ++const _cache: Map> = new Map(); ++ ++export function getNLSConfiguration(language: string, userDataPath: string): Promise { ++ const key = `${language}||${userDataPath}`; ++ let result = _cache.get(key); ++ if (!result) { ++ // The OS Locale on the remote side really doesn't matter, so we pass in the same language ++ result = lp.getNLSConfiguration("dummy_commit", userDataPath, metaData, language, language).then(value => { ++ if (InternalNLSConfiguration.is(value)) { ++ value._languagePackSupport = true; ++ } ++ // If the configuration has no results keep trying since code-server ++ // doesn't restart when a language is installed so this result would ++ // persist (the plugin might not be installed yet for example). ++ if (value.locale !== 'en' && value.locale !== 'en-us' && Object.keys(value.availableLanguages).length === 0) { ++ _cache.delete(key); ++ } ++ return value; ++ }); ++ _cache.set(key, result); ++ } ++ return result; ++} ++ ++export namespace InternalNLSConfiguration { ++ export function is(value: lp.NLSConfiguration): value is lp.InternalNLSConfiguration { ++ const candidate: lp.InternalNLSConfiguration = value as lp.InternalNLSConfiguration; ++ return candidate && typeof candidate._languagePackId === 'string'; ++ } ++} ++ ++/** ++ * The code below is copied from from src/main.js. ++ */ ++ ++export const getLocaleFromConfig = async (argvResource: string): Promise => { ++ try { ++ const content = stripComments(await fs.promises.readFile(argvResource, 'utf8')); ++ return JSON.parse(content).locale; ++ } catch (error) { ++ if (error.code !== "ENOENT") { ++ console.warn(error) ++ } ++ return 'en'; ++ } ++}; ++ ++const stripComments = (content: string): string => { ++ const regexp = /('(?:[^\\']*(?:\\.)?)*')|('(?:[^\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g; ++ ++ return content.replace(regexp, (match, _m1, _m2, m3, m4) => { ++ // Only one of m1, m2, m3, m4 matches ++ if (m3) { ++ // A block comment. Replace with nothing ++ return ''; ++ } else if (m4) { ++ // A line comment. If it ends in \r?\n then keep it. ++ const length_1 = m4.length; ++ if (length_1 > 2 && m4[length_1 - 1] === '\n') { ++ return m4[length_1 - 2] === '\r' ? '\r\n' : '\n'; ++ } ++ else { ++ return ''; ++ } ++ } else { ++ // We match a string ++ return match; ++ } ++ }); ++}; Index: sagemaker-code-editor/vscode/src/vs/server/node/serverEnvironmentService.ts =================================================================== --- sagemaker-code-editor.orig/vscode/src/vs/server/node/serverEnvironmentService.ts @@ -238,6 +383,68 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts =================================================================== --- sagemaker-code-editor.orig/vscode/src/vs/server/node/webClientServer.ts +++ sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts +@@ -8,6 +8,7 @@ + import * as url from 'url'; + import * as cookie from 'cookie'; + import * as crypto from 'crypto'; ++import * as path from 'path'; + import { isEqualOrParent } from '../../base/common/extpath.js'; + import { getMediaMime } from '../../base/common/mime.js'; + import { isLinux } from '../../base/common/platform.js'; +@@ -25,9 +26,9 @@ + import { streamToBuffer } from '../../base/common/buffer.js'; + import { IProductConfiguration } from '../../base/common/product.js'; + import { isString, Mutable } from '../../base/common/types.js'; ++import { getLocaleFromConfig, getNLSConfiguration } from '../../server/node/remoteLanguagePacks.js'; + import { CharCode } from '../../base/common/charCode.js'; + import { IExtensionManifest } from '../../platform/extensions/common/extensions.js'; +-import { ICSSDevelopmentService } from '../../platform/cssDev/node/cssDevService.js'; + + const textMimeType: { [ext: string]: string | undefined } = { + '.html': 'text/html', + '.js': 'text/javascript', +@@ -393,26 +394,20 @@ export class WebClientServer { + workspaceUri: resolveWorkspaceURI(this._environmentService.args['default-workspace']), + productConfiguration, +- callbackRoute: callbackRoute +- }; +- +- const cookies = cookie.parse(req.headers.cookie || ''); +- const locale = cookies['vscode.nls.locale'] || req.headers['accept-language']?.split(',')[0]?.toLowerCase() || 'en'; +- let WORKBENCH_NLS_BASE_URL: string | undefined; +- let WORKBENCH_NLS_URL: string; +- if (!locale.startsWith('en') && this._productService.nlsCoreBaseUrl) { +- WORKBENCH_NLS_BASE_URL = this._productService.nlsCoreBaseUrl; +- WORKBENCH_NLS_URL = `${WORKBENCH_NLS_BASE_URL}${this._productService.commit}/${this._productService.version}/${locale}/nls.messages.js`; +- } else { +- WORKBENCH_NLS_URL = ''; // fallback will apply +- } +- +- const values: { [key: string]: string } = { +- WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration), +- WORKBENCH_AUTH_SESSION: authSessionInfo ? asJSON(authSessionInfo) : '', +- WORKBENCH_WEB_BASE_URL: staticRoute, +- WORKBENCH_NLS_URL, +- WORKBENCH_NLS_FALLBACK_URL: `${staticRoute}/out/nls.messages.js` +- }; ++ callbackRoute: this._callbackRoute ++ }; ++ ++ const locale = this._environmentService.args.locale || await getLocaleFromConfig(this._environmentService.argvResource.fsPath); ++ const nlsConfiguration = await getNLSConfiguration(locale, this._environmentService.userDataPath) ++ const nlsBaseUrl = this._productService.extensionsGallery?.nlsBaseUrl; ++ const values: { [key: string]: string } = { ++ WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration), ++ WORKBENCH_AUTH_SESSION: authSessionInfo ? asJSON(authSessionInfo) : '', ++ WORKBENCH_WEB_BASE_URL: this._staticRoute, ++ WORKBENCH_NLS_BASE_URL: nlsBaseUrl ? `${nlsBaseUrl}${!nlsBaseUrl.endsWith('/') ? '/' : ''}${this._productService.commit}/${this._productService.version}/` : '', ++ BASE: base, ++ VS_BASE: vscodeBase, ++ NLS_CONFIGURATION: asJSON(nlsConfiguration), ++ }; + + // DEV --------------------------------------------------------------------------------------- + // DEV: This is for development and enables loading CSS via import-statements via import-maps. @@ -401,7 +405,7 @@ export class WebClientServer { `frame-src 'self' https://*.vscode-cdn.net data:;`, 'worker-src \'self\' data: blob:;', diff --git a/patches/webview.diff b/patches/webview.diff index 25f77c266..6d96dc0de 100644 --- a/patches/webview.diff +++ b/patches/webview.diff @@ -74,10 +74,19 @@ Index: sagemaker-code-editor/vscode/src/vs/workbench/contrib/webview/browser/pre -+ content="default-src 'none'; script-src 'sha256-1qYtPnTQa4VwKNJO61EOhs2agF9TvuQSYIJ27OgzZqI=' 'self'; frame-src 'self'; style-src 'unsafe-inline';"> ++ content="default-src 'none'; script-src 'sha256-Oi71Tq4Buohx0KDH3yEbVJUzABnqYv9iVLo420HZXqI=' 'self'; frame-src 'self'; style-src 'unsafe-inline';"> { + /** + * @param {MessageEvent} event @@ -344,6 +344,12 @@ const hostname = location.hostname;