Skip to content

Commit a903c11

Browse files
committed
Restrict creation of TS client to known schemes
1 parent 17ab24f commit a903c11

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

extensions/typescript/src/extension.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as languageConfigurations from './utils/languageConfigurations';
1616
import { standardLanguageDescriptions } from './utils/languageDescription';
1717
import ManagedFileContextManager from './utils/managedFileContext';
1818
import { lazy, Lazy } from './utils/lazy';
19+
import TypeScriptServiceClient from './typescriptServiceClient';
1920

2021
export function activate(
2122
context: vscode.ExtensionContext
@@ -27,26 +28,21 @@ export function activate(
2728

2829
const lazyClientHost = createLazyClientHost(context, plugins, commandManager);
2930

30-
context.subscriptions.push(new ManagedFileContextManager(resource => {
31-
// Don't force evaluation here.
32-
if (lazyClientHost.hasValue) {
33-
return lazyClientHost.value.serviceClient.normalizePath(resource);
34-
}
35-
return null;
36-
}));
37-
3831
registerCommands(commandManager, lazyClientHost);
3932
context.subscriptions.push(new TypeScriptTaskProviderManager(lazyClientHost.map(x => x.serviceClient)));
4033
context.subscriptions.push(vscode.languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
4134

42-
4335
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
4436
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
45-
if (supportedLanguage.indexOf(textDocument.languageId) >= 0) {
37+
if (isSupportedDocument(supportedLanguage, textDocument)) {
4638
openListener.dispose();
4739
// Force activation
4840
// tslint:disable-next-line:no-unused-expression
4941
void lazyClientHost.value;
42+
43+
context.subscriptions.push(new ManagedFileContextManager(resource => {
44+
return lazyClientHost.value.serviceClient.normalizePath(resource);
45+
}));
5046
return true;
5147
}
5248
return false;
@@ -89,3 +85,19 @@ function registerCommands(
8985
commandManager.register(new commands.TypeScriptGoToProjectConfigCommand(lazyClientHost));
9086
commandManager.register(new commands.JavaScriptGoToProjectConfigCommand(lazyClientHost));
9187
}
88+
89+
90+
function isSupportedDocument(
91+
supportedLanguage: string[],
92+
document: vscode.TextDocument
93+
): boolean {
94+
if (supportedLanguage.indexOf(document.languageId) < 0) {
95+
return false;
96+
}
97+
const scheme = document.uri.scheme;
98+
return (
99+
scheme === TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME
100+
|| scheme === 'untitled'
101+
|| scheme === 'file'
102+
);
103+
}

extensions/typescript/src/typescriptServiceClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class RequestQueue {
107107
}
108108

109109
export default class TypeScriptServiceClient implements ITypeScriptServiceClient {
110-
private static readonly WALK_THROUGH_SNIPPET_SCHEME = 'walkThroughSnippet';
110+
public static readonly WALK_THROUGH_SNIPPET_SCHEME = 'walkThroughSnippet';
111111
private static readonly WALK_THROUGH_SNIPPET_SCHEME_COLON = `${TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME}:`;
112112

113113
private pathSeparator: string;

0 commit comments

Comments
 (0)