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..07b051bf808b 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.*/,