mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
adopt web extensions to webpack 5
This commit is contained in:
@@ -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 { Disposable, ExtensionContext, Uri } from 'vscode';
|
||||
import { LanguageClientOptions } from 'vscode-languageclient';
|
||||
import { startClient, LanguageClientConstructor } from '../htmlClient';
|
||||
import { LanguageClient } from 'vscode-languageclient/browser';
|
||||
@@ -24,7 +24,14 @@ export function activate(context: ExtensionContext) {
|
||||
return new LanguageClient(id, name, clientOptions, worker);
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { TextDecoder });
|
||||
const timer = {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable {
|
||||
const handle = setTimeout(callback, ms, ...args);
|
||||
return { dispose: () => clearTimeout(handle) };
|
||||
}
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { TextDecoder, timer });
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -58,6 +58,9 @@ export interface Runtime {
|
||||
TextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string; } };
|
||||
fs?: RequestService;
|
||||
telemetry?: TelemetryReporter;
|
||||
readonly timer: {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable;
|
||||
}
|
||||
}
|
||||
|
||||
export function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime) {
|
||||
@@ -126,7 +129,7 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
||||
let param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
|
||||
return client.sendRequest(TagCloseRequest.type, param);
|
||||
};
|
||||
disposable = activateTagClosing(tagRequestor, { html: true, handlebars: true }, 'html.autoClosingTags');
|
||||
disposable = activateTagClosing(tagRequestor, { html: true, handlebars: true }, 'html.autoClosingTags', runtime);
|
||||
toDispose.push(disposable);
|
||||
|
||||
disposable = client.onTelemetry(e => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getNodeFSRequestService } from './nodeFs';
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { Disposable, ExtensionContext } from 'vscode';
|
||||
import { startClient, LanguageClientConstructor } from '../htmlClient';
|
||||
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
|
||||
import { TextDecoder } from 'util';
|
||||
@@ -37,7 +37,14 @@ export function activate(context: ExtensionContext) {
|
||||
return new LanguageClient(id, name, serverOptions, clientOptions);
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder, telemetry });
|
||||
const timer = {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable {
|
||||
const handle = setTimeout(callback, ms, ...args);
|
||||
return { dispose: () => clearTimeout(handle) };
|
||||
}
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder, telemetry, timer });
|
||||
}
|
||||
|
||||
interface IPackageInfo {
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { window, workspace, Disposable, TextDocumentContentChangeEvent, TextDocument, Position, SnippetString } from 'vscode';
|
||||
import { Runtime } from './htmlClient';
|
||||
|
||||
export function activateTagClosing(tagProvider: (document: TextDocument, position: Position) => Thenable<string>, supportedLanguages: { [id: string]: boolean }, configName: string): Disposable {
|
||||
export function activateTagClosing(tagProvider: (document: TextDocument, position: Position) => Thenable<string>, supportedLanguages: { [id: string]: boolean }, configName: string, runtime: Runtime): Disposable {
|
||||
|
||||
let disposables: Disposable[] = [];
|
||||
workspace.onDidChangeTextDocument(event => onDidChangeTextDocument(event.document, event.contentChanges), null, disposables);
|
||||
@@ -14,7 +15,13 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
|
||||
updateEnabledState();
|
||||
window.onDidChangeActiveTextEditor(updateEnabledState, null, disposables);
|
||||
|
||||
let timeout: NodeJS.Timer | undefined = undefined;
|
||||
let timeout: Disposable | undefined = undefined;
|
||||
|
||||
disposables.push({
|
||||
dispose: () => {
|
||||
timeout?.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
function updateEnabledState() {
|
||||
isEnabled = false;
|
||||
@@ -40,8 +47,8 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
|
||||
if (document !== activeDocument || changes.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (typeof timeout !== 'undefined') {
|
||||
clearTimeout(timeout);
|
||||
if (timeout) {
|
||||
timeout.dispose();
|
||||
}
|
||||
let lastChange = changes[changes.length - 1];
|
||||
let lastCharacter = lastChange.text[lastChange.text.length - 1];
|
||||
@@ -50,7 +57,7 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
|
||||
}
|
||||
let rangeStart = lastChange.range.start;
|
||||
let version = document.version;
|
||||
timeout = setTimeout(() => {
|
||||
timeout = runtime.timer.setTimeout(() => {
|
||||
let position = new Position(rangeStart.line, rangeStart.character + lastChange.text.length);
|
||||
tagProvider(document, position).then(text => {
|
||||
if (text && isEnabled) {
|
||||
@@ -72,4 +79,4 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
|
||||
}, 100);
|
||||
}
|
||||
return Disposable.from(...disposables);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user