Skip to content

Commit

Permalink
Restrict language services to file/untitled schemes (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent authored and brettcannon committed Apr 9, 2018
1 parent 67f42f0 commit 63b7410
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 9 additions & 11 deletions src/client/activation/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand All @@ -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>(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>(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<OutputChannel>(IOutputChannel, TEST_OUTPUT_CHANNEL);
Expand Down
11 changes: 8 additions & 3 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ import { WorkspaceSymbols } from './workspaceSymbols/main';

const activationDeferred = createDeferred<void>();
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) {
Expand All @@ -76,7 +81,7 @@ export async function activate(context: ExtensionContext) {

const activator: IExtensionActivator = isPythonAnalysisEngineTest() || !pythonSettings.jediEnabled
? new AnalysisExtensionActivator(serviceManager, pythonSettings)
: new ClassicExtensionActivator(serviceManager, pythonSettings);
: new ClassicExtensionActivator(serviceManager, pythonSettings, PYTHON);

await activator.activate(context);

Expand Down Expand Up @@ -104,7 +109,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)\b.*:\s*\S+/,
Expand Down

0 comments on commit 63b7410

Please sign in to comment.