mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-31 09:10:30 -04:00
Merge from vscode 011858832762aaff245b2336fb1c38166e7a10fb (#4663)
This commit is contained in:
@@ -3,57 +3,6 @@
|
||||
* Licensed under the Source EULA. 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
|
||||
);
|
||||
import 'vs/css!./media/format.contribution';
|
||||
import './formatActionsMultiple';
|
||||
import './formatActionsNone';
|
||||
|
||||
138
src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts
Normal file
138
src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { KeyChord, 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 { DocumentRangeFormattingEditProviderRegistry } from 'vs/editor/common/modes';
|
||||
import * as nls from 'vs/nls';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IQuickInputService, IQuickPickItem, IQuickInputButton } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { formatDocumentRangeWithProvider, formatDocumentWithProvider, getRealAndSyntheticDocumentFormattersOrdered } from 'vs/editor/contrib/format/format';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { showExtensionQuery } from 'vs/workbench/contrib/format/browser/showExtensionQuery';
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
|
||||
interface IIndexedPick extends IQuickPickItem {
|
||||
index: number;
|
||||
}
|
||||
|
||||
const openExtensionAction: IQuickInputButton = {
|
||||
tooltip: nls.localize('show.ext', "Show extension..."),
|
||||
iconClass: 'format-show-extension'
|
||||
};
|
||||
|
||||
registerEditorAction(class FormatDocumentMultipleAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.formatDocument.multiple',
|
||||
label: nls.localize('formatDocument.label.multiple', "Format Document..."),
|
||||
alias: 'Format Document...',
|
||||
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasMultipleDocumentFormattingProvider),
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.editorTextFocus,
|
||||
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F,
|
||||
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I },
|
||||
weight: KeybindingWeight.EditorContrib,
|
||||
},
|
||||
menuOpts: {
|
||||
group: '1_modification',
|
||||
order: 1.3
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): Promise<void> {
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
const instaService = accessor.get(IInstantiationService);
|
||||
const quickPickService = accessor.get(IQuickInputService);
|
||||
const viewletService = accessor.get(IViewletService);
|
||||
const model = editor.getModel();
|
||||
|
||||
const provider = getRealAndSyntheticDocumentFormattersOrdered(model);
|
||||
const picks = provider.map((provider, index) => {
|
||||
return <IIndexedPick>{
|
||||
index,
|
||||
label: provider.displayName || '',
|
||||
buttons: [openExtensionAction]
|
||||
};
|
||||
});
|
||||
|
||||
const pick = await quickPickService.pick(picks, {
|
||||
placeHolder: nls.localize('format.placeHolder', "Select a formatter"),
|
||||
onDidTriggerItemButton: (e) => {
|
||||
const { extensionId } = provider[e.item.index];
|
||||
return showExtensionQuery(viewletService, `@id:${extensionId!.value}`);
|
||||
}
|
||||
});
|
||||
if (pick) {
|
||||
await instaService.invokeFunction(formatDocumentWithProvider, provider[pick.index], editor, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
registerEditorAction(class FormatSelectionMultipleAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.formatSelection.multiple',
|
||||
label: nls.localize('formatSelection.label.multiple', "Format Selection..."),
|
||||
alias: 'Format Code...',
|
||||
precondition: ContextKeyExpr.and(ContextKeyExpr.and(EditorContextKeys.writable), EditorContextKeys.hasMultipleDocumentSelectionFormattingProvider),
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.editorTextFocus,
|
||||
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_F),
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
},
|
||||
menuOpts: {
|
||||
when: ContextKeyExpr.and(EditorContextKeys.hasNonEmptySelection),
|
||||
group: '1_modification',
|
||||
order: 1.31
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
const instaService = accessor.get(IInstantiationService);
|
||||
const quickPickService = accessor.get(IQuickInputService);
|
||||
const viewletService = accessor.get(IViewletService);
|
||||
const model = editor.getModel();
|
||||
|
||||
let range: Range = editor.getSelection();
|
||||
if (range.isEmpty()) {
|
||||
range = new Range(range.startLineNumber, 1, range.startLineNumber, model.getLineMaxColumn(range.startLineNumber));
|
||||
}
|
||||
|
||||
const provider = DocumentRangeFormattingEditProviderRegistry.ordered(model);
|
||||
const picks = provider.map((provider, index) => {
|
||||
return <IIndexedPick>{
|
||||
index,
|
||||
label: provider.displayName || '',
|
||||
buttons: [openExtensionAction]
|
||||
};
|
||||
});
|
||||
|
||||
const pick = await quickPickService.pick(picks, {
|
||||
placeHolder: nls.localize('format.placeHolder', "Select a formatter"),
|
||||
onDidTriggerItemButton: (e) => {
|
||||
const { extensionId } = provider[e.item.index];
|
||||
return showExtensionQuery(viewletService, `@id:${extensionId!.value}`);
|
||||
}
|
||||
});
|
||||
if (pick) {
|
||||
await instaService.invokeFunction(formatDocumentRangeWithProvider, provider[pick.index], editor, range, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
});
|
||||
61
src/vs/workbench/contrib/format/browser/formatActionsNone.ts
Normal file
61
src/vs/workbench/contrib/format/browser/formatActionsNone.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
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/modes';
|
||||
import * as nls from 'vs/nls';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { showExtensionQuery } from 'vs/workbench/contrib/format/browser/showExtensionQuery';
|
||||
|
||||
registerEditorAction(class FormatDocumentMultipleAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.formatDocument.none',
|
||||
label: nls.localize('formatDocument.label.multiple', "Format Document"),
|
||||
alias: 'Format Document',
|
||||
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasDocumentFormattingProvider.toNegated()),
|
||||
kbOpts: {
|
||||
kbExpr: ContextKeyExpr.and(EditorContextKeys.editorTextFocus, EditorContextKeys.hasDocumentFormattingProvider.toNegated()),
|
||||
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F,
|
||||
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I },
|
||||
weight: KeybindingWeight.EditorContrib,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): Promise<void> {
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const commandService = accessor.get(ICommandService);
|
||||
const viewletService = accessor.get(IViewletService);
|
||||
const notificationService = accessor.get(INotificationService);
|
||||
const model = editor.getModel();
|
||||
const formatterCount = DocumentFormattingEditProviderRegistry.all(model).length;
|
||||
|
||||
if (formatterCount > 1) {
|
||||
return commandService.executeCommand('editor.action.formatDocument.multiple');
|
||||
} else if (formatterCount === 1) {
|
||||
return commandService.executeCommand('editor.action.formatDocument');
|
||||
} else {
|
||||
const langName = model.getLanguageIdentifier().language;
|
||||
const message = nls.localize('no.rovider', "There is no formatter for '{0}'-files installed.", langName);
|
||||
const choice = {
|
||||
label: nls.localize('install.formatter', "Install Formatter..."),
|
||||
run: () => showExtensionQuery(viewletService, `category:formatters ${langName}`)
|
||||
};
|
||||
notificationService.prompt(Severity.Info, message, [choice]);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g fill="#C5C5C5"><path d="M12.714 9.603c-.07.207-.15.407-.246.601l1.017 2.139c-.335.424-.718.807-1.142 1.143l-2.14-1.018c-.193.097-.394.176-.601.247l-.795 2.235c-.265.03-.534.05-.807.05-.272 0-.541-.02-.806-.05l-.795-2.235c-.207-.071-.408-.15-.602-.247l-2.14 1.017c-.424-.336-.807-.719-1.143-1.143l1.017-2.139c-.094-.193-.175-.393-.245-.6l-2.236-.796c-.03-.265-.05-.534-.05-.807s.02-.542.05-.807l2.236-.795c.07-.207.15-.407.246-.601l-1.016-2.139c.336-.423.719-.807 1.143-1.142l2.14 1.017c.193-.096.394-.176.602-.247l.793-2.236c.265-.03.534-.05.806-.05.273 0 .542.02.808.05l.795 2.236c.207.07.407.15.601.246l2.14-1.017c.424.335.807.719 1.142 1.142l-1.017 2.139c.096.194.176.394.246.601l2.236.795c.029.266.049.535.049.808s-.02.542-.05.807l-2.236.796zm-4.714-4.603c-1.657 0-3 1.343-3 3s1.343 3 3 3 3-1.343 3-3-1.343-3-3-3z"/><circle cx="8" cy="8" r="1.5"/></g></svg>
|
||||
|
After Width: | Height: | Size: 927 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g fill="#424242"><path d="M12.714 9.603c-.07.207-.15.407-.246.601l1.017 2.139c-.335.424-.718.807-1.142 1.143l-2.14-1.018c-.193.097-.394.176-.601.247l-.795 2.235c-.265.03-.534.05-.807.05-.272 0-.541-.02-.806-.05l-.795-2.235c-.207-.071-.408-.15-.602-.247l-2.14 1.017c-.424-.336-.807-.719-1.143-1.143l1.017-2.139c-.094-.193-.175-.393-.245-.6l-2.236-.796c-.03-.265-.05-.534-.05-.807s.02-.542.05-.807l2.236-.795c.07-.207.15-.407.246-.601l-1.016-2.139c.336-.423.719-.807 1.143-1.142l2.14 1.017c.193-.096.394-.176.602-.247l.793-2.236c.265-.03.534-.05.806-.05.273 0 .542.02.808.05l.795 2.236c.207.07.407.15.601.246l2.14-1.017c.424.335.807.719 1.142 1.142l-1.017 2.139c.096.194.176.394.246.601l2.236.795c.029.266.049.535.049.808s-.02.542-.05.807l-2.236.796zm-4.714-4.603c-1.657 0-3 1.343-3 3s1.343 3 3 3 3-1.343 3-3-1.343-3-3-3z"/><circle cx="8" cy="8" r="1.5"/></g></svg>
|
||||
|
After Width: | Height: | Size: 927 B |
@@ -0,0 +1,13 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
.monaco-workbench .format-show-extension {
|
||||
background-image: url('configure.svg');
|
||||
}
|
||||
|
||||
.vs-dark .monaco-workbench .format-show-extension,
|
||||
.hc-black .monaco-workbench .format-show-extension {
|
||||
background-image: url('configure-inverse.svg');
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
import { VIEWLET_ID, IExtensionsViewlet } from 'vs/workbench/contrib/extensions/common/extensions';
|
||||
|
||||
export function showExtensionQuery(viewletService: IViewletService, query: string) {
|
||||
return viewletService.openViewlet(VIEWLET_ID, true).then(viewlet => {
|
||||
if (viewlet) {
|
||||
(viewlet as IExtensionsViewlet).search(query);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user