Pass translations down to Markdown Language Server (#172884)

Fixes #172060
This commit is contained in:
Matt Bierner
2023-01-30 21:29:41 -08:00
committed by GitHub
parent 62dd7cd76d
commit c18f80a2d4
9 changed files with 83 additions and 8 deletions
@@ -13,10 +13,10 @@ const path = require('path');
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/main.ts',
extension: './src/browser/workerMain.ts',
},
output: {
filename: 'main.js',
filename: 'workerMain.js',
path: path.join(__dirname, 'dist', 'browser'),
libraryTarget: 'var',
library: 'serverExportVar'
@@ -13,10 +13,10 @@ const path = require('path');
module.exports = withDefaults({
context: path.join(__dirname),
entry: {
extension: './src/node/main.ts',
extension: './src/node/workerMain.ts',
},
output: {
filename: 'main.js',
filename: 'workerMain.js',
path: path.join(__dirname, 'dist', 'node'),
}
});
@@ -14,7 +14,7 @@
"out/**/*.js"
],
"dependencies": {
"@vscode/l10n": "^0.0.10",
"@vscode/l10n": "^0.0.11",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.5",
"vscode-languageserver-types": "^3.17.1",
@@ -27,6 +27,8 @@
"scripts": {
"compile": "gulp compile-extension:markdown-language-features-server",
"prepublishOnly": "npm run compile",
"watch": "gulp watch-extension:markdown-language-features-server"
"watch": "gulp watch-extension:markdown-language-features-server",
"compile-web": "npx webpack-cli --config extension-browser.webpack.config --mode none",
"watch-web": "npx webpack-cli --config extension-browser.webpack.config --mode none --watch --info-verbosity verbose"
}
}
@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as l10n from '@vscode/l10n';
let initialized = false;
const pendingMessages: any[] = [];
const messageHandler = async (e: any) => {
if (!initialized) {
const l10nLog: string[] = [];
initialized = true;
const i10lLocation = e.data.i10lLocation;
if (i10lLocation) {
try {
await l10n.config({ uri: i10lLocation });
l10nLog.push(`l10n: Configured to ${i10lLocation.toString()}.`);
} catch (e) {
l10nLog.push(`l10n: Problems loading ${i10lLocation.toString()} : ${e}.`);
}
} else {
l10nLog.push(`l10n: No bundle configured.`);
}
await import('./main');
if (self.onmessage !== messageHandler) {
pendingMessages.forEach(msg => self.onmessage?.(msg));
pendingMessages.length = 0;
}
l10nLog.forEach(console.log);
} else {
pendingMessages.push(e);
}
};
self.onmessage = messageHandler;
@@ -0,0 +1,23 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as l10n from '@vscode/l10n';
async function setupMain() {
const l10nLog: string[] = [];
const i10lLocation = process.env['VSCODE_L10N_BUNDLE_LOCATION'];
if (i10lLocation) {
try {
await l10n.config({ uri: i10lLocation });
l10nLog.push(`l10n: Configured to ${i10lLocation.toString()}`);
} catch (e) {
l10nLog.push(`l10n: Problems loading ${i10lLocation.toString()} : ${e}`);
}
}
await import('./main');
l10nLog.forEach(console.log);
}
setupMain();
@@ -12,6 +12,11 @@
resolved "https://registry.yarnpkg.com/@vscode/l10n/-/l10n-0.0.10.tgz#9c513107c690c0dd16e3ec61e453743de15ebdb0"
integrity sha512-E1OCmDcDWa0Ya7vtSjp/XfHFGqYJfh+YPC1RkATU71fTac+j1JjCcB3qwSzmlKAighx2WxhLlfhS0RwAN++PFQ==
"@vscode/l10n@^0.0.11":
version "0.0.11"
resolved "https://registry.yarnpkg.com/@vscode/l10n/-/l10n-0.0.11.tgz#325d7beb2cfb87162bc624d16c4d546de6a73b72"
integrity sha512-ukOMWnCg1tCvT7WnDfsUKQOFDQGsyR5tNgRpwmqi+5/vzU3ghdDXzvIM4IOPdSb3OeSsBNvmSL8nxIVOqi2WXA==
picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
@@ -52,6 +52,7 @@ export async function startClient(factory: LanguageClientConstructor, parser: IM
},
initializationOptions: {
markdownFileExtensions,
i10lLocation: vscode.l10n.uri?.toJSON(),
},
diagnosticPullOptions: {
onChange: true,
@@ -27,8 +27,10 @@ export async function activate(context: vscode.ExtensionContext) {
}
function startServer(context: vscode.ExtensionContext, parser: IMdParser): Promise<MdLanguageClient> {
const serverMain = vscode.Uri.joinPath(context.extensionUri, 'server/dist/browser/main.js');
const serverMain = vscode.Uri.joinPath(context.extensionUri, 'server/dist/browser/workerMain.js');
const worker = new Worker(serverMain.toString());
worker.postMessage({ i10lLocation: vscode.l10n.uri?.toString() ?? '' });
return startClient((id: string, name: string, clientOptions: LanguageClientOptions) => {
return new LanguageClient(id, name, clientOptions, worker);
@@ -29,7 +29,7 @@ export async function activate(context: vscode.ExtensionContext) {
function startServer(context: vscode.ExtensionContext, parser: IMdParser): Promise<MdLanguageClient> {
const clientMain = vscode.extensions.getExtension('vscode.markdown-language-features')?.packageJSON?.main || '';
const serverMain = `./server/${clientMain.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/node/main`;
const serverMain = `./server/${clientMain.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/node/workerMain`;
const serverModule = context.asAbsolutePath(serverMain);
// The debug options for the server
@@ -41,6 +41,10 @@ function startServer(context: vscode.ExtensionContext, parser: IMdParser): Promi
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// pass the location of the localization bundle to the server
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = vscode.l10n.uri?.toString() ?? '';
return startClient((id, name, clientOptions) => {
return new LanguageClient(id, name, serverOptions, clientOptions);
}, parser);