mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
add client/server browser parts
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext, window } from 'vscode';
|
||||
//import { startClient } from '../cssClient';
|
||||
|
||||
// this method is called when vs code is activated
|
||||
export function activate(_context: ExtensionContext) {
|
||||
|
||||
window.showInformationMessage('cssClientBrowserMain.ts running');
|
||||
|
||||
//startClient(context, {});
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext, window } from 'vscode';
|
||||
import { CommonLanguageClient, LanguageClientOptions, MessageTransports } from 'vscode-languageclient';
|
||||
import { startClient, LanguageClientConstructor } from '../cssClient';
|
||||
import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-jsonrpc/lib/browser/main';
|
||||
|
||||
declare const Worker: {
|
||||
new(stringUrl: string): any;
|
||||
};
|
||||
|
||||
class BrowserLanguageClient extends CommonLanguageClient {
|
||||
|
||||
constructor(id: string, name: string, clientOptions: LanguageClientOptions, private worker: any) {
|
||||
super(id, name, clientOptions);
|
||||
}
|
||||
|
||||
protected createMessageTransports(_encoding: string): Promise<MessageTransports> {
|
||||
const reader = new BrowserMessageReader(this.worker);
|
||||
const writer = new BrowserMessageWriter(this.worker);
|
||||
return Promise.resolve({ reader, writer });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this method is called when vs code is activated
|
||||
export function activate(context: ExtensionContext) {
|
||||
const serverMain = context.asAbsolutePath('server/dist/browser/cssServerMain.js');
|
||||
try {
|
||||
const worker = new Worker(serverMain);
|
||||
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
|
||||
return new BrowserLanguageClient(id, name, clientOptions, worker);
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, {});
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export interface Options {
|
||||
locale?: string;
|
||||
cacheLanguageResolution?: boolean;
|
||||
}
|
||||
export interface LocalizeInfo {
|
||||
key: string;
|
||||
comment: string[];
|
||||
}
|
||||
export interface LocalizeFunc {
|
||||
(info: LocalizeInfo, message: string, ...args: any[]): string;
|
||||
(key: string, message: string, ...args: any[]): string;
|
||||
}
|
||||
export interface LoadFunc {
|
||||
(file?: string): LocalizeFunc;
|
||||
}
|
||||
|
||||
function format(message: string, args: any[]): string {
|
||||
let result: string;
|
||||
|
||||
if (args.length === 0) {
|
||||
result = message;
|
||||
} else {
|
||||
result = message.replace(/\{(\d+)\}/g, (match, rest) => {
|
||||
let index = rest[0];
|
||||
return typeof args[index] !== 'undefined' ? args[index] : match;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function localize(_key: string | LocalizeInfo, message: string, ...args: any[]): string {
|
||||
return format(message, args);
|
||||
}
|
||||
|
||||
export function loadMessageBundle(_file?: string): LocalizeFunc {
|
||||
return localize;
|
||||
}
|
||||
|
||||
export function config(_opt?: Options | string): LoadFunc {
|
||||
return loadMessageBundle;
|
||||
}
|
||||
Reference in New Issue
Block a user