Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discussion] [VS Live Share] Restrict language services to file/untitled schemes #1298

Merged
merged 2 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -58,7 +58,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 @@ -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);

Expand Down Expand Up @@ -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.*/,
Expand Down