From bf4eb8832bac78262027169c8b202e9cdf17a3a6 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 4 Apr 2018 12:21:34 -0700 Subject: [PATCH 1/2] Restrict language services to file schemes --- src/client/activation/classic.ts | 20 +++++++++----------- src/client/extension.ts | 11 ++++++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/client/activation/classic.ts b/src/client/activation/classic.ts index 61b82fae79f9..0574765f6336 100644 --- a/src/client/activation/classic.ts +++ b/src/client/activation/classic.ts @@ -20,10 +20,8 @@ import { TEST_OUTPUT_CHANNEL } from '../unittests/common/constants'; import * as tests from '../unittests/main'; import { IExtensionActivator } from './types'; -const PYTHON: DocumentFilter = { language: 'python' }; - export class ClassicExtensionActivator implements IExtensionActivator { - constructor(private serviceManager: IServiceManager, private pythonSettings: IPythonSettings) { + constructor(private serviceManager: IServiceManager, private pythonSettings: IPythonSettings, private documentSelector: DocumentFilter[]) { } public async activate(context: ExtensionContext): Promise { @@ -35,20 +33,20 @@ export class ClassicExtensionActivator implements IExtensionActivator { context.subscriptions.push(...activateGoToObjectDefinitionProvider(jediFactory)); context.subscriptions.push(jediFactory); - context.subscriptions.push(languages.registerRenameProvider(PYTHON, new PythonRenameProvider(this.serviceManager))); + context.subscriptions.push(languages.registerRenameProvider(this.documentSelector, new PythonRenameProvider(this.serviceManager))); const definitionProvider = new PythonDefinitionProvider(jediFactory); - context.subscriptions.push(languages.registerDefinitionProvider(PYTHON, definitionProvider)); - context.subscriptions.push(languages.registerHoverProvider(PYTHON, new PythonHoverProvider(jediFactory))); - context.subscriptions.push(languages.registerReferenceProvider(PYTHON, new PythonReferenceProvider(jediFactory))); - context.subscriptions.push(languages.registerCompletionItemProvider(PYTHON, new PythonCompletionItemProvider(jediFactory, this.serviceManager), '.')); - context.subscriptions.push(languages.registerCodeLensProvider(PYTHON, this.serviceManager.get(IShebangCodeLensProvider))); + context.subscriptions.push(languages.registerDefinitionProvider(this.documentSelector, definitionProvider)); + context.subscriptions.push(languages.registerHoverProvider(this.documentSelector, new PythonHoverProvider(jediFactory))); + context.subscriptions.push(languages.registerReferenceProvider(this.documentSelector, new PythonReferenceProvider(jediFactory))); + context.subscriptions.push(languages.registerCompletionItemProvider(this.documentSelector, new PythonCompletionItemProvider(jediFactory, this.serviceManager), '.')); + context.subscriptions.push(languages.registerCodeLensProvider(this.documentSelector, this.serviceManager.get(IShebangCodeLensProvider))); const symbolProvider = new PythonSymbolProvider(jediFactory); - context.subscriptions.push(languages.registerDocumentSymbolProvider(PYTHON, symbolProvider)); + context.subscriptions.push(languages.registerDocumentSymbolProvider(this.documentSelector, symbolProvider)); if (this.pythonSettings.devOptions.indexOf('DISABLE_SIGNATURE') === -1) { - context.subscriptions.push(languages.registerSignatureHelpProvider(PYTHON, new PythonSignatureProvider(jediFactory), '(', ',')); + context.subscriptions.push(languages.registerSignatureHelpProvider(this.documentSelector, new PythonSignatureProvider(jediFactory), '(', ',')); } const unitTestOutChannel = this.serviceManager.get(IOutputChannel, TEST_OUTPUT_CHANNEL); diff --git a/src/client/extension.ts b/src/client/extension.ts index e86959d62255..8a8dfb556588 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -58,7 +58,12 @@ import { WorkspaceSymbols } from './workspaceSymbols/main'; const activationDeferred = createDeferred(); export const activated = activationDeferred.promise; -const PYTHON: DocumentFilter = { language: 'python' }; + +const PYTHON_LANGUAGE = 'python'; +const PYTHON: DocumentFilter = [ + { scheme: 'file', language: PYTHON_LANGUAGE }, + { scheme: 'untitled', language: PYTHON_LANGUAGE } +]; // tslint:disable-next-line:max-func-body-length export async function activate(context: ExtensionContext) { @@ -77,7 +82,7 @@ export async function activate(context: ExtensionContext) { const activator: IExtensionActivator = IS_ANALYSIS_ENGINE_TEST || !pythonSettings.jediEnabled ? new AnalysisExtensionActivator(serviceManager, pythonSettings) - : new ClassicExtensionActivator(serviceManager, pythonSettings); + : new ClassicExtensionActivator(serviceManager, pythonSettings, PYTHON); await activator.activate(context); @@ -105,7 +110,7 @@ export async function activate(context: ExtensionContext) { // Enable indentAction // tslint:disable-next-line:no-non-null-assertion - languages.setLanguageConfiguration(PYTHON.language!, { + languages.setLanguageConfiguration(PYTHON_LANGUAGE, { onEnterRules: [ { beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async)\b.*/, From 50e3552d97d74237610031b99dc5f8a6524ae3c8 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 4 Apr 2018 12:24:44 -0700 Subject: [PATCH 2/2] Fixing type declaration --- src/client/extension.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 8a8dfb556588..07b051bf808b 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -60,7 +60,7 @@ const activationDeferred = createDeferred(); export const activated = activationDeferred.promise; const PYTHON_LANGUAGE = 'python'; -const PYTHON: DocumentFilter = [ +const PYTHON: DocumentFilter[] = [ { scheme: 'file', language: PYTHON_LANGUAGE }, { scheme: 'untitled', language: PYTHON_LANGUAGE } ]; @@ -110,7 +110,7 @@ export async function activate(context: ExtensionContext) { // Enable indentAction // tslint:disable-next-line:no-non-null-assertion - languages.setLanguageConfiguration(PYTHON_LANGUAGE, { + languages.setLanguageConfiguration(PYTHON_LANGUAGE!, { onEnterRules: [ { beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async)\b.*/,