From ecbdbffde220115689c6cae7fde9c3111ac52c84 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 31 Jan 2022 10:01:17 +0100 Subject: [PATCH] replace formatting registries for service properties --- .../editor/browser/widget/codeEditorWidget.ts | 12 +++--- src/vs/editor/common/languages.ts | 15 -------- .../common/services/languageFeatures.ts | 8 +++- .../services/languageFeaturesService.ts | 8 +++- .../editor/contrib/format/browser/format.ts | 38 +++++++++++++------ .../contrib/format/browser/formatActions.ts | 13 ++++--- .../standalone/browser/standaloneLanguages.ts | 9 +++-- .../api/browser/mainThreadLanguageFeatures.ts | 6 +-- .../browser/extHostLanguageFeatures.test.ts | 14 +++---- .../format/browser/formatActionsMultiple.ts | 9 +++-- .../format/browser/formatActionsNone.ts | 5 ++- .../browser/contrib/format/formatting.ts | 6 ++- 12 files changed, 84 insertions(+), 59 deletions(-) diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 7f4a6203a50..500c33c62d4 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1957,8 +1957,8 @@ export class EditorModeContext extends Disposable { this._register(_languageFeaturesService.documentSymbolProvider.onDidChange(update)); this._register(_languageFeaturesService.referenceProvider.onDidChange(update)); this._register(_languageFeaturesService.renameProvider.onDidChange(update)); - this._register(modes.DocumentFormattingEditProviderRegistry.onDidChange(update)); - this._register(modes.DocumentRangeFormattingEditProviderRegistry.onDidChange(update)); + this._register(_languageFeaturesService.documentFormattingEditProvider.onDidChange(update)); + this._register(_languageFeaturesService.documentRangeFormattingEditProvider.onDidChange(update)); this._register(modes.SignatureHelpProviderRegistry.onDidChange(update)); this._register(_languageFeaturesService.inlayHintsProvider.onDidChange(update)); @@ -2013,10 +2013,10 @@ export class EditorModeContext extends Disposable { this._hasRenameProvider.set(this._languageFeaturesService.renameProvider.has(model)); this._hasSignatureHelpProvider.set(modes.SignatureHelpProviderRegistry.has(model)); this._hasInlayHintsProvider.set(this._languageFeaturesService.inlayHintsProvider.has(model)); - this._hasDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.has(model) || modes.DocumentRangeFormattingEditProviderRegistry.has(model)); - this._hasDocumentSelectionFormattingProvider.set(modes.DocumentRangeFormattingEditProviderRegistry.has(model)); - this._hasMultipleDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.all(model).length + modes.DocumentRangeFormattingEditProviderRegistry.all(model).length > 1); - this._hasMultipleDocumentSelectionFormattingProvider.set(modes.DocumentRangeFormattingEditProviderRegistry.all(model).length > 1); + this._hasDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.has(model) || this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); + this._hasDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.has(model)); + this._hasMultipleDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.all(model).length + this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); + this._hasMultipleDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1); this._isInWalkThrough.set(model.uri.scheme === Schemas.walkThroughSnippet); }); } diff --git a/src/vs/editor/common/languages.ts b/src/vs/editor/common/languages.ts index 7dce7eac151..b699279bb9c 100644 --- a/src/vs/editor/common/languages.ts +++ b/src/vs/editor/common/languages.ts @@ -1952,21 +1952,6 @@ export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry(); -/** - * @internal - */ -export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry(); - -/** - * @internal - */ -export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry(); - -/** - * @internal - */ -export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry(); - /** * @internal */ diff --git a/src/vs/editor/common/services/languageFeatures.ts b/src/vs/editor/common/services/languageFeatures.ts index 85e0e434ae2..1911a3b8095 100644 --- a/src/vs/editor/common/services/languageFeatures.ts +++ b/src/vs/editor/common/services/languageFeatures.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry'; -import { CodeLensProvider, DocumentSymbolProvider, InlayHintsProvider, ReferenceProvider, RenameProvider } from 'vs/editor/common/languages'; +import { CodeLensProvider, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, DocumentSymbolProvider, InlayHintsProvider, OnTypeFormattingEditProvider, ReferenceProvider, RenameProvider } from 'vs/editor/common/languages'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; export const ILanguageFeaturesService = createDecorator('ILanguageFeaturesService'); @@ -22,4 +22,10 @@ export interface ILanguageFeaturesService { readonly inlayHintsProvider: LanguageFeatureRegistry; readonly codeLensProvider: LanguageFeatureRegistry; + + readonly documentFormattingEditProvider: LanguageFeatureRegistry; + + readonly documentRangeFormattingEditProvider: LanguageFeatureRegistry; + + readonly onTypeFormattingEditProvider: LanguageFeatureRegistry; } diff --git a/src/vs/editor/common/services/languageFeaturesService.ts b/src/vs/editor/common/services/languageFeaturesService.ts index 7e970b156c1..be988684805 100644 --- a/src/vs/editor/common/services/languageFeaturesService.ts +++ b/src/vs/editor/common/services/languageFeaturesService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry'; -import { CodeLensProvider, DocumentSymbolProvider, InlayHintsProvider, ReferenceProvider, RenameProvider } from 'vs/editor/common/languages'; +import { CodeLensProvider, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, DocumentSymbolProvider, InlayHintsProvider, OnTypeFormattingEditProvider, ReferenceProvider, RenameProvider } from 'vs/editor/common/languages'; import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; @@ -21,6 +21,12 @@ export class LanguageFeatureService implements ILanguageFeaturesService { readonly inlayHintsProvider = new LanguageFeatureRegistry(); readonly codeLensProvider = new LanguageFeatureRegistry(); + + readonly documentFormattingEditProvider = new LanguageFeatureRegistry(); + + readonly documentRangeFormattingEditProvider = new LanguageFeatureRegistry(); + + readonly onTypeFormattingEditProvider = new LanguageFeatureRegistry(); } registerSingleton(ILanguageFeaturesService, LanguageFeatureService, true); diff --git a/src/vs/editor/contrib/format/browser/format.ts b/src/vs/editor/contrib/format/browser/format.ts index 19b939fd950..1618d7af989 100644 --- a/src/vs/editor/contrib/format/browser/format.ts +++ b/src/vs/editor/contrib/format/browser/format.ts @@ -21,7 +21,7 @@ import { Selection } from 'vs/editor/common/core/selection'; import { ScrollType } from 'vs/editor/common/editorCommon'; import { ITextModel } from 'vs/editor/common/model'; import { ISingleEditOperation } from 'vs/editor/common/core/editOperation'; -import { DocumentFormattingEditProvider, DocumentFormattingEditProviderRegistry, DocumentRangeFormattingEditProvider, DocumentRangeFormattingEditProviderRegistry, FormattingOptions, OnTypeFormattingEditProviderRegistry, TextEdit } from 'vs/editor/common/languages'; +import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, FormattingOptions, TextEdit } from 'vs/editor/common/languages'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit'; @@ -30,6 +30,8 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IProgress } from 'vs/platform/progress/common/progress'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry'; export function alertFormattingEdits(edits: ISingleEditOperation[]): void { @@ -58,12 +60,16 @@ export function alertFormattingEdits(edits: ISingleEditOperation[]): void { } } -export function getRealAndSyntheticDocumentFormattersOrdered(model: ITextModel): DocumentFormattingEditProvider[] { +export function getRealAndSyntheticDocumentFormattersOrdered( + documentFormattingEditProvider: LanguageFeatureRegistry, + documentRangeFormattingEditProvider: LanguageFeatureRegistry, + model: ITextModel +): DocumentFormattingEditProvider[] { const result: DocumentFormattingEditProvider[] = []; const seen = new Set(); // (1) add all document formatter - const docFormatter = DocumentFormattingEditProviderRegistry.ordered(model); + const docFormatter = documentFormattingEditProvider.ordered(model); for (const formatter of docFormatter) { result.push(formatter); if (formatter.extensionId) { @@ -72,7 +78,7 @@ export function getRealAndSyntheticDocumentFormattersOrdered(model: ITextModel): } // (2) add all range formatter as document formatter (unless the same extension already did that) - const rangeFormatter = DocumentRangeFormattingEditProviderRegistry.ordered(model); + const rangeFormatter = documentRangeFormattingEditProvider.ordered(model); for (const formatter of rangeFormatter) { if (formatter.extensionId) { if (seen.has(ExtensionIdentifier.toKey(formatter.extensionId))) { @@ -131,8 +137,9 @@ export async function formatDocumentRangesWithSelectedProvider( ): Promise { const instaService = accessor.get(IInstantiationService); + const { documentRangeFormattingEditProvider: documentRangeFormattingEditProviderRegistry } = accessor.get(ILanguageFeaturesService); const model = isCodeEditor(editorOrModel) ? editorOrModel.getModel() : editorOrModel; - const provider = DocumentRangeFormattingEditProviderRegistry.ordered(model); + const provider = documentRangeFormattingEditProviderRegistry.ordered(model); const selected = await FormattingConflicts.select(provider, model, mode); if (selected) { progress.report(selected); @@ -286,8 +293,9 @@ export async function formatDocumentWithSelectedProvider( ): Promise { const instaService = accessor.get(IInstantiationService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const model = isCodeEditor(editorOrModel) ? editorOrModel.getModel() : editorOrModel; - const provider = getRealAndSyntheticDocumentFormattersOrdered(model); + const provider = getRealAndSyntheticDocumentFormattersOrdered(languageFeaturesService.documentFormattingEditProvider, languageFeaturesService.documentRangeFormattingEditProvider, model); const selected = await FormattingConflicts.select(provider, model, mode); if (selected) { progress.report(selected); @@ -370,13 +378,14 @@ export async function formatDocumentWithProvider( export async function getDocumentRangeFormattingEditsUntilResult( workerService: IEditorWorkerService, + languageFeaturesService: ILanguageFeaturesService, model: ITextModel, range: Range, options: FormattingOptions, token: CancellationToken ): Promise { - const providers = DocumentRangeFormattingEditProviderRegistry.ordered(model); + const providers = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model); for (const provider of providers) { let rawEdits = await Promise.resolve(provider.provideDocumentRangeFormattingEdits(model, range, options, token)).catch(onUnexpectedExternalError); if (isNonEmptyArray(rawEdits)) { @@ -388,12 +397,13 @@ export async function getDocumentRangeFormattingEditsUntilResult( export async function getDocumentFormattingEditsUntilResult( workerService: IEditorWorkerService, + languageFeaturesService: ILanguageFeaturesService, model: ITextModel, options: FormattingOptions, token: CancellationToken ): Promise { - const providers = getRealAndSyntheticDocumentFormattersOrdered(model); + const providers = getRealAndSyntheticDocumentFormattersOrdered(languageFeaturesService.documentFormattingEditProvider, languageFeaturesService.documentRangeFormattingEditProvider, model); for (const provider of providers) { let rawEdits = await Promise.resolve(provider.provideDocumentFormattingEdits(model, options, token)).catch(onUnexpectedExternalError); if (isNonEmptyArray(rawEdits)) { @@ -405,6 +415,7 @@ export async function getDocumentFormattingEditsUntilResult( export function getOnTypeFormattingEdits( workerService: IEditorWorkerService, + languageFeaturesService: ILanguageFeaturesService, model: ITextModel, position: Position, ch: string, @@ -412,7 +423,7 @@ export function getOnTypeFormattingEdits( token: CancellationToken ): Promise { - const providers = OnTypeFormattingEditProviderRegistry.ordered(model); + const providers = languageFeaturesService.onTypeFormattingEditProvider.ordered(model); if (providers.length === 0) { return Promise.resolve(undefined); @@ -434,9 +445,10 @@ CommandsRegistry.registerCommand('_executeFormatRangeProvider', async function ( const resolverService = accessor.get(ITextModelService); const workerService = accessor.get(IEditorWorkerService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const reference = await resolverService.createModelReference(resource); try { - return getDocumentRangeFormattingEditsUntilResult(workerService, reference.object.textEditorModel, Range.lift(range), options, CancellationToken.None); + return getDocumentRangeFormattingEditsUntilResult(workerService, languageFeaturesService, reference.object.textEditorModel, Range.lift(range), options, CancellationToken.None); } finally { reference.dispose(); } @@ -448,9 +460,10 @@ CommandsRegistry.registerCommand('_executeFormatDocumentProvider', async functio const resolverService = accessor.get(ITextModelService); const workerService = accessor.get(IEditorWorkerService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const reference = await resolverService.createModelReference(resource); try { - return getDocumentFormattingEditsUntilResult(workerService, reference.object.textEditorModel, options, CancellationToken.None); + return getDocumentFormattingEditsUntilResult(workerService, languageFeaturesService, reference.object.textEditorModel, options, CancellationToken.None); } finally { reference.dispose(); } @@ -464,9 +477,10 @@ CommandsRegistry.registerCommand('_executeFormatOnTypeProvider', async function const resolverService = accessor.get(ITextModelService); const workerService = accessor.get(IEditorWorkerService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const reference = await resolverService.createModelReference(resource); try { - return getOnTypeFormattingEdits(workerService, reference.object.textEditorModel, Position.lift(position), ch, options, CancellationToken.None); + return getOnTypeFormattingEdits(workerService, languageFeaturesService, reference.object.textEditorModel, Position.lift(position), ch, options, CancellationToken.None); } finally { reference.dispose(); } diff --git a/src/vs/editor/contrib/format/browser/formatActions.ts b/src/vs/editor/contrib/format/browser/formatActions.ts index 1c1e6f6a3fa..df01e5796ba 100644 --- a/src/vs/editor/contrib/format/browser/formatActions.ts +++ b/src/vs/editor/contrib/format/browser/formatActions.ts @@ -16,8 +16,8 @@ import { CharacterSet } from 'vs/editor/common/core/characterClassifier'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { DocumentRangeFormattingEditProviderRegistry, OnTypeFormattingEditProviderRegistry } from 'vs/editor/common/languages'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; import { alertFormattingEdits, formatDocumentRangesWithSelectedProvider, formatDocumentWithSelectedProvider, FormattingMode, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/browser/format'; import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit'; import * as nls from 'vs/nls'; @@ -37,10 +37,11 @@ class FormatOnType implements IEditorContribution { constructor( private readonly _editor: ICodeEditor, + @ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService, @IEditorWorkerService private readonly _workerService: IEditorWorkerService ) { - this._disposables.add(OnTypeFormattingEditProviderRegistry.onDidChange(this._update, this)); + this._disposables.add(_languageFeaturesService.onTypeFormattingEditProvider.onDidChange(this._update, this)); this._disposables.add(_editor.onDidChangeModel(() => this._update())); this._disposables.add(_editor.onDidChangeModelLanguage(() => this._update())); this._disposables.add(_editor.onDidChangeConfiguration(e => { @@ -73,7 +74,7 @@ class FormatOnType implements IEditorContribution { const model = this._editor.getModel(); // no support - const [support] = OnTypeFormattingEditProviderRegistry.ordered(model); + const [support] = this._languageFeaturesService.onTypeFormattingEditProvider.ordered(model); if (!support || !support.autoFormatTriggerCharacters) { return; } @@ -129,6 +130,7 @@ class FormatOnType implements IEditorContribution { getOnTypeFormattingEdits( this._workerService, + this._languageFeaturesService, model, position, ch, @@ -157,12 +159,13 @@ class FormatOnPaste implements IEditorContribution { constructor( private readonly editor: ICodeEditor, + @ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService, @IInstantiationService private readonly _instantiationService: IInstantiationService, ) { this._callOnDispose.add(editor.onDidChangeConfiguration(() => this._update())); this._callOnDispose.add(editor.onDidChangeModel(() => this._update())); this._callOnDispose.add(editor.onDidChangeModelLanguage(() => this._update())); - this._callOnDispose.add(DocumentRangeFormattingEditProviderRegistry.onDidChange(this._update, this)); + this._callOnDispose.add(_languageFeaturesService.documentRangeFormattingEditProvider.onDidChange(this._update, this)); } dispose(): void { @@ -186,7 +189,7 @@ class FormatOnPaste implements IEditorContribution { } // no formatter - if (!DocumentRangeFormattingEditProviderRegistry.has(this.editor.getModel())) { + if (!this._languageFeaturesService.documentRangeFormattingEditProvider.has(this.editor.getModel())) { return; } diff --git a/src/vs/editor/standalone/browser/standaloneLanguages.ts b/src/vs/editor/standalone/browser/standaloneLanguages.ts index 4397bc8c4ec..ba4ba41c961 100644 --- a/src/vs/editor/standalone/browser/standaloneLanguages.ts +++ b/src/vs/editor/standalone/browser/standaloneLanguages.ts @@ -528,21 +528,24 @@ export function registerCodeActionProvider(languageId: string, provider: CodeAct * Register a formatter that can handle only entire models. */ export function registerDocumentFormattingEditProvider(languageId: string, provider: languages.DocumentFormattingEditProvider): IDisposable { - return languages.DocumentFormattingEditProviderRegistry.register(languageId, provider); + const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService); + return languageFeaturesService.documentFormattingEditProvider.register(languageId, provider); } /** * Register a formatter that can handle a range inside a model. */ export function registerDocumentRangeFormattingEditProvider(languageId: string, provider: languages.DocumentRangeFormattingEditProvider): IDisposable { - return languages.DocumentRangeFormattingEditProviderRegistry.register(languageId, provider); + const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService); + return languageFeaturesService.documentRangeFormattingEditProvider.register(languageId, provider); } /** * Register a formatter than can do formatting as the user types. */ export function registerOnTypeFormattingEditProvider(languageId: string, provider: languages.OnTypeFormattingEditProvider): IDisposable { - return languages.OnTypeFormattingEditProviderRegistry.register(languageId, provider); + const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService); + return languageFeaturesService.onTypeFormattingEditProvider.register(languageId, provider); } /** diff --git a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts index 0ef6c7d0f97..2f248dfe461 100644 --- a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts +++ b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts @@ -363,7 +363,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha // --- formatting $registerDocumentFormattingSupport(handle: number, selector: IDocumentFilterDto[], extensionId: ExtensionIdentifier, displayName: string): void { - this._registrations.set(handle, modes.DocumentFormattingEditProviderRegistry.register(selector, { + this._registrations.set(handle, this._languageFeaturesService.documentFormattingEditProvider.register(selector, { extensionId, displayName, provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise => { @@ -373,7 +373,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha } $registerRangeFormattingSupport(handle: number, selector: IDocumentFilterDto[], extensionId: ExtensionIdentifier, displayName: string): void { - this._registrations.set(handle, modes.DocumentRangeFormattingEditProviderRegistry.register(selector, { + this._registrations.set(handle, this._languageFeaturesService.documentRangeFormattingEditProvider.register(selector, { extensionId, displayName, provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise => { @@ -383,7 +383,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha } $registerOnTypeFormattingSupport(handle: number, selector: IDocumentFilterDto[], autoFormatTriggerCharacters: string[], extensionId: ExtensionIdentifier): void { - this._registrations.set(handle, modes.OnTypeFormattingEditProviderRegistry.register(selector, { + this._registrations.set(handle, this._languageFeaturesService.onTypeFormattingEditProvider.register(selector, { extensionId, autoFormatTriggerCharacters, provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise => { diff --git a/src/vs/workbench/api/test/browser/extHostLanguageFeatures.test.ts b/src/vs/workbench/api/test/browser/extHostLanguageFeatures.test.ts index 0b62af872aa..951aaac4d3e 100644 --- a/src/vs/workbench/api/test/browser/extHostLanguageFeatures.test.ts +++ b/src/vs/workbench/api/test/browser/extHostLanguageFeatures.test.ts @@ -1048,7 +1048,7 @@ suite('ExtHostLanguageFeatures', function () { })); await rpcProtocol.sync(); - let value = (await getDocumentFormattingEditsUntilResult(NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; + let value = (await getDocumentFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; assert.strictEqual(value.length, 2); let [first, second] = value; assert.strictEqual(first.text, 'testing'); @@ -1066,7 +1066,7 @@ suite('ExtHostLanguageFeatures', function () { })); await rpcProtocol.sync(); - return getDocumentFormattingEditsUntilResult(NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None); + return getDocumentFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None); }); test('Format Doc, order', async () => { @@ -1090,7 +1090,7 @@ suite('ExtHostLanguageFeatures', function () { })); await rpcProtocol.sync(); - let value = (await getDocumentFormattingEditsUntilResult(NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; + let value = (await getDocumentFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; assert.strictEqual(value.length, 1); let [first] = value; assert.strictEqual(first.text, 'testing'); @@ -1105,7 +1105,7 @@ suite('ExtHostLanguageFeatures', function () { })); await rpcProtocol.sync(); - const value = (await getDocumentRangeFormattingEditsUntilResult(NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; + const value = (await getDocumentRangeFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; assert.strictEqual(value.length, 1); const [first] = value; assert.strictEqual(first.text, 'testing'); @@ -1129,7 +1129,7 @@ suite('ExtHostLanguageFeatures', function () { } })); await rpcProtocol.sync(); - const value = (await getDocumentRangeFormattingEditsUntilResult(NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; + const value = (await getDocumentRangeFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None))!; assert.strictEqual(value.length, 1); const [first] = value; assert.strictEqual(first.text, 'range2'); @@ -1147,7 +1147,7 @@ suite('ExtHostLanguageFeatures', function () { })); await rpcProtocol.sync(); - return getDocumentRangeFormattingEditsUntilResult(NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None); + return getDocumentRangeFormattingEditsUntilResult(NullWorkerService, languageFeaturesService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None); }); test('Format on Type, data conversion', async () => { @@ -1159,7 +1159,7 @@ suite('ExtHostLanguageFeatures', function () { }, [';'])); await rpcProtocol.sync(); - const value = (await getOnTypeFormattingEdits(NullWorkerService, model, new EditorPosition(1, 1), ';', { insertSpaces: true, tabSize: 2 }, CancellationToken.None))!; + const value = (await getOnTypeFormattingEdits(NullWorkerService, languageFeaturesService, model, new EditorPosition(1, 1), ';', { insertSpaces: true, tabSize: 2 }, CancellationToken.None))!; assert.strictEqual(value.length, 1); const [first] = value; assert.strictEqual(first.text, ';'); diff --git a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts index 0e4df8b308f..ffd1d49fe74 100644 --- a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts +++ b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts @@ -6,7 +6,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, registerEditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { DocumentRangeFormattingEditProviderRegistry, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from 'vs/editor/common/languages'; +import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from 'vs/editor/common/languages'; import * as nls from 'vs/nls'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput'; @@ -29,6 +29,7 @@ import { ILanguageService } from 'vs/editor/common/services/language'; import { IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; import { editorConfigurationBaseNode } from 'vs/editor/common/config/editorConfigurationSchema'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; type FormattingEditProvider = DocumentFormattingEditProvider | DocumentRangeFormattingEditProvider; @@ -305,8 +306,9 @@ registerEditorAction(class FormatDocumentMultipleAction extends EditorAction { } const instaService = accessor.get(IInstantiationService); const telemetryService = accessor.get(ITelemetryService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const model = editor.getModel(); - const provider = getRealAndSyntheticDocumentFormattersOrdered(model); + const provider = getRealAndSyntheticDocumentFormattersOrdered(languageFeaturesService.documentFormattingEditProvider, languageFeaturesService.documentRangeFormattingEditProvider, model); const pick = await instaService.invokeFunction(showFormatterPick, model, provider); if (typeof pick === 'number') { await instaService.invokeFunction(formatDocumentWithProvider, provider[pick], editor, FormattingMode.Explicit, CancellationToken.None); @@ -336,6 +338,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction { return; } const instaService = accessor.get(IInstantiationService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const telemetryService = accessor.get(ITelemetryService); const model = editor.getModel(); @@ -344,7 +347,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction { range = new Range(range.startLineNumber, 1, range.startLineNumber, model.getLineMaxColumn(range.startLineNumber)); } - const provider = DocumentRangeFormattingEditProviderRegistry.ordered(model); + const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model); const pick = await instaService.invokeFunction(showFormatterPick, model, provider); if (typeof pick === 'number') { await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None); diff --git a/src/vs/workbench/contrib/format/browser/formatActionsNone.ts b/src/vs/workbench/contrib/format/browser/formatActionsNone.ts index 4bc0210545c..b32e1dc76fb 100644 --- a/src/vs/workbench/contrib/format/browser/formatActionsNone.ts +++ b/src/vs/workbench/contrib/format/browser/formatActionsNone.ts @@ -7,7 +7,6 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, registerEditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { DocumentFormattingEditProviderRegistry } from 'vs/editor/common/languages'; import * as nls from 'vs/nls'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; @@ -17,6 +16,7 @@ import { VIEWLET_ID, IExtensionsViewPaneContainer } from 'vs/workbench/contrib/e import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { ViewContainerLocation } from 'vs/workbench/common/views'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; async function showExtensionQuery(paneCompositeService: IPaneCompositePartService, query: string) { const viewlet = await paneCompositeService.openPaneComposite(VIEWLET_ID, ViewContainerLocation.Sidebar, true); @@ -51,9 +51,10 @@ registerEditorAction(class FormatDocumentMultipleAction extends EditorAction { const paneCompositeService = accessor.get(IPaneCompositePartService); const notificationService = accessor.get(INotificationService); const dialogService = accessor.get(IDialogService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const model = editor.getModel(); - const formatterCount = DocumentFormattingEditProviderRegistry.all(model).length; + const formatterCount = languageFeaturesService.documentFormattingEditProvider.all(model).length; if (formatterCount > 1) { return commandService.executeCommand('editor.action.formatDocument.multiple'); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts b/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts index 6c85ccf7185..b66379399c8 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts @@ -24,6 +24,7 @@ import { registerEditorAction, EditorAction } from 'vs/editor/browser/editorExte import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { Progress } from 'vs/platform/progress/common/progress'; import { flatten } from 'vs/base/common/arrays'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; // format notebook registerAction2(class extends Action2 { @@ -53,6 +54,7 @@ registerAction2(class extends Action2 { const editorService = accessor.get(IEditorService); const textModelService = accessor.get(ITextModelService); const editorWorkerService = accessor.get(IEditorWorkerService); + const languageFeaturesService = accessor.get(ILanguageFeaturesService); const bulkEditService = accessor.get(IBulkEditService); const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane); @@ -70,7 +72,9 @@ registerAction2(class extends Action2 { const model = ref.object.textEditorModel; const formatEdits = await getDocumentFormattingEditsUntilResult( - editorWorkerService, model, + editorWorkerService, + languageFeaturesService, + model, model.getOptions(), CancellationToken.None );