diff --git a/extensions/typescript/src/features/bufferSyncSupport.ts b/extensions/typescript/src/features/bufferSyncSupport.ts index 83d5b98b775..2c1b414723d 100644 --- a/extensions/typescript/src/features/bufferSyncSupport.ts +++ b/extensions/typescript/src/features/bufferSyncSupport.ts @@ -7,11 +7,10 @@ import * as cp from 'child_process'; import * as fs from 'fs'; -import { workspace, window, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable, MessageItem } from 'vscode'; +import { workspace, window, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable, MessageItem, Uri, commands } from 'vscode'; import * as Proto from '../protocol'; import { ITypescriptServiceClient } from '../typescriptService'; import { Delayer } from '../utils/async'; -import LinkedMap from './linkedMap'; import * as nls from 'vscode-nls'; let localize = nls.loadMessageBundle(); @@ -29,17 +28,12 @@ const Mode2ScriptKind: ObjectMap<'TS' | 'JS' | 'TSX' | 'JSX'> = { class SyncedBuffer { - private document: TextDocument; - private filepath: string; - private diagnosticRequestor: IDiagnosticRequestor; - private client: ITypescriptServiceClient; - - constructor(document: TextDocument, filepath: string, diagnosticRequestor: IDiagnosticRequestor, client: ITypescriptServiceClient) { - this.document = document; - this.filepath = filepath; - this.diagnosticRequestor = diagnosticRequestor; - this.client = client; - } + constructor( + private readonly document: TextDocument, + private readonly filepath: string, + private readonly diagnosticRequestor: IDiagnosticRequestor, + private readonly client: ITypescriptServiceClient + ) { } public open(): void { const args: Proto.OpenRequestArgs = { @@ -66,23 +60,22 @@ class SyncedBuffer { } public close(): void { - let args: Proto.FileRequestArgs = { + const args: Proto.FileRequestArgs = { file: this.filepath }; this.client.execute('close', args, false); } - onContentChanged(events: TextDocumentContentChangeEvent[]): void { - let filePath = this.client.normalizePath(this.document.uri); + public onContentChanged(events: TextDocumentContentChangeEvent[]): void { + const filePath = this.client.normalizePath(this.document.uri); if (!filePath) { return; } - for (let i = 0; i < events.length; i++) { - let event = events[i]; - let range = event.range; - let text = event.text; - let args: Proto.ChangeRequestArgs = { + for (const event of events) { + const range = event.range; + const text = event.text; + const args: Proto.ChangeRequestArgs = { file: filePath, line: range.start.line + 1, offset: range.start.character + 1, @@ -115,7 +108,6 @@ export default class BufferSyncSupport { private pendingDiagnostics: { [key: string]: number; }; private diagnosticDelayer: Delayer; - private emitQueue: LinkedMap; private checkGlobalTSCVersion: boolean; constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, validate: boolean = true) { @@ -131,7 +123,6 @@ export default class BufferSyncSupport { this.diagnosticDelayer = new Delayer(300); this.syncedBuffers = Object.create(null); - this.emitQueue = new LinkedMap(); const tsConfig = workspace.getConfiguration('typescript'); this.checkGlobalTSCVersion = client.checkGlobalTSCVersion && this.modeIds['typescript'] === true && tsConfig.get(checkTscVersionSettingKey, true); @@ -297,21 +288,6 @@ export default class BufferSyncSupport { id: number; } - function openUrl(url: string) { - let cmd: string; - switch (process.platform) { - case 'darwin': - cmd = 'open'; - break; - case 'win32': - cmd = 'start'; - break; - default: - cmd = 'xdg-open'; - } - return cp.exec(cmd + ' ' + url); - } - let tscVersion: string | undefined = undefined; try { let out = cp.execSync('tsc --version', { encoding: 'utf8' }); @@ -345,7 +321,7 @@ export default class BufferSyncSupport { } switch (selected.id) { case 1: - openUrl('http://go.microsoft.com/fwlink/?LinkId=826239'); + commands.executeCommand('vscode.open', Uri.parse('http://go.microsoft.com/fwlink/?LinkId=826239')); break; case 2: const tsConfig = workspace.getConfiguration('typescript'); diff --git a/extensions/typescript/src/features/linkedMap.ts b/extensions/typescript/src/features/linkedMap.ts deleted file mode 100644 index 9f0a41a02bb..00000000000 --- a/extensions/typescript/src/features/linkedMap.ts +++ /dev/null @@ -1,168 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -interface Item { - previous: Item | undefined; - next: Item | undefined; - key: string; - value: T; -} - -export default class LinkedMap { - - private map: ObjectMap>; - private head: Item | undefined; - private tail: Item | undefined; - private _length: number; - - constructor() { - this.map = Object.create(null); - this.head = undefined; - this.tail = undefined; - this._length = 0; - } - - public isEmpty(): boolean { - return !this.head && !this.tail; - } - - public length(): number { - return this._length; - } - - public get(key: string): T | undefined { - const item = this.map[key]; - if (!item) { - return undefined; - } - return item.value; - } - - public add(key: string, value: T, touch = false): void { - let item = this.map[key]; - if (item) { - item.value = value; - if (touch) { - this.touch(item); - } - } - else { - item = { key, value, next: undefined, previous: undefined }; - if (touch) { - this.addItemFirst(item); - } - else { - this.addItemLast(item); - } - this.map[key] = item; - this._length++; - } - } - - public remove(key: string): T | undefined { - const item = this.map[key]; - if (!item) { - return undefined; - } - delete this.map[key]; - this.removeItem(item); - this._length--; - return item.value; - } - - public shift(): T | undefined { - if (!this.head && !this.tail) { - return undefined; - } - if (!this.head || !this.tail) { - throw new Error('Invalid list'); - } - const item = this.head; - delete this.map[item.key]; - this.removeItem(item); - this._length--; - return item.value; - } - - private addItemFirst(item: Item): void { - // First time Insert - if (!this.head && !this.tail) { - this.tail = item; - } else if (!this.head) { - throw new Error('Invalid list'); - } else { - item.next = this.head; - this.head.previous = item; - } - this.head = item; - } - - private addItemLast(item: Item): void { - // First time Insert - if (!this.head && !this.tail) { - this.head = item; - } else if (!this.tail) { - throw new Error('Invalid list'); - } else { - item.previous = this.tail; - this.tail.next = item; - } - this.tail = item; - } - - private removeItem(item: Item): void { - if (item === this.head && item === this.tail) { - this.head = undefined; - this.tail = undefined; - } - else if (item === this.head) { - this.head = item.next; - } - else if (item === this.tail) { - this.tail = item.previous; - } - else { - const next = item.next; - const previous = item.previous; - if (!next || !previous) { - throw new Error('Invalid list'); - } - next.previous = previous; - previous.next = next; - } - } - - private touch(item: Item): void { - if (item === this.head) { - return; - } - - const next = item.next; - const previous = item.previous; - - // Unlink the item - if (item === this.tail) { - this.tail = previous; - } - else { - // Both next and previous are not null since item was neither head nor tail. - if (next) { - next.previous = previous; - } - if (previous) { - previous.next = next; - } - } - - // Insert the node at head - item.previous = undefined; - item.next = this.head; - if (!this.head) { - throw new Error('Invalid list'); - } - this.head.previous = item; - this.head = item; - } -}