Restrict creation of TS client to known schemes

This commit is contained in:
Matt Bierner
2017-12-01 15:46:26 -08:00
parent 17ab24fcf0
commit a903c11790
2 changed files with 23 additions and 11 deletions

View File

@@ -16,6 +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';
export function activate(
context: vscode.ExtensionContext
@@ -27,26 +28,21 @@ export function activate(
const lazyClientHost = createLazyClientHost(context, plugins, commandManager);
context.subscriptions.push(new ManagedFileContextManager(resource => {
// Don't force evaluation here.
if (lazyClientHost.hasValue) {
return lazyClientHost.value.serviceClient.normalizePath(resource);
}
return null;
}));
registerCommands(commandManager, lazyClientHost);
context.subscriptions.push(new TypeScriptTaskProviderManager(lazyClientHost.map(x => x.serviceClient)));
context.subscriptions.push(vscode.languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
if (supportedLanguage.indexOf(textDocument.languageId) >= 0) {
if (isSupportedDocument(supportedLanguage, textDocument)) {
openListener.dispose();
// Force activation
// tslint:disable-next-line:no-unused-expression
void lazyClientHost.value;
context.subscriptions.push(new ManagedFileContextManager(resource => {
return lazyClientHost.value.serviceClient.normalizePath(resource);
}));
return true;
}
return false;
@@ -89,3 +85,19 @@ function registerCommands(
commandManager.register(new commands.TypeScriptGoToProjectConfigCommand(lazyClientHost));
commandManager.register(new commands.JavaScriptGoToProjectConfigCommand(lazyClientHost));
}
function isSupportedDocument(
supportedLanguage: string[],
document: vscode.TextDocument
): boolean {
if (supportedLanguage.indexOf(document.languageId) < 0) {
return false;
}
const scheme = document.uri.scheme;
return (
scheme === TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME
|| scheme === 'untitled'
|| scheme === 'file'
);
}

View File

@@ -107,7 +107,7 @@ class RequestQueue {
}
export default class TypeScriptServiceClient implements ITypeScriptServiceClient {
private static readonly WALK_THROUGH_SNIPPET_SCHEME = 'walkThroughSnippet';
public static readonly WALK_THROUGH_SNIPPET_SCHEME = 'walkThroughSnippet';
private static readonly WALK_THROUGH_SNIPPET_SCHEME_COLON = `${TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME}:`;
private pathSeparator: string;