From a1af04f57110d6a6c791116ad1275c0090702bdc Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 25 Jul 2018 18:34:12 -0700 Subject: [PATCH] Prefer namespace imports for 'vscode' --- .../src/features/baseCodeLensProvider.ts | 38 ++++---- .../src/features/bufferSyncSupport.ts | 50 +++++----- .../src/features/definitionProviderBase.ts | 10 +- .../src/features/fileConfigurationManager.ts | 38 ++++---- .../src/features/jsDocCompletions.ts | 52 +++++------ .../src/typeScriptServiceClientHost.ts | 60 ++++++------ .../src/typescriptService.ts | 92 +++++++++---------- .../src/typescriptServiceClient.ts | 72 +++++++-------- .../src/utils/codeAction.ts | 6 +- .../src/utils/configuration.ts | 22 ++--- .../src/utils/logger.ts | 6 +- .../src/utils/pluginPathsProvider.ts | 4 +- .../src/utils/plugins.ts | 4 +- .../src/utils/previewer.ts | 10 +- .../src/utils/relativePathResolver.ts | 4 +- .../src/utils/resourceMap.ts | 14 +-- .../src/utils/tracer.ts | 6 +- .../src/utils/typingsStatus.ts | 22 ++--- .../src/utils/versionPicker.ts | 12 +-- .../src/utils/versionProvider.ts | 15 ++- 20 files changed, 266 insertions(+), 271 deletions(-) diff --git a/extensions/typescript-language-features/src/features/baseCodeLensProvider.ts b/extensions/typescript-language-features/src/features/baseCodeLensProvider.ts index 9576008eab4..6204d3521ac 100644 --- a/extensions/typescript-language-features/src/features/baseCodeLensProvider.ts +++ b/extensions/typescript-language-features/src/features/baseCodeLensProvider.ts @@ -3,18 +3,18 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CancellationToken, CodeLens, CodeLensProvider, Event, EventEmitter, Position, Range, TextDocument, Uri } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import { escapeRegExp } from '../utils/regexp'; import * as typeConverters from '../utils/typeConverters'; -export class ReferencesCodeLens extends CodeLens { +export class ReferencesCodeLens extends vscode.CodeLens { constructor( - public document: Uri, + public document: vscode.Uri, public file: string, - range: Range + range: vscode.Range ) { super(range); } @@ -26,7 +26,7 @@ export class CachedNavTreeResponse { private document: string = ''; public execute( - document: TextDocument, + document: vscode.TextDocument, f: () => Promise ) { if (this.matches(document)) { @@ -36,12 +36,12 @@ export class CachedNavTreeResponse { return this.update(document, f()); } - private matches(document: TextDocument): boolean { + private matches(document: vscode.TextDocument): boolean { return this.version === document.version && this.document === document.uri.toString(); } private update( - document: TextDocument, + document: vscode.TextDocument, response: Promise ): Promise { this.response = response; @@ -51,19 +51,19 @@ export class CachedNavTreeResponse { } } -export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider { - private onDidChangeCodeLensesEmitter = new EventEmitter(); +export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensProvider { + private onDidChangeCodeLensesEmitter = new vscode.EventEmitter(); public constructor( protected client: ITypeScriptServiceClient, private cachedResponse: CachedNavTreeResponse ) { } - public get onDidChangeCodeLenses(): Event { + public get onDidChangeCodeLenses(): vscode.Event { return this.onDidChangeCodeLensesEmitter.event; } - async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise { + async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise { const filepath = this.client.toPath(document.uri); if (!filepath) { return []; @@ -76,7 +76,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider } const tree = response.body; - const referenceableSpans: Range[] = []; + const referenceableSpans: vscode.Range[] = []; if (tree && tree.childItems) { tree.childItems.forEach(item => this.walkNavTree(document, item, null, referenceableSpans)); } @@ -87,16 +87,16 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider } protected abstract extractSymbol( - document: TextDocument, + document: vscode.TextDocument, item: Proto.NavigationTree, parent: Proto.NavigationTree | null - ): Range | null; + ): vscode.Range | null; private walkNavTree( - document: TextDocument, + document: vscode.TextDocument, item: Proto.NavigationTree, parent: Proto.NavigationTree | null, - results: Range[] + results: vscode.Range[] ): void { if (!item) { return; @@ -109,7 +109,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider (item.childItems || []).forEach(child => this.walkNavTree(document, child, item, results)); } - protected getSymbolRange(document: TextDocument, item: Proto.NavigationTree): Range | null { + protected getSymbolRange(document: vscode.TextDocument, item: Proto.NavigationTree): vscode.Range | null { if (!item) { return null; } @@ -131,8 +131,8 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider const identifierMatch = new RegExp(`^(.*?(\\b|\\W))${escapeRegExp(item.text || '')}(\\b|\\W)`, 'gm'); const match = identifierMatch.exec(text); const prefixLength = match ? match.index + match[1].length : 0; - const startOffset = document.offsetAt(new Position(range.start.line, range.start.character)) + prefixLength; - return new Range( + const startOffset = document.offsetAt(new vscode.Position(range.start.line, range.start.character)) + prefixLength; + return new vscode.Range( document.positionAt(startOffset), document.positionAt(startOffset + item.text.length)); } diff --git a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts index d4be308cfb0..f46c5e4c431 100644 --- a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts +++ b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; -import { CancellationTokenSource, EventEmitter, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Uri, workspace } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import API from '../utils/api'; @@ -32,7 +32,7 @@ function mode2ScriptKind(mode: string): 'TS' | 'TSX' | 'JS' | 'JSX' | undefined class SyncedBuffer { constructor( - private readonly document: TextDocument, + private readonly document: vscode.TextDocument, public readonly filepath: string, private readonly client: ITypeScriptServiceClient ) { } @@ -66,7 +66,7 @@ class SyncedBuffer { this.client.execute('open', args, false); } - public get resource(): Uri { + public get resource(): vscode.Uri { return this.document.uri; } @@ -94,7 +94,7 @@ class SyncedBuffer { this.client.execute('close', args, false); } - public onContentChanged(events: TextDocumentContentChangeEvent[]): void { + public onContentChanged(events: vscode.TextDocumentContentChangeEvent[]): void { for (const { range, text } of events) { const args: Proto.ChangeRequestArgs = { insertString: text, @@ -108,7 +108,7 @@ class SyncedBuffer { class SyncedBufferMap extends ResourceMap { public getForPath(filePath: string): SyncedBuffer | undefined { - return this.get(Uri.file(filePath)); + return this.get(vscode.Uri.file(filePath)); } public get allBuffers(): Iterable { @@ -131,7 +131,7 @@ class GetErrRequest { files: string[], onDone: () => void ) { - const token = new CancellationTokenSource(); + const token = new vscode.CancellationTokenSource(); return new GetErrRequest(client, files, token, onDone); } @@ -140,7 +140,7 @@ class GetErrRequest { private constructor( client: ITypeScriptServiceClient, public readonly files: string[], - private readonly _token: CancellationTokenSource, + private readonly _token: vscode.CancellationTokenSource, onDone: () => void ) { const args: Proto.GeterrRequestArgs = { @@ -191,15 +191,15 @@ export default class BufferSyncSupport extends Disposable { this.diagnosticDelayer = new Delayer(300); - const pathNormalizer = (path: Uri) => this.client.normalizedPath(path); + const pathNormalizer = (path: vscode.Uri) => this.client.normalizedPath(path); this.syncedBuffers = new SyncedBufferMap(pathNormalizer); this.pendingDiagnostics = new PendingDiagnostics(pathNormalizer); this.updateConfiguration(); - workspace.onDidChangeConfiguration(this.updateConfiguration, this, this._disposables); + vscode.workspace.onDidChangeConfiguration(this.updateConfiguration, this, this._disposables); } - private readonly _onDelete = this._register(new EventEmitter()); + private readonly _onDelete = this._register(new vscode.EventEmitter()); public readonly onDelete = this._onDelete.event; public listen(): void { @@ -207,22 +207,22 @@ export default class BufferSyncSupport extends Disposable { return; } this.listening = true; - workspace.onDidOpenTextDocument(this.openTextDocument, this, this._disposables); - workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this._disposables); - workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this._disposables); - workspace.textDocuments.forEach(this.openTextDocument, this); + vscode.workspace.onDidOpenTextDocument(this.openTextDocument, this, this._disposables); + vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this._disposables); + vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this._disposables); + vscode.workspace.textDocuments.forEach(this.openTextDocument, this); } - public handles(resource: Uri): boolean { + public handles(resource: vscode.Uri): boolean { return this.syncedBuffers.has(resource); } - public toResource(filePath: string): Uri { + public toResource(filePath: string): vscode.Uri { const buffer = this.syncedBuffers.getForPath(filePath); if (buffer) { return buffer.resource; } - return Uri.file(filePath); + return vscode.Uri.file(filePath); } public reOpenDocuments(): void { @@ -231,7 +231,7 @@ export default class BufferSyncSupport extends Disposable { } } - public openTextDocument(document: TextDocument): void { + public openTextDocument(document: vscode.TextDocument): void { if (!this.modeIds.has(document.languageId)) { return; } @@ -251,7 +251,7 @@ export default class BufferSyncSupport extends Disposable { this.requestDiagnostic(syncedBuffer); } - public closeResource(resource: Uri): void { + public closeResource(resource: vscode.Uri): void { const syncedBuffer = this.syncedBuffers.get(resource); if (!syncedBuffer) { return; @@ -264,11 +264,11 @@ export default class BufferSyncSupport extends Disposable { } } - private onDidCloseTextDocument(document: TextDocument): void { + private onDidCloseTextDocument(document: vscode.TextDocument): void { this.closeResource(document.uri); } - private onDidChangeTextDocument(e: TextDocumentChangeEvent): void { + private onDidChangeTextDocument(e: vscode.TextDocumentChangeEvent): void { const syncedBuffer = this.syncedBuffers.get(e.document.uri); if (!syncedBuffer) { return; @@ -294,7 +294,7 @@ export default class BufferSyncSupport extends Disposable { this.triggerDiagnostics(); } - public getErr(resources: Uri[]): any { + public getErr(resources: vscode.Uri[]): any { const handledResources = resources.filter(resource => this.handles(resource)); if (!handledResources.length) { return; @@ -325,7 +325,7 @@ export default class BufferSyncSupport extends Disposable { return true; } - public hasPendingDiagnostics(resource: Uri): boolean { + public hasPendingDiagnostics(resource: vscode.Uri): boolean { return this.pendingDiagnostics.has(resource); } @@ -361,8 +361,8 @@ export default class BufferSyncSupport extends Disposable { } private updateConfiguration() { - const jsConfig = workspace.getConfiguration('javascript', null); - const tsConfig = workspace.getConfiguration('typescript', null); + const jsConfig = vscode.workspace.getConfiguration('javascript', null); + const tsConfig = vscode.workspace.getConfiguration('typescript', null); this._validateJavaScript = jsConfig.get('validate.enable', true); this._validateTypeScript = tsConfig.get('validate.enable', true); diff --git a/extensions/typescript-language-features/src/features/definitionProviderBase.ts b/extensions/typescript-language-features/src/features/definitionProviderBase.ts index 029fe0fad64..88d61f56a87 100644 --- a/extensions/typescript-language-features/src/features/definitionProviderBase.ts +++ b/extensions/typescript-language-features/src/features/definitionProviderBase.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CancellationToken, Location, Position, TextDocument } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import * as typeConverters from '../utils/typeConverters'; @@ -16,10 +16,10 @@ export default class TypeScriptDefinitionProviderBase { protected async getSymbolLocations( definitionType: 'definition' | 'implementation' | 'typeDefinition', - document: TextDocument, - position: Position, - token: CancellationToken | boolean - ): Promise { + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken | boolean + ): Promise { const filepath = this.client.toPath(document.uri); if (!filepath) { return undefined; diff --git a/extensions/typescript-language-features/src/features/fileConfigurationManager.ts b/extensions/typescript-language-features/src/features/fileConfigurationManager.ts index 8673f3a1c91..90587ba4925 100644 --- a/extensions/typescript-language-features/src/features/fileConfigurationManager.ts +++ b/extensions/typescript-language-features/src/features/fileConfigurationManager.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CancellationToken, Disposable, FormattingOptions, TextDocument, window, workspace as Workspace, workspace, WorkspaceConfiguration } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import API from '../utils/api'; @@ -35,13 +35,13 @@ function areFileConfigurationsEqual(a: FileConfiguration, b: FileConfiguration): } export default class FileConfigurationManager { - private onDidCloseTextDocumentSub: Disposable | undefined; + private onDidCloseTextDocumentSub: vscode.Disposable | undefined; private formatOptions = new ResourceMap(); public constructor( private readonly client: ITypeScriptServiceClient ) { - this.onDidCloseTextDocumentSub = Workspace.onDidCloseTextDocument((textDocument) => { + this.onDidCloseTextDocumentSub = vscode.workspace.onDidCloseTextDocument((textDocument) => { // When a document gets closed delete the cached formatting options. // This is necessary since the tsserver now closed a project when its // last file in it closes which drops the stored formatting options @@ -58,23 +58,23 @@ export default class FileConfigurationManager { } public async ensureConfigurationForDocument( - document: TextDocument, - token: CancellationToken | undefined + document: vscode.TextDocument, + token: vscode.CancellationToken | undefined ): Promise { - const editor = window.visibleTextEditors.find(editor => editor.document.fileName === document.fileName); + const editor = vscode.window.visibleTextEditors.find(editor => editor.document.fileName === document.fileName); if (editor) { const formattingOptions = { tabSize: editor.options.tabSize, insertSpaces: editor.options.insertSpaces - } as FormattingOptions; + } as vscode.FormattingOptions; return this.ensureConfigurationOptions(document, formattingOptions, token); } } public async ensureConfigurationOptions( - document: TextDocument, - options: FormattingOptions, - token: CancellationToken | undefined + document: vscode.TextDocument, + options: vscode.FormattingOptions, + token: vscode.CancellationToken | undefined ): Promise { const file = this.client.toPath(document.uri); if (!file) { @@ -100,8 +100,8 @@ export default class FileConfigurationManager { } private getFileOptions( - document: TextDocument, - options: FormattingOptions + document: vscode.TextDocument, + options: vscode.FormattingOptions ): FileConfiguration { return { formatOptions: this.getFormatOptions(document, options), @@ -110,10 +110,10 @@ export default class FileConfigurationManager { } private getFormatOptions( - document: TextDocument, - options: FormattingOptions + document: vscode.TextDocument, + options: vscode.FormattingOptions ): Proto.FormatCodeSettings { - const config = workspace.getConfiguration( + const config = vscode.workspace.getConfiguration( isTypeScriptDocument(document) ? 'typescript.format' : 'javascript.format', document.uri); @@ -141,12 +141,12 @@ export default class FileConfigurationManager { }; } - private getPreferences(document: TextDocument): Proto.UserPreferences { + private getPreferences(document: vscode.TextDocument): Proto.UserPreferences { if (!this.client.apiVersion.gte(API.v290)) { return {}; } - const preferences = workspace.getConfiguration( + const preferences = vscode.workspace.getConfiguration( isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences', document.uri); @@ -158,7 +158,7 @@ export default class FileConfigurationManager { } } -function getQuoteStylePreference(config: WorkspaceConfiguration) { +function getQuoteStylePreference(config: vscode.WorkspaceConfiguration) { switch (config.get('quoteStyle')) { case 'single': return 'single'; case 'double': return 'double'; @@ -166,7 +166,7 @@ function getQuoteStylePreference(config: WorkspaceConfiguration) { } } -function getImportModuleSpecifierPreference(config: WorkspaceConfiguration) { +function getImportModuleSpecifierPreference(config: vscode.WorkspaceConfiguration) { switch (config.get('importModuleSpecifier')) { case 'relative': return 'relative'; case 'non-relative': return 'non-relative'; diff --git a/extensions/typescript-language-features/src/features/jsDocCompletions.ts b/extensions/typescript-language-features/src/features/jsDocCompletions.ts index b8683b81e77..49a51c95807 100644 --- a/extensions/typescript-language-features/src/features/jsDocCompletions.ts +++ b/extensions/typescript-language-features/src/features/jsDocCompletions.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CancellationToken, CompletionItem, CompletionItemKind, CompletionItemProvider, Disposable, DocumentSelector, languages, Position, Range, SnippetString, TextDocument, TextEditor, Uri, window } from 'vscode'; +import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; @@ -14,12 +14,12 @@ import * as typeConverters from '../utils/typeConverters'; const localize = nls.loadMessageBundle(); -class JsDocCompletionItem extends CompletionItem { +class JsDocCompletionItem extends vscode.CompletionItem { constructor( - document: TextDocument, - position: Position + document: vscode.TextDocument, + position: vscode.Position ) { - super('/** */', CompletionItemKind.Snippet); + super('/** */', vscode.CompletionItemKind.Snippet); this.detail = localize('typescript.jsDocCompletionItem.documentation', 'JSDoc comment'); this.insertText = ''; this.sortText = '\0'; @@ -28,7 +28,7 @@ class JsDocCompletionItem extends CompletionItem { const prefix = line.slice(0, position.character).match(/\/\**\s*$/); const suffix = line.slice(position.character).match(/^\s*\**\//); const start = position.translate(0, prefix ? -prefix[0].length : 0); - this.range = new Range( + this.range = new vscode.Range( start, position.translate(0, suffix ? suffix[0].length : 0)); @@ -40,7 +40,7 @@ class JsDocCompletionItem extends CompletionItem { } } -class JsDocCompletionProvider implements CompletionItemProvider { +class JsDocCompletionProvider implements vscode.CompletionItemProvider { constructor( private readonly client: ITypeScriptServiceClient, @@ -50,10 +50,10 @@ class JsDocCompletionProvider implements CompletionItemProvider { } public async provideCompletionItems( - document: TextDocument, - position: Position, - token: CancellationToken - ): Promise { + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken + ): Promise { const file = this.client.toPath(document.uri); if (!file) { return []; @@ -72,8 +72,8 @@ class JsDocCompletionProvider implements CompletionItemProvider { private async isCommentableLocation( file: string, - position: Position, - token: CancellationToken + position: vscode.Position, + token: vscode.CancellationToken ): Promise { const args: Proto.FileRequestArgs = { file @@ -104,7 +104,7 @@ class JsDocCompletionProvider implements CompletionItemProvider { return matchesPosition(body); } - private isValidCursorPosition(document: TextDocument, position: Position): boolean { + private isValidCursorPosition(document: vscode.TextDocument, position: vscode.Position): boolean { // Only show the JSdoc completion when the everything before the cursor is whitespace // or could be the opening of a comment const line = document.lineAt(position.line).text; @@ -112,7 +112,7 @@ class JsDocCompletionProvider implements CompletionItemProvider { return prefix.match(/^\s*$|\/\*\*\s*$|^\s*\/\*\*+\s*$/) !== null; } - public resolveCompletionItem(item: CompletionItem, _token: CancellationToken) { + public resolveCompletionItem(item: vscode.CompletionItem, _token: vscode.CancellationToken) { return item; } } @@ -129,13 +129,13 @@ class TryCompleteJsDocCommand implements Command { * Try to insert a jsdoc comment, using a template provide by typescript * if possible, otherwise falling back to a default comment format. */ - public async execute(resource: Uri, start: Position): Promise { + public async execute(resource: vscode.Uri, start: vscode.Position): Promise { const file = this.client.toPath(resource); if (!file) { return false; } - const editor = window.activeTextEditor; + const editor = vscode.window.activeTextEditor; if (!editor || editor.document.uri.fsPath !== resource.fsPath) { return false; } @@ -148,7 +148,7 @@ class TryCompleteJsDocCommand implements Command { return this.tryInsertDefaultDoc(editor, start); } - private async tryInsertJsDocFromTemplate(editor: TextEditor, file: string, position: Position): Promise { + private async tryInsertJsDocFromTemplate(editor: vscode.TextEditor, file: string, position: vscode.Position): Promise { const snippet = await TryCompleteJsDocCommand.getSnippetTemplate(this.client, file, position); if (!snippet) { return false; @@ -159,7 +159,7 @@ class TryCompleteJsDocCommand implements Command { { undoStopBefore: false, undoStopAfter: true }); } - public static getSnippetTemplate(client: ITypeScriptServiceClient, file: string, position: Position): Promise { + public static getSnippetTemplate(client: ITypeScriptServiceClient, file: string, position: vscode.Position): Promise { const args = typeConverters.Position.toFileLocationRequestArgs(file, position); return Promise.race([ client.execute('docCommentTemplate', args), @@ -181,14 +181,14 @@ class TryCompleteJsDocCommand implements Command { /** * Insert the default JSDoc */ - private tryInsertDefaultDoc(editor: TextEditor, position: Position): Thenable { - const snippet = new SnippetString(`/**\n * $0\n */`); + private tryInsertDefaultDoc(editor: vscode.TextEditor, position: vscode.Position): Thenable { + const snippet = new vscode.SnippetString(`/**\n * $0\n */`); return editor.insertSnippet(snippet, position, { undoStopBefore: false, undoStopAfter: true }); } } -export function templateToSnippet(template: string): SnippetString { +export function templateToSnippet(template: string): vscode.SnippetString { // TODO: use append placeholder let snippetIndex = 1; template = template.replace(/\$/g, '\\$'); @@ -204,16 +204,16 @@ export function templateToSnippet(template: string): SnippetString { out += post + ` \${${snippetIndex++}}`; return out; }); - return new SnippetString(template); + return new vscode.SnippetString(template); } export function register( - selector: DocumentSelector, + selector: vscode.DocumentSelector, client: ITypeScriptServiceClient, commandManager: CommandManager -): Disposable { +): vscode.Disposable { return new ConfigurationDependentRegistration('jsDocCompletion', 'enabled', () => { - return languages.registerCompletionItemProvider(selector, + return vscode.languages.registerCompletionItemProvider(selector, new JsDocCompletionProvider(client, commandManager), '*'); }); diff --git a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts index 522c1f8364e..cea7c0a2bc4 100644 --- a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts +++ b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts @@ -8,7 +8,7 @@ * https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences * ------------------------------------------------------------------------------------------ */ -import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Memento, Range, Uri, workspace } from 'vscode'; +import * as vscode from 'vscode'; import { DiagnosticKind } from './features/diagnostics'; import FileConfigurationManager from './features/fileConfigurationManager'; import { register as registerUpdatePathsOnRename } from './features/updatePathsOnRename'; @@ -48,7 +48,7 @@ export default class TypeScriptServiceClientHost extends Disposable { constructor( descriptions: LanguageDescription[], - workspaceState: Memento, + workspaceState: vscode.Memento, plugins: TypeScriptServerPlugin[], private readonly commandManager: CommandManager, logDirectoryProvider: LogDirectoryProvider @@ -63,7 +63,7 @@ export default class TypeScriptServiceClientHost extends Disposable { this.triggerAllDiagnostics(); }, 1500); }; - const configFileWatcher = workspace.createFileSystemWatcher('**/[tj]sconfig.json'); + const configFileWatcher = vscode.workspace.createFileSystemWatcher('**/[tj]sconfig.json'); this._register(configFileWatcher); configFileWatcher.onDidCreate(handleProjectCreateOrDelete, this, this._disposables); configFileWatcher.onDidDelete(handleProjectCreateOrDelete, this, this._disposables); @@ -133,7 +133,7 @@ export default class TypeScriptServiceClientHost extends Disposable { this.triggerAllDiagnostics(); }); - workspace.onDidChangeConfiguration(this.configurationChanged, this, this._disposables); + vscode.workspace.onDidChangeConfiguration(this.configurationChanged, this, this._disposables); this.configurationChanged(); } @@ -154,7 +154,7 @@ export default class TypeScriptServiceClientHost extends Disposable { this.triggerAllDiagnostics(); } - public async handles(resource: Uri): Promise { + public async handles(resource: vscode.Uri): Promise { const provider = await this.findLanguage(resource); if (provider) { return true; @@ -163,14 +163,14 @@ export default class TypeScriptServiceClientHost extends Disposable { } private configurationChanged(): void { - const typescriptConfig = workspace.getConfiguration('typescript'); + const typescriptConfig = vscode.workspace.getConfiguration('typescript'); this.reportStyleCheckAsWarnings = typescriptConfig.get('reportStyleChecksAsWarnings', true); } - private async findLanguage(resource: Uri): Promise { + private async findLanguage(resource: vscode.Uri): Promise { try { - const doc = await workspace.openTextDocument(resource); + const doc = await vscode.workspace.openTextDocument(resource); return this.languages.find(language => language.handles(resource, doc)); } catch { return undefined; @@ -189,7 +189,7 @@ export default class TypeScriptServiceClientHost extends Disposable { this.client.bufferSyncSupport.requestAllDiagnostics(); // See https://github.com/Microsoft/TypeScript/issues/5530 - workspace.saveAll(false).then(() => { + vscode.workspace.saveAll(false).then(() => { for (const language of this.languagePerId.values()) { language.reInitialize(); } @@ -198,7 +198,7 @@ export default class TypeScriptServiceClientHost extends Disposable { private async diagnosticsReceived( kind: DiagnosticKind, - resource: Uri, + resource: vscode.Uri, diagnostics: Proto.Diagnostic[] ): Promise { const language = await this.findLanguage(resource); @@ -224,10 +224,10 @@ export default class TypeScriptServiceClientHost extends Disposable { if (body.diagnostics.length === 0) { language.configFileDiagnosticsReceived(this.client.toResource(body.configFile), []); } else if (body.diagnostics.length >= 1) { - workspace.openTextDocument(Uri.file(body.configFile)).then((document) => { + vscode.workspace.openTextDocument(vscode.Uri.file(body.configFile)).then((document) => { let curly: [number, number, number] | undefined = undefined; let nonCurly: [number, number, number] | undefined = undefined; - let diagnostic: Diagnostic; + let diagnostic: vscode.Diagnostic; for (let index = 0; index < document.lineCount; index++) { const line = document.lineAt(index); const text = line.text; @@ -246,16 +246,16 @@ export default class TypeScriptServiceClientHost extends Disposable { } const match = curly || nonCurly; if (match) { - diagnostic = new Diagnostic(new Range(match[0], match[1], match[0], match[2]), body.diagnostics[0].text); + diagnostic = new vscode.Diagnostic(new vscode.Range(match[0], match[1], match[0], match[2]), body.diagnostics[0].text); } else { - diagnostic = new Diagnostic(new Range(0, 0, 0, 0), body.diagnostics[0].text); + diagnostic = new vscode.Diagnostic(new vscode.Range(0, 0, 0, 0), body.diagnostics[0].text); } if (diagnostic) { diagnostic.source = language.diagnosticSource; language.configFileDiagnosticsReceived(this.client.toResource(body.configFile), [diagnostic]); } }, _error => { - language.configFileDiagnosticsReceived(this.client.toResource(body.configFile), [new Diagnostic(new Range(0, 0, 0, 0), body.diagnostics[0].text)]); + language.configFileDiagnosticsReceived(this.client.toResource(body.configFile), [new vscode.Diagnostic(new vscode.Range(0, 0, 0, 0), body.diagnostics[0].text)]); }); } }); @@ -264,14 +264,14 @@ export default class TypeScriptServiceClientHost extends Disposable { private createMarkerDatas( diagnostics: Proto.Diagnostic[], source: string - ): (Diagnostic & { reportUnnecessary: any })[] { + ): (vscode.Diagnostic & { reportUnnecessary: any })[] { return diagnostics.map(tsDiag => this.tsDiagnosticToVsDiagnostic(tsDiag, source)); } - private tsDiagnosticToVsDiagnostic(diagnostic: Proto.Diagnostic, source: string): Diagnostic & { reportUnnecessary: any } { + private tsDiagnosticToVsDiagnostic(diagnostic: Proto.Diagnostic, source: string): vscode.Diagnostic & { reportUnnecessary: any } { const { start, end, text } = diagnostic; - const range = new Range(typeConverters.Position.fromLocation(start), typeConverters.Position.fromLocation(end)); - const converted = new Diagnostic(range, text); + const range = new vscode.Range(typeConverters.Position.fromLocation(start), typeConverters.Position.fromLocation(end)); + const converted = new vscode.Diagnostic(range, text); converted.severity = this.getDiagnosticSeverity(diagnostic); converted.source = diagnostic.source || source; if (diagnostic.code) { @@ -284,36 +284,36 @@ export default class TypeScriptServiceClientHost extends Disposable { if (!span) { return undefined; } - return new DiagnosticRelatedInformation(typeConverters.Location.fromTextSpan(this.client.toResource(span.file), span), info.message); - }).filter((x: any) => !!x) as DiagnosticRelatedInformation[]; + return new vscode.DiagnosticRelatedInformation(typeConverters.Location.fromTextSpan(this.client.toResource(span.file), span), info.message); + }).filter((x: any) => !!x) as vscode.DiagnosticRelatedInformation[]; } if (diagnostic.reportsUnnecessary) { - converted.tags = [DiagnosticTag.Unnecessary]; + converted.tags = [vscode.DiagnosticTag.Unnecessary]; } - (converted as Diagnostic & { reportUnnecessary: any }).reportUnnecessary = diagnostic.reportsUnnecessary; - return converted as Diagnostic & { reportUnnecessary: any }; + (converted as vscode.Diagnostic & { reportUnnecessary: any }).reportUnnecessary = diagnostic.reportsUnnecessary; + return converted as vscode.Diagnostic & { reportUnnecessary: any }; } - private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity { + private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): vscode.DiagnosticSeverity { if (this.reportStyleCheckAsWarnings && this.isStyleCheckDiagnostic(diagnostic.code) && diagnostic.category === PConst.DiagnosticCategory.error ) { - return DiagnosticSeverity.Warning; + return vscode.DiagnosticSeverity.Warning; } switch (diagnostic.category) { case PConst.DiagnosticCategory.error: - return DiagnosticSeverity.Error; + return vscode.DiagnosticSeverity.Error; case PConst.DiagnosticCategory.warning: - return DiagnosticSeverity.Warning; + return vscode.DiagnosticSeverity.Warning; case PConst.DiagnosticCategory.suggestion: - return DiagnosticSeverity.Hint; + return vscode.DiagnosticSeverity.Hint; default: - return DiagnosticSeverity.Error; + return vscode.DiagnosticSeverity.Error; } } diff --git a/extensions/typescript-language-features/src/typescriptService.ts b/extensions/typescript-language-features/src/typescriptService.ts index 110f41d2658..bb6baa31915 100644 --- a/extensions/typescript-language-features/src/typescriptService.ts +++ b/extensions/typescript-language-features/src/typescriptService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CancellationToken, Event, Uri } from 'vscode'; +import * as vscode from 'vscode'; import BufferSyncSupport from './features/bufferSyncSupport'; import * as Proto from './protocol'; import API from './utils/api'; @@ -17,27 +17,27 @@ export interface ITypeScriptServiceClient { * * Does not try handling case insensitivity. */ - normalizedPath(resource: Uri): string | null; + normalizedPath(resource: vscode.Uri): string | null; /** * Map a resource to a normalized path * * This will attempt to handle case insensitivity. */ - toPath(resource: Uri): string | null; + toPath(resource: vscode.Uri): string | null; /** * Convert a path to a resource. */ - toResource(filepath: string): Uri; + toResource(filepath: string): vscode.Uri; - getWorkspaceRootForResource(resource: Uri): string | undefined; + getWorkspaceRootForResource(resource: vscode.Uri): string | undefined; - readonly onTsServerStarted: Event; - readonly onProjectLanguageServiceStateChanged: Event; - readonly onDidBeginInstallTypings: Event; - readonly onDidEndInstallTypings: Event; - readonly onTypesInstallerInitializationFailed: Event; + readonly onTsServerStarted: vscode.Event; + readonly onProjectLanguageServiceStateChanged: vscode.Event; + readonly onDidBeginInstallTypings: vscode.Event; + readonly onDidEndInstallTypings: vscode.Event; + readonly onTypesInstallerInitializationFailed: vscode.Event; readonly apiVersion: API; readonly plugins: TypeScriptServerPlugin[]; @@ -45,42 +45,42 @@ export interface ITypeScriptServiceClient { readonly logger: Logger; readonly bufferSyncSupport: BufferSyncSupport; - execute(command: 'configure', args: Proto.ConfigureRequestArguments, token?: CancellationToken): Promise; - execute(command: 'open', args: Proto.OpenRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise; - execute(command: 'close', args: Proto.FileRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise; - execute(command: 'change', args: Proto.ChangeRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise; - execute(command: 'quickinfo', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'completions', args: Proto.CompletionsRequestArgs, token?: CancellationToken): Promise; - execute(command: 'completionInfo', args: Proto.CompletionsRequestArgs, token?: CancellationToken): Promise; - execute(command: 'completionEntryDetails', args: Proto.CompletionDetailsRequestArgs, token?: CancellationToken): Promise; - execute(command: 'signatureHelp', args: Proto.SignatureHelpRequestArgs, token?: CancellationToken): Promise; - execute(command: 'definition', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'definitionAndBoundSpan', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'implementation', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'typeDefinition', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'references', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'navto', args: Proto.NavtoRequestArgs, token?: CancellationToken): Promise; - execute(command: 'format', args: Proto.FormatRequestArgs, token?: CancellationToken): Promise; - execute(command: 'formatonkey', args: Proto.FormatOnKeyRequestArgs, token?: CancellationToken): Promise; - execute(command: 'rename', args: Proto.RenameRequestArgs, token?: CancellationToken): Promise; - execute(command: 'occurrences', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'projectInfo', args: Proto.ProjectInfoRequestArgs, token?: CancellationToken): Promise; - execute(command: 'reloadProjects', args: any, expectedResult: boolean, token?: CancellationToken): Promise; - execute(command: 'reload', args: Proto.ReloadRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise; - execute(command: 'compilerOptionsForInferredProjects', args: Proto.SetCompilerOptionsForInferredProjectsArgs, token?: CancellationToken): Promise; - execute(command: 'navtree', args: Proto.FileRequestArgs, token?: CancellationToken): Promise; - execute(command: 'getCodeFixes', args: Proto.CodeFixRequestArgs, token?: CancellationToken): Promise; - execute(command: 'getSupportedCodeFixes', args: null, token?: CancellationToken): Promise; - execute(command: 'getCombinedCodeFix', args: Proto.GetCombinedCodeFixRequestArgs, token?: CancellationToken): Promise; - execute(command: 'docCommentTemplate', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise; - execute(command: 'getApplicableRefactors', args: Proto.GetApplicableRefactorsRequestArgs, token?: CancellationToken): Promise; - execute(command: 'getEditsForRefactor', args: Proto.GetEditsForRefactorRequestArgs, token?: CancellationToken): Promise; - execute(command: 'applyCodeActionCommand', args: Proto.ApplyCodeActionCommandRequestArgs, token?: CancellationToken): Promise; - execute(command: 'organizeImports', args: Proto.OrganizeImportsRequestArgs, token?: CancellationToken): Promise; - execute(command: 'getOutliningSpans', args: Proto.FileRequestArgs, token: CancellationToken): Promise; + execute(command: 'configure', args: Proto.ConfigureRequestArguments, token?: vscode.CancellationToken): Promise; + execute(command: 'open', args: Proto.OpenRequestArgs, expectedResult: boolean, token?: vscode.CancellationToken): Promise; + execute(command: 'close', args: Proto.FileRequestArgs, expectedResult: boolean, token?: vscode.CancellationToken): Promise; + execute(command: 'change', args: Proto.ChangeRequestArgs, expectedResult: boolean, token?: vscode.CancellationToken): Promise; + execute(command: 'quickinfo', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'completions', args: Proto.CompletionsRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'completionInfo', args: Proto.CompletionsRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'completionEntryDetails', args: Proto.CompletionDetailsRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'signatureHelp', args: Proto.SignatureHelpRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'definition', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'definitionAndBoundSpan', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'implementation', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'typeDefinition', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'references', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'navto', args: Proto.NavtoRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'format', args: Proto.FormatRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'formatonkey', args: Proto.FormatOnKeyRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'rename', args: Proto.RenameRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'occurrences', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'projectInfo', args: Proto.ProjectInfoRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'reloadProjects', args: any, expectedResult: boolean, token?: vscode.CancellationToken): Promise; + execute(command: 'reload', args: Proto.ReloadRequestArgs, expectedResult: boolean, token?: vscode.CancellationToken): Promise; + execute(command: 'compilerOptionsForInferredProjects', args: Proto.SetCompilerOptionsForInferredProjectsArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'navtree', args: Proto.FileRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'getCodeFixes', args: Proto.CodeFixRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'getSupportedCodeFixes', args: null, token?: vscode.CancellationToken): Promise; + execute(command: 'getCombinedCodeFix', args: Proto.GetCombinedCodeFixRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'docCommentTemplate', args: Proto.FileLocationRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'getApplicableRefactors', args: Proto.GetApplicableRefactorsRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'getEditsForRefactor', args: Proto.GetEditsForRefactorRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'applyCodeActionCommand', args: Proto.ApplyCodeActionCommandRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'organizeImports', args: Proto.OrganizeImportsRequestArgs, token?: vscode.CancellationToken): Promise; + execute(command: 'getOutliningSpans', args: Proto.FileRequestArgs, token: vscode.CancellationToken): Promise; execute(command: 'getEditsForFileRename', args: Proto.GetEditsForFileRenameRequestArgs): Promise; - execute(command: 'jsxClosingTag', args: Proto.JsxClosingTagRequestArgs, token: CancellationToken): Promise; - execute(command: string, args: any, expectedResult: boolean | CancellationToken, token?: CancellationToken): Promise; + execute(command: 'jsxClosingTag', args: Proto.JsxClosingTagRequestArgs, token: vscode.CancellationToken): Promise; + execute(command: string, args: any, expectedResult: boolean | vscode.CancellationToken, token?: vscode.CancellationToken): Promise; - executeAsync(command: 'geterr', args: Proto.GeterrRequestArgs, token: CancellationToken): Promise; + executeAsync(command: 'geterr', args: Proto.GeterrRequestArgs, token: vscode.CancellationToken): Promise; } \ No newline at end of file diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts index 1655c6b5419..adc73a29e3b 100644 --- a/extensions/typescript-language-features/src/typescriptServiceClient.ts +++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts @@ -6,7 +6,7 @@ import * as cp from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; -import { CancellationToken, commands, env, EventEmitter, Memento, MessageItem, Uri, window, workspace } from 'vscode'; +import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import BufferSyncSupport from './features/bufferSyncSupport'; import { DiagnosticKind, DiagnosticsManager } from './features/diagnostics'; @@ -152,7 +152,7 @@ class ForkedTsServerProcess { export interface TsDiagnostics { readonly kind: DiagnosticKind; - readonly resource: Uri; + readonly resource: vscode.Uri; readonly diagnostics: Proto.Diagnostic[]; } @@ -195,7 +195,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType public readonly diagnosticsManager: DiagnosticsManager; constructor( - private readonly workspaceState: Memento, + private readonly workspaceState: vscode.Memento, private readonly onDidChangeTypeScriptVersion: (version: TypeScriptVersion) => void, public readonly plugins: TypeScriptServerPlugin[], private readonly logDirectoryProvider: LogDirectoryProvider, @@ -233,7 +233,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType this.diagnosticsManager.delete(resource); }, null, this._disposables); - workspace.onDidChangeConfiguration(() => { + vscode.workspace.onDidChangeConfiguration(() => { const oldConfiguration = this._configuration; this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace(); @@ -291,28 +291,28 @@ export default class TypeScriptServiceClient extends Disposable implements IType } } - private readonly _onTsServerStarted = this._register(new EventEmitter()); + private readonly _onTsServerStarted = this._register(new vscode.EventEmitter()); public readonly onTsServerStarted = this._onTsServerStarted.event; - private readonly _onDiagnosticsReceived = this._register(new EventEmitter()); + private readonly _onDiagnosticsReceived = this._register(new vscode.EventEmitter()); public readonly onDiagnosticsReceived = this._onDiagnosticsReceived.event; - private readonly _onConfigDiagnosticsReceived = this._register(new EventEmitter()); + private readonly _onConfigDiagnosticsReceived = this._register(new vscode.EventEmitter()); public readonly onConfigDiagnosticsReceived = this._onConfigDiagnosticsReceived.event; - private readonly _onResendModelsRequested = this._register(new EventEmitter()); + private readonly _onResendModelsRequested = this._register(new vscode.EventEmitter()); public readonly onResendModelsRequested = this._onResendModelsRequested.event; - private readonly _onProjectLanguageServiceStateChanged = this._register(new EventEmitter()); + private readonly _onProjectLanguageServiceStateChanged = this._register(new vscode.EventEmitter()); public readonly onProjectLanguageServiceStateChanged = this._onProjectLanguageServiceStateChanged.event; - private readonly _onDidBeginInstallTypings = this._register(new EventEmitter()); + private readonly _onDidBeginInstallTypings = this._register(new vscode.EventEmitter()); public readonly onDidBeginInstallTypings = this._onDidBeginInstallTypings.event; - private readonly _onDidEndInstallTypings = this._register(new EventEmitter()); + private readonly _onDidEndInstallTypings = this._register(new vscode.EventEmitter()); public readonly onDidEndInstallTypings = this._onDidEndInstallTypings.event; - private readonly _onTypesInstallerInitializationFailed = this._register(new EventEmitter()); + private readonly _onTypesInstallerInitializationFailed = this._register(new vscode.EventEmitter()); public readonly onTypesInstallerInitializationFailed = this._onTypesInstallerInitializationFailed.event; public get apiVersion(): API { @@ -360,7 +360,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType this.info(`Using tsserver from: ${currentVersion.path}`); if (!fs.existsSync(currentVersion.tsServerPath)) { - window.showWarningMessage(localize('noServerFound', 'The path {0} doesn\'t point to a valid tsserver install. Falling back to bundled TypeScript version.', currentVersion.path)); + vscode.window.showWarningMessage(localize('noServerFound', 'The path {0} doesn\'t point to a valid tsserver install. Falling back to bundled TypeScript version.', currentVersion.path)); this.versionPicker.useBundledVersion(); currentVersion = this.versionPicker.currentVersion; @@ -384,7 +384,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType if (err || !childProcess) { this.lastError = err; this.error('Starting TSServer failed with error.', err); - window.showErrorMessage(localize('serverCouldNotBeStarted', 'TypeScript language server couldn\'t be started. Error message is: {0}', err.message || err)); + vscode.window.showErrorMessage(localize('serverCouldNotBeStarted', 'TypeScript language server couldn\'t be started. Error message is: {0}', err.message || err)); /* __GDPR__ "error" : { "${include}": [ @@ -471,7 +471,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType public async openTsServerLogFile(): Promise { if (!this.apiVersion.gte(API.v222)) { - window.showErrorMessage( + vscode.window.showErrorMessage( localize( 'typescript.openTsServerLog.notSupported', 'TS Server logging requires TS 2.2.2+')); @@ -479,7 +479,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType } if (this._configuration.tsServerLogLevel === TsServerLogLevel.Off) { - window.showErrorMessage( + vscode.window.showErrorMessage( localize( 'typescript.openTsServerLog.loggingNotEnabled', 'TS Server logging is off. Please set `typescript.tsserver.log` and restart the TS server to enable logging'), @@ -490,7 +490,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType }) .then(selection => { if (selection) { - return workspace.getConfiguration().update('typescript.tsserver.log', 'verbose', true).then(() => { + return vscode.workspace.getConfiguration().update('typescript.tsserver.log', 'verbose', true).then(() => { this.restartTsServer(); }); } @@ -500,17 +500,17 @@ export default class TypeScriptServiceClient extends Disposable implements IType } if (!this.tsServerLogFile) { - window.showWarningMessage(localize( + vscode.window.showWarningMessage(localize( 'typescript.openTsServerLog.noLogFile', 'TS Server has not started logging.')); return false; } try { - await commands.executeCommand('revealFileInOS', Uri.parse(this.tsServerLogFile)); + await vscode.commands.executeCommand('revealFileInOS', vscode.Uri.parse(this.tsServerLogFile)); return true; } catch { - window.showWarningMessage(localize( + vscode.window.showWarningMessage(localize( 'openTsServerLog.openFileFailedFailed', 'Could not open TS Server log file')); return false; @@ -553,7 +553,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType reportIssue } - interface MyMessageItem extends MessageItem { + interface MyMessageItem extends vscode.MessageItem { id: MessageAction; } @@ -574,7 +574,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType if (diff < 10 * 1000 /* 10 seconds */) { this.lastStart = Date.now(); startService = false; - prompt = window.showErrorMessage( + prompt = vscode.window.showErrorMessage( localize('serverDiedAfterStart', 'The TypeScript language service died 5 times right after it got started. The service will not be restarted.'), { title: localize('serverDiedReportIssue', 'Report Issue'), @@ -591,7 +591,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType this.resetClientVersion(); } else if (diff < 60 * 1000 /* 1 Minutes */) { this.lastStart = Date.now(); - prompt = window.showWarningMessage( + prompt = vscode.window.showWarningMessage( localize('serverDied', 'The TypeScript language service died unexpectedly 5 times in the last 5 Minutes.'), { title: localize('serverDiedReportIssue', 'Report Issue'), @@ -601,7 +601,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType if (prompt) { prompt.then(item => { if (item && item.id === MessageAction.reportIssue) { - return commands.executeCommand('workbench.action.reportIssues'); + return vscode.commands.executeCommand('workbench.action.reportIssues'); } return undefined; }); @@ -613,7 +613,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType } } - public normalizedPath(resource: Uri): string | null { + public normalizedPath(resource: vscode.Uri): string | null { if (this._apiVersion.gte(API.v213)) { if (resource.scheme === fileSchemes.walkThroughSnippet || resource.scheme === fileSchemes.untitled) { const dirName = path.dirname(resource.path); @@ -635,7 +635,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/'); } - public toPath(resource: Uri): string | null { + public toPath(resource: vscode.Uri): string | null { return this.normalizedPath(resource); } @@ -643,11 +643,11 @@ export default class TypeScriptServiceClient extends Disposable implements IType return this._apiVersion.gte(API.v270) ? '^' : ''; } - public toResource(filepath: string): Uri { + public toResource(filepath: string): vscode.Uri { if (this._apiVersion.gte(API.v213)) { if (filepath.startsWith(TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME_COLON) || (filepath.startsWith(fileSchemes.untitled + ':')) ) { - let resource = Uri.parse(filepath); + let resource = vscode.Uri.parse(filepath); if (this.inMemoryResourcePrefix) { const dirName = path.dirname(resource.path); const fileName = path.basename(resource.path); @@ -661,8 +661,8 @@ export default class TypeScriptServiceClient extends Disposable implements IType return this.bufferSyncSupport.toResource(filepath); } - public getWorkspaceRootForResource(resource: Uri): string | undefined { - const roots = workspace.workspaceFolders; + public getWorkspaceRootForResource(resource: vscode.Uri): string | undefined { + const roots = vscode.workspace.workspaceFolders; if (!roots || !roots.length) { return undefined; } @@ -679,12 +679,12 @@ export default class TypeScriptServiceClient extends Disposable implements IType return undefined; } - public executeAsync(command: string, args: Proto.GeterrRequestArgs, token: CancellationToken): Promise { + public executeAsync(command: string, args: Proto.GeterrRequestArgs, token: vscode.CancellationToken): Promise { return this.executeImpl(command, args, { isAsync: true, token, expectsResult: true }); } - public execute(command: string, args: any, expectsResultOrToken?: boolean | CancellationToken): Promise { - let token: CancellationToken | undefined = undefined; + public execute(command: string, args: any, expectsResultOrToken?: boolean | vscode.CancellationToken): Promise { + let token: vscode.CancellationToken | undefined = undefined; let expectsResult = true; if (typeof expectsResultOrToken === 'boolean') { expectsResult = expectsResultOrToken; @@ -694,7 +694,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType return this.executeImpl(command, args, { isAsync: false, token, expectsResult }); } - private executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: CancellationToken, expectsResult: boolean }): Promise { + private executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: vscode.CancellationToken, expectsResult: boolean }): Promise { const request = this.requestQueue.createRequest(command, args); const requestInfo: RequestItem = { request: request, @@ -874,7 +874,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType case 'projectsUpdatedInBackground': if (event.body) { const body = (event as Proto.ProjectsUpdatedInBackgroundEvent).body; - const resources = body.openFiles.map(Uri.file); + const resources = body.openFiles.map(vscode.Uri.file); this.bufferSyncSupport.getErr(resources); } break; @@ -1048,7 +1048,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType const getTsLocale = (configuration: TypeScriptServiceConfiguration): string | undefined => (configuration.locale ? configuration.locale - : env.language); + : vscode.env.language); function getDignosticsKind(event: Proto.Event) { switch (event.event) { diff --git a/extensions/typescript-language-features/src/utils/codeAction.ts b/extensions/typescript-language-features/src/utils/codeAction.ts index e2c71edb370..0271a93c8fb 100644 --- a/extensions/typescript-language-features/src/utils/codeAction.ts +++ b/extensions/typescript-language-features/src/utils/codeAction.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { workspace, WorkspaceEdit } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import * as typeConverters from './typeConverters'; @@ -11,7 +11,7 @@ import * as typeConverters from './typeConverters'; export function getEditForCodeAction( client: ITypeScriptServiceClient, action: Proto.CodeAction -): WorkspaceEdit | undefined { +): vscode.WorkspaceEdit | undefined { return action.changes && action.changes.length ? typeConverters.WorkspaceEdit.fromFileCodeEdits(client, action.changes) : undefined; @@ -23,7 +23,7 @@ export async function applyCodeAction( ): Promise { const workspaceEdit = getEditForCodeAction(client, action); if (workspaceEdit) { - if (!(await workspace.applyEdit(workspaceEdit))) { + if (!(await vscode.workspace.applyEdit(workspaceEdit))) { return false; } } diff --git a/extensions/typescript-language-features/src/utils/configuration.ts b/extensions/typescript-language-features/src/utils/configuration.ts index d5c0d00bdf3..adeb071062e 100644 --- a/extensions/typescript-language-features/src/utils/configuration.ts +++ b/extensions/typescript-language-features/src/utils/configuration.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { workspace, WorkspaceConfiguration } from 'vscode'; +import * as vscode from 'vscode'; import * as arrays from './arrays'; export enum TsServerLogLevel { @@ -58,7 +58,7 @@ export class TypeScriptServiceConfiguration { } private constructor() { - const configuration = workspace.getConfiguration(); + const configuration = vscode.workspace.getConfiguration(); this.locale = TypeScriptServiceConfiguration.extractLocale(configuration); this.globalTsdk = TypeScriptServiceConfiguration.extractGlobalTsdk(configuration); @@ -83,7 +83,7 @@ export class TypeScriptServiceConfiguration { && arrays.equals(this.tsServerPluginPaths, other.tsServerPluginPaths); } - private static extractGlobalTsdk(configuration: WorkspaceConfiguration): string | null { + private static extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null { const inspect = configuration.inspect('typescript.tsdk'); if (inspect && inspect.globalValue && 'string' === typeof inspect.globalValue) { return inspect.globalValue; @@ -91,7 +91,7 @@ export class TypeScriptServiceConfiguration { return null; } - private static extractLocalTsdk(configuration: WorkspaceConfiguration): string | null { + private static extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null { const inspect = configuration.inspect('typescript.tsdk'); if (inspect && inspect.workspaceValue && 'string' === typeof inspect.workspaceValue) { return inspect.workspaceValue; @@ -99,32 +99,32 @@ export class TypeScriptServiceConfiguration { return null; } - private static readTsServerLogLevel(configuration: WorkspaceConfiguration): TsServerLogLevel { + private static readTsServerLogLevel(configuration: vscode.WorkspaceConfiguration): TsServerLogLevel { const setting = configuration.get('typescript.tsserver.log', 'off'); return TsServerLogLevel.fromString(setting); } - private static readTsServerPluginPaths(configuration: WorkspaceConfiguration): string[] { + private static readTsServerPluginPaths(configuration: vscode.WorkspaceConfiguration): string[] { return configuration.get('typescript.tsserver.pluginPaths', []); } - private static readCheckJs(configuration: WorkspaceConfiguration): boolean { + private static readCheckJs(configuration: vscode.WorkspaceConfiguration): boolean { return configuration.get('javascript.implicitProjectConfig.checkJs', false); } - private static readExperimentalDecorators(configuration: WorkspaceConfiguration): boolean { + private static readExperimentalDecorators(configuration: vscode.WorkspaceConfiguration): boolean { return configuration.get('javascript.implicitProjectConfig.experimentalDecorators', false); } - private static readNpmLocation(configuration: WorkspaceConfiguration): string | null { + private static readNpmLocation(configuration: vscode.WorkspaceConfiguration): string | null { return configuration.get('typescript.npm', null); } - private static readDisableAutomaticTypeAcquisition(configuration: WorkspaceConfiguration): boolean { + private static readDisableAutomaticTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean { return configuration.get('typescript.disableAutomaticTypeAcquisition', false); } - private static extractLocale(configuration: WorkspaceConfiguration): string | null { + private static extractLocale(configuration: vscode.WorkspaceConfiguration): string | null { return configuration.get('typescript.locale', null); } } diff --git a/extensions/typescript-language-features/src/utils/logger.ts b/extensions/typescript-language-features/src/utils/logger.ts index 782fe871fe3..7ba79adad12 100644 --- a/extensions/typescript-language-features/src/utils/logger.ts +++ b/extensions/typescript-language-features/src/utils/logger.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { OutputChannel, window } from 'vscode'; +import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import * as is from './is'; import { memoize } from './memoize'; @@ -13,8 +13,8 @@ const localize = nls.loadMessageBundle(); export default class Logger { @memoize - private get output(): OutputChannel { - return window.createOutputChannel(localize('channelName', 'TypeScript')); + private get output(): vscode.OutputChannel { + return vscode.window.createOutputChannel(localize('channelName', 'TypeScript')); } private data2String(data: any): string { diff --git a/extensions/typescript-language-features/src/utils/pluginPathsProvider.ts b/extensions/typescript-language-features/src/utils/pluginPathsProvider.ts index d001512234b..547660f0649 100644 --- a/extensions/typescript-language-features/src/utils/pluginPathsProvider.ts +++ b/extensions/typescript-language-features/src/utils/pluginPathsProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as path from 'path'; -import { workspace } from 'vscode'; +import * as vscode from 'vscode'; import { TypeScriptServiceConfiguration } from './configuration'; import { RelativeWorkspacePathResolver } from './relativePathResolver'; @@ -37,7 +37,7 @@ export class TypeScriptPluginPathsProvider { return [workspacePath]; } - return (workspace.workspaceFolders || []) + return (vscode.workspace.workspaceFolders || []) .map(workspaceFolder => path.join(workspaceFolder.uri.fsPath, pluginPath)); } } \ No newline at end of file diff --git a/extensions/typescript-language-features/src/utils/plugins.ts b/extensions/typescript-language-features/src/utils/plugins.ts index 13966dd0b06..e67df651b40 100644 --- a/extensions/typescript-language-features/src/utils/plugins.ts +++ b/extensions/typescript-language-features/src/utils/plugins.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { extensions } from 'vscode'; +import * as vscode from 'vscode'; export interface TypeScriptServerPlugin { readonly path: string; @@ -13,7 +13,7 @@ export interface TypeScriptServerPlugin { export function getContributedTypeScriptServerPlugins(): TypeScriptServerPlugin[] { const plugins: TypeScriptServerPlugin[] = []; - for (const extension of extensions.all) { + for (const extension of vscode.extensions.all) { const pack = extension.packageJSON; if (pack.contributes && pack.contributes.typescriptServerPlugins && Array.isArray(pack.contributes.typescriptServerPlugins)) { for (const plugin of pack.contributes.typescriptServerPlugins) { diff --git a/extensions/typescript-language-features/src/utils/previewer.ts b/extensions/typescript-language-features/src/utils/previewer.ts index df0105ac287..aa698b2c163 100644 --- a/extensions/typescript-language-features/src/utils/previewer.ts +++ b/extensions/typescript-language-features/src/utils/previewer.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MarkdownString } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; function getTagBodyText(tag: Proto.JSDocTagInfo): string | undefined { @@ -64,17 +64,17 @@ export function tagsMarkdownPreview(tags: Proto.JSDocTagInfo[]): string { export function markdownDocumentation( documentation: Proto.SymbolDisplayPart[], tags: Proto.JSDocTagInfo[] -): MarkdownString { - const out = new MarkdownString(); +): vscode.MarkdownString { + const out = new vscode.MarkdownString(); addMarkdownDocumentation(out, documentation, tags); return out; } export function addMarkdownDocumentation( - out: MarkdownString, + out: vscode.MarkdownString, documentation: Proto.SymbolDisplayPart[] | undefined, tags: Proto.JSDocTagInfo[] | undefined -): MarkdownString { +): vscode.MarkdownString { if (documentation) { out.appendMarkdown(plain(documentation)); } diff --git a/extensions/typescript-language-features/src/utils/relativePathResolver.ts b/extensions/typescript-language-features/src/utils/relativePathResolver.ts index e424fca126a..85b72a55d6b 100644 --- a/extensions/typescript-language-features/src/utils/relativePathResolver.ts +++ b/extensions/typescript-language-features/src/utils/relativePathResolver.ts @@ -3,11 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as path from 'path'; -import { workspace } from 'vscode'; +import * as vscode from 'vscode'; export class RelativeWorkspacePathResolver { public asAbsoluteWorkspacePath(relativePath: string): string | undefined { - for (const root of workspace.workspaceFolders || []) { + for (const root of vscode.workspace.workspaceFolders || []) { const rootPrefixes = [`./${root.name}/`, `${root.name}/`, `.\\${root.name}\\`, `${root.name}\\`]; for (const rootPrefix of rootPrefixes) { if (relativePath.startsWith(rootPrefix)) { diff --git a/extensions/typescript-language-features/src/utils/resourceMap.ts b/extensions/typescript-language-features/src/utils/resourceMap.ts index f59ab661f5a..73364c03207 100644 --- a/extensions/typescript-language-features/src/utils/resourceMap.ts +++ b/extensions/typescript-language-features/src/utils/resourceMap.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; -import { Uri } from 'vscode'; +import * as vscode from 'vscode'; import { memoize } from './memoize'; import { getTempFile } from './temp'; @@ -18,27 +18,27 @@ export class ResourceMap { private readonly _map = new Map(); constructor( - private readonly _normalizePath?: (resource: Uri) => string | null + private readonly _normalizePath?: (resource: vscode.Uri) => string | null ) { } - public has(resource: Uri): boolean { + public has(resource: vscode.Uri): boolean { const file = this.toKey(resource); return !!file && this._map.has(file); } - public get(resource: Uri): T | undefined { + public get(resource: vscode.Uri): T | undefined { const file = this.toKey(resource); return file ? this._map.get(file) : undefined; } - public set(resource: Uri, value: T) { + public set(resource: vscode.Uri, value: T) { const file = this.toKey(resource); if (file) { this._map.set(file, value); } } - public delete(resource: Uri): void { + public delete(resource: vscode.Uri): void { const file = this.toKey(resource); if (file) { this._map.delete(file); @@ -57,7 +57,7 @@ export class ResourceMap { return this._map.entries(); } - private toKey(resource: Uri): string | null { + private toKey(resource: vscode.Uri): string | null { const key = this._normalizePath ? this._normalizePath(resource) : resource.fsPath; if (!key) { return key; diff --git a/extensions/typescript-language-features/src/utils/tracer.ts b/extensions/typescript-language-features/src/utils/tracer.ts index 2c12e2bf15a..2f2394dcaa1 100644 --- a/extensions/typescript-language-features/src/utils/tracer.ts +++ b/extensions/typescript-language-features/src/utils/tracer.ts @@ -3,12 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { workspace } from 'vscode'; +import * as vscode from 'vscode'; import * as Proto from '../protocol'; import Logger from './logger'; - - enum Trace { Off, Messages, @@ -45,7 +43,7 @@ export default class Tracer { } private static readTrace(): Trace { - let result: Trace = Trace.fromString(workspace.getConfiguration().get('typescript.tsserver.trace', 'off')); + let result: Trace = Trace.fromString(vscode.workspace.getConfiguration().get('typescript.tsserver.trace', 'off')); if (result === Trace.Off && !!process.env.TSS_TRACE) { result = Trace.Messages; } diff --git a/extensions/typescript-language-features/src/utils/typingsStatus.ts b/extensions/typescript-language-features/src/utils/typingsStatus.ts index 0113435deda..78f303f0f39 100644 --- a/extensions/typescript-language-features/src/utils/typingsStatus.ts +++ b/extensions/typescript-language-features/src/utils/typingsStatus.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Disposable, MessageItem, ProgressLocation, window, workspace } from 'vscode'; +import * as vscode from 'vscode'; import { loadMessageBundle } from 'vscode-nls'; import { ITypeScriptServiceClient } from '../typescriptService'; @@ -11,10 +11,10 @@ const localize = loadMessageBundle(); const typingsInstallTimeout = 30 * 1000; -export default class TypingsStatus extends Disposable { +export default class TypingsStatus extends vscode.Disposable { private _acquiringTypings: { [eventId: string]: NodeJS.Timer } = Object.create({}); private _client: ITypeScriptServiceClient; - private _subscriptions: Disposable[] = []; + private _subscriptions: vscode.Disposable[] = []; constructor(client: ITypeScriptServiceClient) { super(() => this.dispose()); @@ -60,10 +60,10 @@ export default class TypingsStatus extends Disposable { export class AtaProgressReporter { private _promises = new Map(); - private _disposable: Disposable; + private _disposable: vscode.Disposable; constructor(client: ITypeScriptServiceClient) { - this._disposable = Disposable.from( + this._disposable = vscode.Disposable.from( client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)), client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)), client.onTypesInstallerInitializationFailed(_ => this.onTypesInstallerInitializationFailed())); @@ -83,8 +83,8 @@ export class AtaProgressReporter { }); }); - window.withProgress({ - location: ProgressLocation.Window, + vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, title: localize('installingPackages', "Fetching data for better TypeScript IntelliSense") }, () => promise); } @@ -98,12 +98,12 @@ export class AtaProgressReporter { } private onTypesInstallerInitializationFailed() { - interface MyMessageItem extends MessageItem { + interface MyMessageItem extends vscode.MessageItem { id: number; } - if (workspace.getConfiguration('typescript').get('check.npmIsInstalled', true)) { - window.showWarningMessage( + if (vscode.workspace.getConfiguration('typescript').get('check.npmIsInstalled', true)) { + vscode.window.showWarningMessage( localize( 'typesInstallerInitializationFailed.title', "Could not install typings files for JavaScript language features. Please ensure that NPM is installed or configure 'typescript.npm' in your user settings. Click [here]({0}) to learn more.", @@ -118,7 +118,7 @@ export class AtaProgressReporter { } switch (selected.id) { case 1: - const tsConfig = workspace.getConfiguration('typescript'); + const tsConfig = vscode.workspace.getConfiguration('typescript'); tsConfig.update('check.npmIsInstalled', false, true); break; } diff --git a/extensions/typescript-language-features/src/utils/versionPicker.ts b/extensions/typescript-language-features/src/utils/versionPicker.ts index 0702a60e533..bf81cb5c466 100644 --- a/extensions/typescript-language-features/src/utils/versionPicker.ts +++ b/extensions/typescript-language-features/src/utils/versionPicker.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { commands, Memento, QuickPickItem, Uri, window, workspace } from 'vscode'; +import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import { TypeScriptVersion, TypeScriptVersionProvider } from './versionProvider'; @@ -11,7 +11,7 @@ const localize = nls.loadMessageBundle(); const useWorkspaceTsdkStorageKey = 'typescript.useWorkspaceTsdk'; -interface MyQuickPickItem extends QuickPickItem { +interface MyQuickPickItem extends vscode.QuickPickItem { id: MessageAction; version?: TypeScriptVersion; } @@ -27,7 +27,7 @@ export class TypeScriptVersionPicker { public constructor( private readonly versionProvider: TypeScriptVersionProvider, - private readonly workspaceState: Memento + private readonly workspaceState: vscode.Memento ) { this._currentVersion = this.versionProvider.defaultVersion; @@ -82,7 +82,7 @@ export class TypeScriptVersionPicker { id: MessageAction.learnMore }); - const selected = await window.showQuickPick(pickOptions, { + const selected = await vscode.window.showQuickPick(pickOptions, { placeHolder: localize( 'selectTsVersion', 'Select the TypeScript version used for JavaScript and TypeScript language features'), @@ -97,7 +97,7 @@ export class TypeScriptVersionPicker { case MessageAction.useLocal: await this.workspaceState.update(useWorkspaceTsdkStorageKey, true); if (selected.version) { - const tsConfig = workspace.getConfiguration('typescript'); + const tsConfig = vscode.workspace.getConfiguration('typescript'); await tsConfig.update('tsdk', selected.version.pathLabel, false); const previousVersion = this.currentVersion; @@ -114,7 +114,7 @@ export class TypeScriptVersionPicker { case MessageAction.learnMore: - commands.executeCommand('vscode.open', Uri.parse('https://go.microsoft.com/fwlink/?linkid=839919')); + vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=839919')); return { oldVersion: this.currentVersion }; default: diff --git a/extensions/typescript-language-features/src/utils/versionProvider.ts b/extensions/typescript-language-features/src/utils/versionProvider.ts index 27b2d9fdebe..3061f1576b9 100644 --- a/extensions/typescript-language-features/src/utils/versionProvider.ts +++ b/extensions/typescript-language-features/src/utils/versionProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; import * as path from 'path'; -import { window, workspace } from 'vscode'; +import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import API from './api'; import { TypeScriptServiceConfiguration } from './configuration'; @@ -12,9 +12,6 @@ import { RelativeWorkspacePathResolver } from './relativePathResolver'; const localize = nls.loadMessageBundle(); - - - export class TypeScriptVersion { constructor( public readonly path: string, @@ -40,7 +37,7 @@ export class TypeScriptVersion { } // Allow TS developers to provide custom version - const tsdkVersion = workspace.getConfiguration().get('typescript.tsdk_version', undefined); + const tsdkVersion = vscode.workspace.getConfiguration().get('typescript.tsdk_version', undefined); if (tsdkVersion) { return API.fromVersionString(tsdkVersion); } @@ -152,7 +149,7 @@ export class TypeScriptVersionProvider { } catch (e) { // noop } - window.showErrorMessage(localize( + vscode.window.showErrorMessage(localize( 'noBundledServerFound', 'VS Code\'s tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code.')); throw new Error('Could not find bundled tsserver.js'); @@ -182,14 +179,14 @@ export class TypeScriptVersionProvider { } private loadTypeScriptVersionsFromPath(relativePath: string): TypeScriptVersion[] { - if (!workspace.workspaceFolders) { + if (!vscode.workspace.workspaceFolders) { return []; } const versions: TypeScriptVersion[] = []; - for (const root of workspace.workspaceFolders) { + for (const root of vscode.workspace.workspaceFolders) { let label: string = relativePath; - if (workspace.workspaceFolders && workspace.workspaceFolders.length > 1) { + if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) { label = path.join(root.name, relativePath); }