[html/css/json] pass the location of the localization bundle to the server (#168111)

pass the location of the localization bundle to the server
This commit is contained in:
Martin Aeschlimann 2022-12-05 23:49:27 +01:00 committed by GitHub
parent 6e3976f744
commit b27ee6b7b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 88 additions and 12 deletions

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtensionContext, Uri } from 'vscode';
import { ExtensionContext, Uri, l10n } from 'vscode';
import { BaseLanguageClient, LanguageClientOptions } from 'vscode-languageclient';
import { startClient, LanguageClientConstructor } from '../cssClient';
import { LanguageClient } from 'vscode-languageclient/browser';
@ -22,6 +22,8 @@ export async function activate(context: ExtensionContext) {
const serverMain = Uri.joinPath(context.extensionUri, 'server/dist/browser/cssServerMain.js');
try {
const worker = new Worker(serverMain.toString());
worker.postMessage({ i10lLocation: l10n.uri?.toString(false) ?? '' });
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
return new LanguageClient(id, name, clientOptions, worker);
};

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { getNodeFSRequestService } from './nodeFs';
import { ExtensionContext, extensions } from 'vscode';
import { ExtensionContext, extensions, l10n } from 'vscode';
import { startClient, LanguageClientConstructor } from '../cssClient';
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient, BaseLanguageClient } from 'vscode-languageclient/node';
import { TextDecoder } from 'util';
@ -33,6 +33,9 @@ export async function activate(context: ExtensionContext) {
return new LanguageClient(id, name, serverOptions, clientOptions);
};
// pass the location of the localization bundle to the server
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = l10n.uri?.toString() ?? '';
client = await startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder });
}

View file

@ -13,7 +13,7 @@ const path = require('path');
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/cssServerMain.ts',
extension: './src/browser/cssServerWorkerMain.ts',
},
output: {
filename: 'cssServerMain.js',

View file

@ -12,7 +12,8 @@
"dependencies": {
"vscode-css-languageservice": "^6.2.1",
"vscode-languageserver": "^8.1.0-next.2",
"vscode-uri": "^3.0.6"
"vscode-uri": "^3.0.6",
"@vscode/l10n": "^0.0.10"
},
"devDependencies": {
"@types/mocha": "^9.1.1",

View file

@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare let self: any;
import * as l10n from '@vscode/l10n';
let initialized = false;
self.onmessage = async (e: any) => {
if (!initialized) {
initialized = true;
const i10lLocation = e.data.i10lLocation;
if (i10lLocation) {
await l10n.config({ uri: i10lLocation });
}
await import('./cssServerMain');
}
};

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable, ExtensionContext, Uri } from 'vscode';
import { Disposable, ExtensionContext, Uri, l10n } from 'vscode';
import { LanguageClientOptions } from 'vscode-languageclient';
import { startClient, LanguageClientConstructor, AsyncDisposable } from '../htmlClient';
import { LanguageClient } from 'vscode-languageclient/browser';
@ -22,6 +22,8 @@ export async function activate(context: ExtensionContext) {
const serverMain = Uri.joinPath(context.extensionUri, 'server/dist/browser/htmlServerMain.js');
try {
const worker = new Worker(serverMain.toString());
worker.postMessage({ i10lLocation: l10n.uri?.toString(false) ?? '' });
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
return new LanguageClient(id, name, clientOptions, worker);
};

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { getNodeFileFS } from './nodeFs';
import { Disposable, ExtensionContext } from 'vscode';
import { Disposable, ExtensionContext, l10n } from 'vscode';
import { startClient, LanguageClientConstructor, AsyncDisposable } from '../htmlClient';
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
import { TextDecoder } from 'util';
@ -45,6 +45,10 @@ export async function activate(context: ExtensionContext) {
}
};
// pass the location of the localization bundle to the server
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = l10n.uri?.toString() ?? '';
client = await startClient(context, newLanguageClient, { fileFs: getNodeFileFS(), TextDecoder, telemetry, timer });
}

View file

@ -13,7 +13,7 @@ const path = require('path');
const serverConfig = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/htmlServerMain.ts',
extension: './src/browser/htmlServerWorkerMain.ts',
},
output: {
filename: 'htmlServerMain.js',

View file

@ -13,7 +13,8 @@
"vscode-html-languageservice": "^5.0.3",
"vscode-languageserver": "^8.1.0-next.2",
"vscode-languageserver-textdocument": "^1.0.7",
"vscode-uri": "^3.0.6"
"vscode-uri": "^3.0.6",
"@vscode/l10n": "^0.0.10"
},
"devDependencies": {
"@types/mocha": "^9.1.1",

View file

@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare let self: any;
import * as l10n from '@vscode/l10n';
let initialized = false;
self.onmessage = async (e: any) => {
if (!initialized) {
initialized = true;
const i10lLocation = e.data.i10lLocation;
if (i10lLocation) {
await l10n.config({ uri: i10lLocation });
}
await import('./htmlServerMain');
}
};

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtensionContext, Uri } from 'vscode';
import { ExtensionContext, Uri, l10n } from 'vscode';
import { BaseLanguageClient, LanguageClientOptions } from 'vscode-languageclient';
import { startClient, LanguageClientConstructor, SchemaRequestService } from '../jsonClient';
import { LanguageClient } from 'vscode-languageclient/browser';
@ -21,6 +21,8 @@ export async function activate(context: ExtensionContext) {
const serverMain = Uri.joinPath(context.extensionUri, 'server/dist/browser/jsonServerMain.js');
try {
const worker = new Worker(serverMain.toString());
worker.postMessage({ i10lLocation: l10n.uri?.toString(false) ?? '' });
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
return new LanguageClient(id, name, clientOptions, worker);
};

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtensionContext, OutputChannel, window, workspace } from 'vscode';
import { ExtensionContext, OutputChannel, window, workspace, l10n } from 'vscode';
import { startClient, LanguageClientConstructor, SchemaRequestService, languageServerDescription } from '../jsonClient';
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient, BaseLanguageClient } from 'vscode-languageclient/node';
@ -44,6 +44,9 @@ export async function activate(context: ExtensionContext) {
const log = getLog(outputChannel);
context.subscriptions.push(log);
// pass the location of the localization bundle to the server
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = l10n.uri?.toString() ?? '';
const schemaRequests = await getSchemaRequestService(context, log);
client = await startClient(context, newLanguageClient, { schemaRequests, telemetry });

View file

@ -13,7 +13,7 @@ const path = require('path');
module.exports = withBrowserDefaults({
context: __dirname,
entry: {
extension: './src/browser/jsonServerMain.ts',
extension: './src/browser/jsonServerWorkerMain.ts',
},
output: {
filename: 'jsonServerMain.js',

View file

@ -16,7 +16,8 @@
"request-light": "^0.6.0",
"vscode-json-languageservice": "^5.1.3",
"vscode-languageserver": "^8.1.0-next.2",
"vscode-uri": "^3.0.6"
"vscode-uri": "^3.0.6",
"@vscode/l10n": "^0.0.10"
},
"devDependencies": {
"@types/mocha": "^9.1.1",

View file

@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare let self: any;
import * as l10n from '@vscode/l10n';
let initialized = false;
self.onmessage = async (e: any) => {
if (!initialized) {
initialized = true;
const i10lLocation = e.data.i10lLocation;
if (i10lLocation) {
await l10n.config({ uri: i10lLocation });
}
await import('./jsonServerMain');
}
};