提交 408b6d5f 编写于 作者: M Matt Bierner

Move file schemes to own file

上级 20fc7885
......@@ -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
......@@ -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;
......
/*---------------------------------------------------------------------------------------------
* 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册