Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/quickAccess/browser/commandsQuickAccess.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { stripIcons } from '../../../../base/common/iconLabels.js';
7
import { IEditor } from '../../../common/editorCommon.js';
8
import { ILocalizedString } from '../../../../nls.js';
9
import { isLocalizedString } from '../../../../platform/action/common/action.js';
10
import { ICommandService } from '../../../../platform/commands/common/commands.js';
11
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
12
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
13
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
14
import { AbstractCommandsQuickAccessProvider, ICommandQuickPick, ICommandsQuickAccessOptions } from '../../../../platform/quickinput/browser/commandsQuickAccess.js';
15
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
16
17
export abstract class AbstractEditorCommandsQuickAccessProvider extends AbstractCommandsQuickAccessProvider {
18
19
constructor(
20
options: ICommandsQuickAccessOptions,
21
instantiationService: IInstantiationService,
22
keybindingService: IKeybindingService,
23
commandService: ICommandService,
24
telemetryService: ITelemetryService,
25
dialogService: IDialogService
26
) {
27
super(options, instantiationService, keybindingService, commandService, telemetryService, dialogService);
28
}
29
30
/**
31
* Subclasses to provide the current active editor control.
32
*/
33
protected abstract activeTextEditorControl: IEditor | undefined;
34
35
protected getCodeEditorCommandPicks(): ICommandQuickPick[] {
36
const activeTextEditorControl = this.activeTextEditorControl;
37
if (!activeTextEditorControl) {
38
return [];
39
}
40
41
const editorCommandPicks: ICommandQuickPick[] = [];
42
for (const editorAction of activeTextEditorControl.getSupportedActions()) {
43
let commandDescription: undefined | ILocalizedString;
44
if (editorAction.metadata?.description) {
45
if (isLocalizedString(editorAction.metadata.description)) {
46
commandDescription = editorAction.metadata.description;
47
} else {
48
commandDescription = { original: editorAction.metadata.description, value: editorAction.metadata.description };
49
}
50
}
51
editorCommandPicks.push({
52
commandId: editorAction.id,
53
commandAlias: editorAction.alias,
54
commandDescription,
55
label: stripIcons(editorAction.label) || editorAction.id,
56
});
57
}
58
59
return editorCommandPicks;
60
}
61
}
62
63