提交 32834839 编写于 作者: J Johannes Rieken

add formatter call, use it for no-formatter-case for now #41882

上级 afd3310d
......@@ -118,6 +118,10 @@
"name": "vs/workbench/contrib/snippets",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/format",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/stats",
"project": "vscode-workbench"
......
......@@ -18,6 +18,7 @@ import * as model from 'vs/editor/common/model';
import { LanguageFeatureRegistry } from 'vs/editor/common/modes/languageFeatureRegistry';
import { TokenizationRegistryImpl } from 'vs/editor/common/modes/tokenizationRegistry';
import { IMarkerData } from 'vs/platform/markers/common/markers';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
/**
* Open ended enum at runtime
......@@ -914,7 +915,10 @@ export interface FormattingOptions {
*/
export interface DocumentFormattingEditProvider {
displayName?: string;
/**
* @internal
*/
readonly extensionId?: ExtensionIdentifier;
/**
* Provide formatting edits for a whole document.
......@@ -927,7 +931,11 @@ export interface DocumentFormattingEditProvider {
*/
export interface DocumentRangeFormattingEditProvider {
displayName?: string;
/**
* @internal
*/
readonly extensionId?: ExtensionIdentifier;
/**
* Provide formatting edits for a range in a document.
......@@ -943,7 +951,15 @@ export interface DocumentRangeFormattingEditProvider {
* the formatting-feature.
*/
export interface OnTypeFormattingEditProvider {
/**
* @internal
*/
readonly extensionId?: ExtensionIdentifier;
autoFormatTriggerCharacters: string[];
/**
* Provide formatting edits after a character has been typed.
*
......
......@@ -16,34 +16,57 @@ import { Position } from 'vs/editor/common/core/position';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IDisposable } from 'vs/base/common/lifecycle';
export class NoProviderError extends Error {
export const enum FormatMode {
Auto = 1,
Manual = 2,
}
static is(thing: any): thing is NoProviderError {
return thing instanceof Error && thing.name === NoProviderError._name;
}
export const enum FormatKind {
Document = 8,
Range = 16,
OnType = 32,
}
private static readonly _name = 'NOPRO';
export interface IFormatterConflictCallback {
(extensionIds: ExtensionIdentifier[], model: ITextModel, mode: number): void;
}
constructor(message?: string) {
super();
this.name = NoProviderError._name;
if (message) {
this.message = message;
let _conflictResolver: IFormatterConflictCallback;
export function setFormatterConflictCallback(callback: IFormatterConflictCallback): IDisposable {
let oldCallback = _conflictResolver;
_conflictResolver = callback;
return {
dispose() {
if (oldCallback) {
_conflictResolver = oldCallback;
oldCallback = undefined;
}
}
};
}
function invokeFormatterCallback<T extends { extensionId?: ExtensionIdentifier }>(formatter: T[], model: ITextModel, mode: number): void {
if (_conflictResolver) {
const ids = formatter.map(formatter => formatter.extensionId);
_conflictResolver(ids, model, mode);
}
}
export function getDocumentRangeFormattingEdits(
export async function getDocumentRangeFormattingEdits(
telemetryService: ITelemetryService,
workerService: IEditorWorkerService,
model: ITextModel,
range: Range,
options: FormattingOptions,
mode: FormatMode,
token: CancellationToken
): Promise<TextEdit[] | undefined | null> {
const allProvider = DocumentRangeFormattingEditProviderRegistry.ordered(model);
const providers = DocumentRangeFormattingEditProviderRegistry.ordered(model);
/* __GDPR__
"formatterInfo" : {
......@@ -55,14 +78,12 @@ export function getDocumentRangeFormattingEdits(
telemetryService.publicLog('formatterInfo', {
type: 'range',
language: model.getLanguageIdentifier().language,
count: allProvider.length,
count: providers.length,
});
if (allProvider.length === 0) {
return Promise.reject(new NoProviderError());
}
invokeFormatterCallback(providers, model, mode | FormatKind.Range);
return first(allProvider.map(provider => () => {
return first(providers.map(provider => () => {
return Promise.resolve(provider.provideDocumentRangeFormattingEdits(model, range, options, token)).catch(onUnexpectedExternalError);
}), isNonEmptyArray).then(edits => {
// break edits into smaller edits
......@@ -75,10 +96,11 @@ export function getDocumentFormattingEdits(
workerService: IEditorWorkerService,
model: ITextModel,
options: FormattingOptions,
mode: FormatMode,
token: CancellationToken
): Promise<TextEdit[] | null | undefined> {
const providers = DocumentFormattingEditProviderRegistry.ordered(model);
const docFormattingProviders = DocumentFormattingEditProviderRegistry.ordered(model);
/* __GDPR__
"formatterInfo" : {
......@@ -90,21 +112,21 @@ export function getDocumentFormattingEdits(
telemetryService.publicLog('formatterInfo', {
type: 'document',
language: model.getLanguageIdentifier().language,
count: providers.length,
count: docFormattingProviders.length,
});
// try range formatters when no document formatter is registered
if (providers.length === 0) {
return getDocumentRangeFormattingEdits(telemetryService, workerService, model, model.getFullModelRange(), options, token);
if (docFormattingProviders.length > 0) {
return first(docFormattingProviders.map(provider => () => {
// first with result wins...
return Promise.resolve(provider.provideDocumentFormattingEdits(model, options, token)).catch(onUnexpectedExternalError);
}), isNonEmptyArray).then(edits => {
// break edits into smaller edits
return workerService.computeMoreMinimalEdits(model.uri, edits);
});
} else {
// try range formatters when no document formatter is registered
return getDocumentRangeFormattingEdits(telemetryService, workerService, model, model.getFullModelRange(), options, mode | FormatKind.Document, token);
}
return first(providers.map(provider => () => {
// first with result wins...
return Promise.resolve(provider.provideDocumentFormattingEdits(model, options, token)).catch(onUnexpectedExternalError);
}), isNonEmptyArray).then(edits => {
// break edits into smaller edits
return workerService.computeMoreMinimalEdits(model.uri, edits);
});
}
export function getOnTypeFormattingEdits(
......@@ -153,7 +175,7 @@ registerLanguageCommand('_executeFormatRangeProvider', function (accessor, args)
if (!model) {
throw illegalArgument('resource');
}
return getDocumentRangeFormattingEdits(accessor.get(ITelemetryService), accessor.get(IEditorWorkerService), model, Range.lift(range), options, CancellationToken.None);
return getDocumentRangeFormattingEdits(accessor.get(ITelemetryService), accessor.get(IEditorWorkerService), model, Range.lift(range), options, FormatMode.Auto, CancellationToken.None);
});
registerLanguageCommand('_executeFormatDocumentProvider', function (accessor, args) {
......@@ -166,7 +188,7 @@ registerLanguageCommand('_executeFormatDocumentProvider', function (accessor, ar
throw illegalArgument('resource');
}
return getDocumentFormattingEdits(accessor.get(ITelemetryService), accessor.get(IEditorWorkerService), model, options, CancellationToken.None);
return getDocumentFormattingEdits(accessor.get(ITelemetryService), accessor.get(IEditorWorkerService), model, options, FormatMode.Auto, CancellationToken.None);
});
registerLanguageCommand('_executeFormatOnTypeProvider', function (accessor, args) {
......
......@@ -17,17 +17,15 @@ import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ISingleEditOperation } from 'vs/editor/common/model';
import { DocumentFormattingEditProviderRegistry, DocumentRangeFormattingEditProviderRegistry, FormattingOptions, OnTypeFormattingEditProviderRegistry } from 'vs/editor/common/modes';
import { DocumentRangeFormattingEditProviderRegistry, FormattingOptions, OnTypeFormattingEditProviderRegistry } from 'vs/editor/common/modes';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { getOnTypeFormattingEdits, NoProviderError, getDocumentFormattingEdits, getDocumentRangeFormattingEdits } from 'vs/editor/contrib/format/format';
import { getOnTypeFormattingEdits, getDocumentFormattingEdits, getDocumentRangeFormattingEdits, FormatMode } from 'vs/editor/contrib/format/format';
import { FormattingEdit } from 'vs/editor/contrib/format/formattingEdit';
import * as nls from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { MenuRegistry } from 'vs/platform/actions/common/actions';
function alertFormattingEdits(edits: ISingleEditOperation[]): void {
......@@ -56,12 +54,12 @@ function alertFormattingEdits(edits: ISingleEditOperation[]): void {
}
}
export const enum FormatRangeType {
const enum FormatRangeType {
Full,
Selection,
}
export function formatDocumentRange(
function formatDocumentRange(
telemetryService: ITelemetryService,
workerService: IEditorWorkerService,
editor: IActiveCodeEditor,
......@@ -90,7 +88,7 @@ export function formatDocumentRange(
range = rangeOrRangeType;
}
return getDocumentRangeFormattingEdits(telemetryService, workerService, model, range, options, token).then(edits => {
return getDocumentRangeFormattingEdits(telemetryService, workerService, model, range, options, FormatMode.Manual, token).then(edits => {
// make edit only when the editor didn't change while
// computing and only when there are edits
if (state.validate(editor) && isNonEmptyArray(edits)) {
......@@ -103,12 +101,12 @@ export function formatDocumentRange(
}
export function formatDocument(telemetryService: ITelemetryService, workerService: IEditorWorkerService, editor: IActiveCodeEditor, options: FormattingOptions, token: CancellationToken): Promise<void> {
function formatDocument(telemetryService: ITelemetryService, workerService: IEditorWorkerService, editor: IActiveCodeEditor, options: FormattingOptions, token: CancellationToken): Promise<void> {
const allEdits: ISingleEditOperation[] = [];
const state = new EditorState(editor, CodeEditorStateFlag.Value | CodeEditorStateFlag.Position);
return getDocumentFormattingEdits(telemetryService, workerService, editor.getModel(), options, token).then(edits => {
return getDocumentFormattingEdits(telemetryService, workerService, editor.getModel(), options, FormatMode.Manual, token).then(edits => {
// make edit only when the editor didn't change while
// computing and only when there are edits
if (state.validate(editor) && isNonEmptyArray(edits)) {
......@@ -354,15 +352,10 @@ export class FormatDocumentAction extends EditorAction {
if (!editor.hasModel()) {
return;
}
const notificationService = accessor.get(INotificationService);
const workerService = accessor.get(IEditorWorkerService);
const telemetryService = accessor.get(ITelemetryService);
const { tabSize, insertSpaces } = editor.getModel().getOptions();
return formatDocument(telemetryService, workerService, editor, { tabSize, insertSpaces }, CancellationToken.None).catch(err => {
if (NoProviderError.is(err)) {
notificationService.info(nls.localize('no.documentprovider', "There is no document formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language));
}
});
return formatDocument(telemetryService, workerService, editor, { tabSize, insertSpaces }, CancellationToken.None);
}
}
......@@ -391,15 +384,10 @@ export class FormatSelectionAction extends EditorAction {
if (!editor.hasModel()) {
return;
}
const notificationService = accessor.get(INotificationService);
const workerService = accessor.get(IEditorWorkerService);
const telemetryService = accessor.get(ITelemetryService);
const { tabSize, insertSpaces } = editor.getModel().getOptions();
return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None).catch(err => {
if (NoProviderError.is(err)) {
notificationService.info(nls.localize('no.selectionprovider', "There is no selection formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language));
}
});
return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None);
}
}
......@@ -425,38 +413,3 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => {
return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None);
}
});
CommandsRegistry.registerCommand('editor.action.formatInspect', accessor => {
const editor = accessor.get(ICodeEditorService).getActiveCodeEditor();
if (!editor || !editor.hasModel()) {
return;
}
console.log(`Available Formatters for: ${editor.getModel().uri.toString(true)}`);
// range formatters
const documentRangeProvider = DocumentRangeFormattingEditProviderRegistry.ordered(editor.getModel());
console.group('Range Formatters');
if (documentRangeProvider.length === 0) {
console.log('none');
} else {
documentRangeProvider.forEach(value => console.log(value.displayName));
}
console.groupEnd();
// whole document formatters
const documentProvider = DocumentFormattingEditProviderRegistry.ordered(editor.getModel());
console.group('Document Formatters');
if (documentProvider.length === 0) {
console.log('none');
} else {
documentProvider.forEach(value => console.log(value.displayName));
}
console.groupEnd();
});
MenuRegistry.addCommand({
id: 'editor.action.formatInspect',
category: nls.localize('cat', "Developer"),
title: nls.localize('title', "Print Available Formatters..."),
});
......@@ -5167,7 +5167,6 @@ declare namespace monaco.languages {
* the formatting-feature.
*/
export interface DocumentFormattingEditProvider {
displayName?: string;
/**
* Provide formatting edits for a whole document.
*/
......@@ -5179,7 +5178,6 @@ declare namespace monaco.languages {
* the formatting-feature.
*/
export interface DocumentRangeFormattingEditProvider {
displayName?: string;
/**
* Provide formatting edits for a range in a document.
*
......
......@@ -21,6 +21,7 @@ import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import { URI } from 'vs/base/common/uri';
import { Selection } from 'vs/editor/common/core/selection';
import * as codeInset from 'vs/workbench/contrib/codeinset/common/codeInset';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
@extHostNamedCustomer(MainContext.MainThreadLanguageFeatures)
export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesShape {
......@@ -270,29 +271,28 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
// --- formatting
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], extensionId: ExtensionIdentifier): void {
this._registrations[handle] = modes.DocumentFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentFormattingEditProvider>{
displayName,
extensionId,
provideDocumentFormattingEdits: (model: ITextModel, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideDocumentFormattingEdits(handle, model.uri, options, token);
}
});
}
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], displayName: string): void {
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], extensionId: ExtensionIdentifier): void {
this._registrations[handle] = modes.DocumentRangeFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DocumentRangeFormattingEditProvider>{
displayName,
extensionId,
provideDocumentRangeFormattingEdits: (model: ITextModel, range: EditorRange, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideDocumentRangeFormattingEdits(handle, model.uri, range, options, token);
}
});
}
$registerOnTypeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], autoFormatTriggerCharacters: string[]): void {
$registerOnTypeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], autoFormatTriggerCharacters: string[], extensionId: ExtensionIdentifier): void {
this._registrations[handle] = modes.OnTypeFormattingEditProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.OnTypeFormattingEditProvider>{
extensionId,
autoFormatTriggerCharacters,
provideOnTypeFormattingEdits: (model: ITextModel, position: EditorPosition, ch: string, options: modes.FormattingOptions, token: CancellationToken): Promise<ISingleEditOperation[] | undefined> => {
return this._proxy.$provideOnTypeFormattingEdits(handle, model.uri, position, ch, options, token);
}
......
......@@ -23,7 +23,7 @@ import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
import { applyCodeAction } from 'vs/editor/contrib/codeAction/codeActionCommands';
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { getDocumentFormattingEdits, NoProviderError } from 'vs/editor/contrib/format/format';
import { getDocumentFormattingEdits, FormatMode } from 'vs/editor/contrib/format/format';
import { FormattingEdit } from 'vs/editor/contrib/format/formattingEdit';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
import { localize } from 'vs/nls';
......@@ -237,20 +237,14 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
return new Promise<ISingleEditOperation[] | null | undefined>((resolve, reject) => {
let source = new CancellationTokenSource();
let request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, { tabSize, insertSpaces }, source.token);
let request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, { tabSize, insertSpaces }, FormatMode.Auto, source.token);
setTimeout(() => {
reject(localize('timeout.formatOnSave', "Aborted format on save after {0}ms", timeout));
source.cancel();
}, timeout);
request.then(resolve, err => {
if (!NoProviderError.is(err)) {
reject(err);
} else {
resolve();
}
});
request.then(resolve, reject);
}).then(edits => {
if (isNonEmptyArray(edits) && versionNow === model.getVersionId()) {
......
......@@ -310,9 +310,9 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
$registerDocumentHighlightProvider(handle: number, selector: ISerializedDocumentFilter[]): void;
$registerReferenceSupport(handle: number, selector: ISerializedDocumentFilter[]): void;
$registerQuickFixSupport(handle: number, selector: ISerializedDocumentFilter[], supportedKinds?: string[]): void;
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], label: string): void;
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], label: string): void;
$registerOnTypeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], autoFormatTriggerCharacters: string[]): void;
$registerDocumentFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], extensionId: ExtensionIdentifier): void;
$registerRangeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], extensionId: ExtensionIdentifier): void;
$registerOnTypeFormattingSupport(handle: number, selector: ISerializedDocumentFilter[], autoFormatTriggerCharacters: string[], extensionId: ExtensionIdentifier): void;
$registerNavigateTypeSupport(handle: number): void;
$registerRenameSupport(handle: number, selector: ISerializedDocumentFilter[], supportsResolveInitialValues: boolean): void;
$registerSuggestSupport(handle: number, selector: ISerializedDocumentFilter[], triggerCharacters: string[], supportsResolveDetails: boolean): void;
......
......@@ -1256,7 +1256,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
registerDocumentFormattingEditProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
const handle = this._addNewAdapter(new DocumentFormattingAdapter(this._documents, provider), extension);
this._proxy.$registerDocumentFormattingSupport(handle, this._transformDocumentSelector(selector), ExtHostLanguageFeatures._extLabel(extension));
this._proxy.$registerDocumentFormattingSupport(handle, this._transformDocumentSelector(selector), extension.identifier);
return this._createDisposable(handle);
}
......@@ -1266,7 +1266,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
registerDocumentRangeFormattingEditProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
const handle = this._addNewAdapter(new RangeFormattingAdapter(this._documents, provider), extension);
this._proxy.$registerRangeFormattingSupport(handle, this._transformDocumentSelector(selector), ExtHostLanguageFeatures._extLabel(extension));
this._proxy.$registerRangeFormattingSupport(handle, this._transformDocumentSelector(selector), extension.identifier);
return this._createDisposable(handle);
}
......@@ -1276,7 +1276,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
registerOnTypeFormattingEditProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, triggerCharacters: string[]): vscode.Disposable {
const handle = this._addNewAdapter(new OnTypeFormattingAdapter(this._documents, provider), extension);
this._proxy.$registerOnTypeFormattingSupport(handle, this._transformDocumentSelector(selector), triggerCharacters);
this._proxy.$registerOnTypeFormattingSupport(handle, this._transformDocumentSelector(selector), triggerCharacters, extension.identifier);
return this._createDisposable(handle);
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { setFormatterConflictCallback, FormatMode, FormatKind } from 'vs/editor/contrib/format/format';
import { IDisposable } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { VIEWLET_ID, IExtensionsViewlet } from 'vs/workbench/contrib/extensions/common/extensions';
class FormattingConflictHandler {
private _registration: IDisposable;
constructor(
@INotificationService notificationService: INotificationService,
@IViewletService private readonly _viewletService: IViewletService,
) {
this._registration = setFormatterConflictCallback((ids, model, mode) => {
if (mode & FormatMode.Auto) {
return;
}
if (ids.length === 0) {
const langName = model.getLanguageIdentifier().language;
const message = mode & FormatKind.Document
? localize('no.documentprovider', "There is no document formatter for '{0}'-files installed.", langName)
: localize('no.selectionprovider', "There is no selection formatter for '{0}'-files installed.", langName);
const choice = {
label: localize('install.formatter', "Install Formatter..."),
run: () => {
return this._viewletService.openViewlet(VIEWLET_ID, true).then(viewlet => {
if (viewlet) {
(viewlet as IExtensionsViewlet).search(`category:formatters ${langName}`);
}
});
}
};
notificationService.prompt(Severity.Info, message, [choice]);
}
});
}
dispose(): void {
this._registration.dispose();
}
}
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
FormattingConflictHandler,
LifecyclePhase.Restored
);
......@@ -33,7 +33,7 @@ import { getWorkspaceSymbols } from 'vs/workbench/contrib/search/common/search';
import { rename } from 'vs/editor/contrib/rename/rename';
import { provideSignatureHelp } from 'vs/editor/contrib/parameterHints/provideSignatureHelp';
import { provideSuggestionItems } from 'vs/editor/contrib/suggest/suggest';
import { getDocumentFormattingEdits, getDocumentRangeFormattingEdits, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/format';
import { getDocumentFormattingEdits, getDocumentRangeFormattingEdits, getOnTypeFormattingEdits, FormatMode } from 'vs/editor/contrib/format/format';
import { getLinks } from 'vs/editor/contrib/links/getLinks';
import { MainContext, ExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
......@@ -925,7 +925,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
let value = await getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
let value = await getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
assert.equal(value.length, 2);
let [first, second] = value;
assert.equal(first.text, 'testing');
......@@ -943,7 +943,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
return getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
return getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
});
test('Format Doc, order', async () => {
......@@ -967,7 +967,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
let value = await getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
let value = await getDocumentFormattingEdits(NullTelemetryService, NullWorkerService, model, { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
assert.equal(value.length, 1);
let [first] = value;
assert.equal(first.text, 'testing');
......@@ -982,7 +982,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
let value = await getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
let value = await getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
assert.equal(value.length, 1);
let [first] = value;
assert.equal(first.text, 'testing');
......@@ -1006,7 +1006,7 @@ suite('ExtHostLanguageFeatures', function () {
}
}));
await rpcProtocol.sync();
let value = await getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
let value = await getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
assert.equal(value.length, 1);
let [first] = value;
assert.equal(first.text, 'range2');
......@@ -1024,7 +1024,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
return getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, CancellationToken.None);
return getDocumentRangeFormattingEdits(NullTelemetryService, NullWorkerService, model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }, FormatMode.Auto, CancellationToken.None);
});
test('Format on Type, data conversion', async () => {
......
......@@ -140,6 +140,9 @@ import 'vs/workbench/contrib/snippets/browser/insertSnippet';
import 'vs/workbench/contrib/snippets/browser/configureSnippets';
import 'vs/workbench/contrib/snippets/browser/tabCompletion';
// Formatter Help
import 'vs/workbench/contrib/format/browser/format.contribution';
// Send a Smile
import 'vs/workbench/contrib/feedback/electron-browser/feedback.contribution';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册