Skip to content

Enable on-type formatting from language server #2737

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

Merged
merged 2 commits into from
Oct 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
1 change: 1 addition & 0 deletions news/1 Enhancements/2690.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable on-type formatting from language server
12 changes: 12 additions & 0 deletions src/client/activation/jedi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { PythonReferenceProvider } from '../providers/referenceProvider';
import { PythonRenameProvider } from '../providers/renameProvider';
import { PythonSignatureProvider } from '../providers/signatureProvider';
import { JediSymbolProvider } from '../providers/symbolProvider';
import { BlockFormatProviders } from '../typeFormatters/blockFormatProvider';
import { OnTypeFormattingDispatcher } from '../typeFormatters/dispatcher';
import { OnEnterFormatter } from '../typeFormatters/onEnterFormatter';
import { IUnitTestManagementService } from '../unittests/types';
import { WorkspaceSymbols } from '../workspaceSymbols/main';
import { IExtensionActivator } from './types';
Expand Down Expand Up @@ -47,6 +50,15 @@ export class JediExtensionActivator implements IExtensionActivator {
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 onTypeDispatcher = new OnTypeFormattingDispatcher({
'\n': new OnEnterFormatter(),
':': new BlockFormatProviders()
});
const onTypeTriggers = onTypeDispatcher.getTriggerCharacters();
if (onTypeTriggers) {
context.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, onTypeDispatcher, onTypeTriggers.first, ...onTypeTriggers.more));
}

const serviceContainer = this.serviceManager.get<IServiceContainer>(IServiceContainer);
context.subscriptions.push(new WorkspaceSymbols(serviceContainer));

Expand Down
12 changes: 0 additions & 12 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ import { sendTelemetryEvent } from './telemetry';
import { EDITOR_LOAD } from './telemetry/constants';
import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry';
import { ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types';
import { BlockFormatProviders } from './typeFormatters/blockFormatProvider';
import { OnTypeFormattingDispatcher } from './typeFormatters/dispatcher';
import { OnEnterFormatter } from './typeFormatters/onEnterFormatter';
import { TEST_OUTPUT_CHANNEL } from './unittests/common/constants';
import { registerTypes as unitTestsRegisterTypes } from './unittests/serviceRegistry';

Expand Down Expand Up @@ -137,15 +134,6 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
context.subscriptions.push(languages.registerDocumentRangeFormattingEditProvider(PYTHON, formatProvider));
}

const onTypeDispatcher = new OnTypeFormattingDispatcher({
'\n': new OnEnterFormatter(),
':': new BlockFormatProviders()
});
const onTypeTriggers = onTypeDispatcher.getTriggerCharacters();
if (onTypeTriggers) {
context.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, onTypeDispatcher, onTypeTriggers.first, ...onTypeTriggers.more));
}

const deprecationMgr = serviceContainer.get<IFeatureDeprecationManager>(IFeatureDeprecationManager);
deprecationMgr.initialize();
context.subscriptions.push(deprecationMgr);
Expand Down