diff --git a/extensions/typescript/src/extension.ts b/extensions/typescript/src/extension.ts index 2c015f82f2f39d29dd8b6fcd0a715361b3ec1b15..364e154bb1536557f8e5704d878e7b6e8dd9709f 100644 --- a/extensions/typescript/src/extension.ts +++ b/extensions/typescript/src/extension.ts @@ -16,7 +16,7 @@ import * as languageConfigurations from './utils/languageConfigurations'; import { standardLanguageDescriptions } from './utils/languageDescription'; import ManagedFileContextManager from './utils/managedFileContext'; import { lazy, Lazy } from './utils/lazy'; -import TypeScriptServiceClient from './typescriptServiceClient'; +import * as fileSchemes from './utils/fileSchemes'; export function activate( context: vscode.ExtensionContext @@ -94,10 +94,5 @@ function isSupportedDocument( if (supportedLanguage.indexOf(document.languageId) < 0) { return false; } - const scheme = document.uri.scheme; - return ( - scheme === TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME - || scheme === 'untitled' - || scheme === 'file' - ); + return fileSchemes.isSupportedScheme(document.uri.scheme); } \ No newline at end of file diff --git a/extensions/typescript/src/typescriptServiceClient.ts b/extensions/typescript/src/typescriptServiceClient.ts index 8d584a0e3aec5096757fc6cd525a684d0d73448d..89964180240cf987b3442cf6c87509bfea013c2a 100644 --- a/extensions/typescript/src/typescriptServiceClient.ts +++ b/extensions/typescript/src/typescriptServiceClient.ts @@ -26,6 +26,8 @@ import * as nls from 'vscode-nls'; import { TypeScriptServiceConfiguration, TsServerLogLevel } from './utils/configuration'; import { TypeScriptVersionProvider, TypeScriptVersion } from './utils/versionProvider'; import { TypeScriptVersionPicker } from './utils/versionPicker'; +import * as fileSchemes from './utils/fileSchemes'; + const localize = nls.loadMessageBundle(); interface CallbackItem { @@ -107,8 +109,7 @@ class RequestQueue { } export default class TypeScriptServiceClient implements ITypeScriptServiceClient { - public static readonly WALK_THROUGH_SNIPPET_SCHEME = 'walkThroughSnippet'; - private static readonly WALK_THROUGH_SNIPPET_SCHEME_COLON = `${TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME}:`; + private static readonly WALK_THROUGH_SNIPPET_SCHEME_COLON = `${fileSchemes.walkThroughSnippet}:`; private pathSeparator: string; @@ -555,15 +556,15 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } public normalizePath(resource: Uri): string | null { - if (resource.scheme === TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME) { + if (resource.scheme === fileSchemes.walkThroughSnippet) { return resource.toString(); } - if (resource.scheme === 'untitled' && this._apiVersion.has213Features()) { + if (resource.scheme === fileSchemes.untitled && this._apiVersion.has213Features()) { return resource.toString(); } - if (resource.scheme !== 'file') { + if (resource.scheme !== fileSchemes.file) { return null; } const result = resource.fsPath; @@ -576,7 +577,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient public asUrl(filepath: string): Uri { if (filepath.startsWith(TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME_COLON) - || (filepath.startsWith('untitled:') && this._apiVersion.has213Features()) + || (filepath.startsWith(fileSchemes.untitled + ':') && this._apiVersion.has213Features()) ) { return Uri.parse(filepath); } @@ -589,7 +590,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient return undefined; } - if (resource.scheme === 'file' || resource.scheme === 'untitled') { + if (resource.scheme === fileSchemes.file || resource.scheme === fileSchemes.untitled) { for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) { if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) { return root.uri.fsPath; diff --git a/extensions/typescript/src/utils/fileSchemes.ts b/extensions/typescript/src/utils/fileSchemes.ts new file mode 100644 index 0000000000000000000000000000000000000000..285ea43f33177d8c5ceb2821fb42d860256b48a2 --- /dev/null +++ b/extensions/typescript/src/utils/fileSchemes.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export const file = 'file'; + +export const untitled = 'untitled'; + +export const walkThroughSnippet = 'walkThroughSnippet'; + +export const supportedSchemes = [ + file, + untitled, + walkThroughSnippet +]; + +export function isSupportedScheme(scheme: string): boolean { + return supportedSchemes.indexOf(scheme) >= 0; +} \ No newline at end of file