@codingame/monaco-vscode-quickaccess-service-override 1.83.8 → 1.83.10-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ function __decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function __param(paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ }
10
+
11
+ export { __decorate, __param };
package/index.js CHANGED
@@ -1 +1 @@
1
- export { default } from 'vscode/service-override/quickaccess';
1
+ export { default } from './quickaccess.js';
@@ -0,0 +1,8 @@
1
+ var ConfirmResult;
2
+ ( (function(ConfirmResult) {
3
+ ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
4
+ ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
5
+ ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
6
+ })(ConfirmResult || (ConfirmResult = {})));
7
+
8
+ export { ConfirmResult };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-quickaccess-service-override",
3
- "version": "1.83.8",
3
+ "version": "1.83.10-next.0",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,7 +18,7 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@1.83.8",
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.83.10-next.0",
22
22
  "monaco-editor": "0.44.0"
23
23
  }
24
24
  }
package/quickaccess.js ADDED
@@ -0,0 +1,100 @@
1
+ import { __decorate, __param } from './external/tslib/tslib.es6.js';
2
+ import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
3
+ import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
4
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
5
+ import { StandaloneQuickInputService } from 'monaco-editor/esm/vs/editor/standalone/browser/quickInput/standaloneQuickInputService.js';
6
+ import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
7
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
8
+ import { QuickInputService } from './vscode/src/vs/workbench/services/quickinput/browser/quickInputService.js';
9
+ import { ICodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
10
+ import { StandaloneCodeEditor } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneCodeEditor.js';
11
+ import { CommandsQuickAccessProvider } from './vscode/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.js';
12
+ import './vscode/src/vs/workbench/contrib/codeEditor/browser/quickaccess/gotoLineQuickAccess.js';
13
+ import 'vscode/vscode/vs/workbench/contrib/codeEditor/browser/quickaccess/gotoSymbolQuickAccess';
14
+ import './vscode/src/vs/workbench/browser/actions/quickAccessActions.js';
15
+ import './vscode/src/vs/workbench/contrib/quickaccess/browser/quickAccess.contribution.js';
16
+
17
+ let isKeybindingConfigurationVisible = () => {
18
+ return false;
19
+ };
20
+ let shouldUseGlobalPicker = (_activeCodeEditor, _activeCodeEditorStandalone) => {
21
+ return false;
22
+ };
23
+ const original = CommandsQuickAccessProvider.prototype['getCommandPicks'];
24
+ CommandsQuickAccessProvider.prototype['getCommandPicks'] = async function (token) {
25
+ let result = await original.call(this, token);
26
+ if (!isKeybindingConfigurationVisible()) {
27
+ result = ( result.map(picks => ({
28
+ ...picks,
29
+ buttons: picks.buttons?.filter(button => button.tooltip !== 'Configure Keybinding')
30
+ })));
31
+ }
32
+ return result;
33
+ };
34
+ let DelegateQuickInputService = class DelegateQuickInputService {
35
+ constructor(instantiationService) {
36
+ this.instantiationService = instantiationService;
37
+ this.workbenchQuickInputService = instantiationService.createInstance(QuickInputService);
38
+ }
39
+ get activeService() {
40
+ const activeCodeEditor = StandaloneServices.get(ICodeEditorService).getFocusedCodeEditor();
41
+ if (activeCodeEditor == null || shouldUseGlobalPicker(activeCodeEditor, activeCodeEditor instanceof StandaloneCodeEditor)) {
42
+ return this.workbenchQuickInputService;
43
+ }
44
+ this.standaloneQuickInputService ?? (this.standaloneQuickInputService = this.instantiationService.createInstance(StandaloneQuickInputService));
45
+ return this.standaloneQuickInputService;
46
+ }
47
+ get quickAccess() { return this.activeService.quickAccess; }
48
+ get backButton() { return this.activeService.backButton; }
49
+ get onShow() { return this.activeService.onShow; }
50
+ get onHide() { return this.activeService.onHide; }
51
+ createQuickWidget() {
52
+ return this.activeService.createQuickWidget();
53
+ }
54
+ pick(picks, options = {}, token = CancellationToken.None) {
55
+ return this.activeService .pick(picks, options, token);
56
+ }
57
+ input(options, token) {
58
+ return this.activeService.input(options, token);
59
+ }
60
+ createQuickPick() {
61
+ return this.activeService.createQuickPick();
62
+ }
63
+ createInputBox() {
64
+ return this.activeService.createInputBox();
65
+ }
66
+ focus() {
67
+ return this.activeService.focus();
68
+ }
69
+ toggle() {
70
+ return this.activeService.toggle();
71
+ }
72
+ navigate(next, quickNavigate) {
73
+ return this.activeService.navigate(next, quickNavigate);
74
+ }
75
+ accept() {
76
+ return this.activeService.accept();
77
+ }
78
+ back() {
79
+ return this.activeService.back();
80
+ }
81
+ cancel() {
82
+ return this.activeService.cancel();
83
+ }
84
+ };
85
+ DelegateQuickInputService = __decorate([
86
+ ( __param(0, IInstantiationService))
87
+ ], DelegateQuickInputService);
88
+ function getServiceOverride({ isKeybindingConfigurationVisible: _isKeybindingConfigurationVisible, shouldUseGlobalPicker: _shouldUseGlobalPicker } = {}) {
89
+ if (_isKeybindingConfigurationVisible != null) {
90
+ isKeybindingConfigurationVisible = _isKeybindingConfigurationVisible;
91
+ }
92
+ if (_shouldUseGlobalPicker != null) {
93
+ shouldUseGlobalPicker = _shouldUseGlobalPicker;
94
+ }
95
+ return {
96
+ [( IQuickInputService.toString())]: new SyncDescriptor(DelegateQuickInputService, [], true)
97
+ };
98
+ }
99
+
100
+ export { getServiceOverride as default };
@@ -0,0 +1,138 @@
1
+ function countMapFrom(values) {
2
+ const map = ( new Map());
3
+ for (const value of values) {
4
+ map.set(value, (map.get(value) ?? 0) + 1);
5
+ }
6
+ return map;
7
+ }
8
+ class TfIdfCalculator {
9
+ constructor() {
10
+ this.chunkCount = 0;
11
+ this.chunkOccurrences = ( new Map());
12
+ this.documents = ( new Map());
13
+ }
14
+ calculateScores(query, token) {
15
+ const embedding = this.computeEmbedding(query);
16
+ const idfCache = ( new Map());
17
+ const scores = [];
18
+ for (const [key, doc] of this.documents) {
19
+ if (token.isCancellationRequested) {
20
+ return [];
21
+ }
22
+ for (const chunk of doc.chunks) {
23
+ const score = this.computeSimilarityScore(chunk, embedding, idfCache);
24
+ if (score > 0) {
25
+ scores.push({ key, score });
26
+ }
27
+ }
28
+ }
29
+ return scores;
30
+ }
31
+ static termFrequencies(input) {
32
+ return countMapFrom(TfIdfCalculator.splitTerms(input));
33
+ }
34
+ static *splitTerms(input) {
35
+ const normalize = (word) => word.toLowerCase();
36
+ for (const [word] of input.matchAll(/\b\p{Letter}[\p{Letter}\d]{2,}\b/gu)) {
37
+ yield normalize(word);
38
+ const camelParts = word.split(/(?<=[a-z])(?=[A-Z])/g);
39
+ if (camelParts.length > 1) {
40
+ for (const part of camelParts) {
41
+ if (part.length > 2 && /\p{Letter}{3,}/gu.test(part)) {
42
+ yield normalize(part);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ updateDocuments(documents) {
49
+ for (const { key } of documents) {
50
+ this.deleteDocument(key);
51
+ }
52
+ for (const doc of documents) {
53
+ const chunks = [];
54
+ for (const text of doc.textChunks) {
55
+ const tf = TfIdfCalculator.termFrequencies(text);
56
+ for (const term of ( tf.keys())) {
57
+ this.chunkOccurrences.set(term, (this.chunkOccurrences.get(term) ?? 0) + 1);
58
+ }
59
+ chunks.push({ text, tf });
60
+ }
61
+ this.chunkCount += chunks.length;
62
+ this.documents.set(doc.key, { chunks });
63
+ }
64
+ return this;
65
+ }
66
+ deleteDocument(key) {
67
+ const doc = this.documents.get(key);
68
+ if (!doc) {
69
+ return;
70
+ }
71
+ this.documents.delete(key);
72
+ this.chunkCount -= doc.chunks.length;
73
+ for (const chunk of doc.chunks) {
74
+ for (const term of ( chunk.tf.keys())) {
75
+ const currentOccurrences = this.chunkOccurrences.get(term);
76
+ if (typeof currentOccurrences === 'number') {
77
+ const newOccurrences = currentOccurrences - 1;
78
+ if (newOccurrences <= 0) {
79
+ this.chunkOccurrences.delete(term);
80
+ }
81
+ else {
82
+ this.chunkOccurrences.set(term, newOccurrences);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ computeSimilarityScore(chunk, queryEmbedding, idfCache) {
89
+ let sum = 0;
90
+ for (const [term, termTfidf] of Object.entries(queryEmbedding)) {
91
+ const chunkTf = chunk.tf.get(term);
92
+ if (!chunkTf) {
93
+ continue;
94
+ }
95
+ let chunkIdf = idfCache.get(term);
96
+ if (typeof chunkIdf !== 'number') {
97
+ chunkIdf = this.computeIdf(term);
98
+ idfCache.set(term, chunkIdf);
99
+ }
100
+ const chunkTfidf = chunkTf * chunkIdf;
101
+ sum += chunkTfidf * termTfidf;
102
+ }
103
+ return sum;
104
+ }
105
+ computeEmbedding(input) {
106
+ const tf = TfIdfCalculator.termFrequencies(input);
107
+ return this.computeTfidf(tf);
108
+ }
109
+ computeIdf(term) {
110
+ const chunkOccurrences = this.chunkOccurrences.get(term) ?? 0;
111
+ return chunkOccurrences > 0
112
+ ? Math.log((this.chunkCount + 1) / chunkOccurrences)
113
+ : 0;
114
+ }
115
+ computeTfidf(termFrequencies) {
116
+ const embedding = Object.create(null);
117
+ for (const [word, occurrences] of termFrequencies) {
118
+ const idf = this.computeIdf(word);
119
+ if (idf > 0) {
120
+ embedding[word] = occurrences * idf;
121
+ }
122
+ }
123
+ return embedding;
124
+ }
125
+ }
126
+ function normalizeTfIdfScores(scores) {
127
+ const result = scores.slice(0);
128
+ result.sort((a, b) => b.score - a.score);
129
+ const max = result[0]?.score ?? 0;
130
+ if (max > 0) {
131
+ for (const score of result) {
132
+ score.score /= max;
133
+ }
134
+ }
135
+ return result;
136
+ }
137
+
138
+ export { TfIdfCalculator, normalizeTfIdfScores };
@@ -0,0 +1,25 @@
1
+ import { stripIcons } from 'monaco-editor/esm/vs/base/common/iconLabels.js';
2
+ import { AbstractCommandsQuickAccessProvider } from '../../../../platform/quickinput/browser/commandsQuickAccess.js';
3
+
4
+ class AbstractEditorCommandsQuickAccessProvider extends AbstractCommandsQuickAccessProvider {
5
+ constructor(options, instantiationService, keybindingService, commandService, telemetryService, dialogService) {
6
+ super(options, instantiationService, keybindingService, commandService, telemetryService, dialogService);
7
+ }
8
+ getCodeEditorCommandPicks() {
9
+ const activeTextEditorControl = this.activeTextEditorControl;
10
+ if (!activeTextEditorControl) {
11
+ return [];
12
+ }
13
+ const editorCommandPicks = [];
14
+ for (const editorAction of activeTextEditorControl.getSupportedActions()) {
15
+ editorCommandPicks.push({
16
+ commandId: editorAction.id,
17
+ commandAlias: editorAction.alias,
18
+ label: stripIcons(editorAction.label) || editorAction.id,
19
+ });
20
+ }
21
+ return editorCommandPicks;
22
+ }
23
+ }
24
+
25
+ export { AbstractEditorCommandsQuickAccessProvider };
@@ -0,0 +1,333 @@
1
+ import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
2
+ import { toErrorMessage } from 'monaco-editor/esm/vs/base/common/errorMessage.js';
3
+ import { isCancellationError } from 'monaco-editor/esm/vs/base/common/errors.js';
4
+ import { or, matchesPrefix, matchesWords, matchesContiguousSubString } from 'monaco-editor/esm/vs/base/common/filters.js';
5
+ import { createSingleCallFunction } from 'monaco-editor/esm/vs/base/common/functional.js';
6
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
7
+ import { LRUCache } from 'monaco-editor/esm/vs/base/common/map.js';
8
+ import { normalizeTfIdfScores, TfIdfCalculator } from '../../../base/common/tfIdf.js';
9
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
10
+ import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
11
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
12
+ import '../../../../../../override/vs/platform/dialogs/common/dialogs.js';
13
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
14
+ import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/common/keybinding.js';
15
+ import { PickerQuickAccessProvider } from 'vscode/vscode/vs/platform/quickinput/browser/pickerQuickAccess';
16
+ import { IStorageService } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
17
+ import { ITelemetryService } from 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
18
+ import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
19
+
20
+ var AbstractCommandsQuickAccessProvider_1, CommandsHistory_1;
21
+ let AbstractCommandsQuickAccessProvider = class AbstractCommandsQuickAccessProvider extends PickerQuickAccessProvider {
22
+ static { AbstractCommandsQuickAccessProvider_1 = this; }
23
+ static { this.PREFIX = '>'; }
24
+ static { this.TFIDF_THRESHOLD = 0.5; }
25
+ static { this.TFIDF_MAX_RESULTS = 5; }
26
+ static { this.WORD_FILTER = or(matchesPrefix, matchesWords, matchesContiguousSubString); }
27
+ constructor(options, instantiationService, keybindingService, commandService, telemetryService, dialogService) {
28
+ super(AbstractCommandsQuickAccessProvider_1.PREFIX, options);
29
+ this.instantiationService = instantiationService;
30
+ this.keybindingService = keybindingService;
31
+ this.commandService = commandService;
32
+ this.telemetryService = telemetryService;
33
+ this.dialogService = dialogService;
34
+ this.commandsHistory = this._register(this.instantiationService.createInstance(CommandsHistory));
35
+ this.options = options;
36
+ }
37
+ async _getPicks(filter, _disposables, token, runOptions) {
38
+ const allCommandPicks = await this.getCommandPicks(token);
39
+ if (token.isCancellationRequested) {
40
+ return [];
41
+ }
42
+ const runTfidf = createSingleCallFunction(() => {
43
+ const tfidf = ( new TfIdfCalculator());
44
+ tfidf.updateDocuments(( allCommandPicks.map(commandPick => ({
45
+ key: commandPick.commandId,
46
+ textChunks: [commandPick.label + (commandPick.commandAlias ? ` ${commandPick.commandAlias}` : '')]
47
+ }))));
48
+ const result = tfidf.calculateScores(filter, token);
49
+ return normalizeTfIdfScores(result)
50
+ .filter(score => score.score > AbstractCommandsQuickAccessProvider_1.TFIDF_THRESHOLD)
51
+ .slice(0, AbstractCommandsQuickAccessProvider_1.TFIDF_MAX_RESULTS);
52
+ });
53
+ const filteredCommandPicks = [];
54
+ for (const commandPick of allCommandPicks) {
55
+ const labelHighlights = AbstractCommandsQuickAccessProvider_1.WORD_FILTER(filter, commandPick.label) ?? undefined;
56
+ const aliasHighlights = commandPick.commandAlias ? AbstractCommandsQuickAccessProvider_1.WORD_FILTER(filter, commandPick.commandAlias) ?? undefined : undefined;
57
+ if (labelHighlights || aliasHighlights) {
58
+ commandPick.highlights = {
59
+ label: labelHighlights,
60
+ detail: this.options.showAlias ? aliasHighlights : undefined
61
+ };
62
+ filteredCommandPicks.push(commandPick);
63
+ }
64
+ else if (filter === commandPick.commandId) {
65
+ filteredCommandPicks.push(commandPick);
66
+ }
67
+ else if (filter.length >= 3) {
68
+ const tfidf = runTfidf();
69
+ if (token.isCancellationRequested) {
70
+ return [];
71
+ }
72
+ const tfidfScore = tfidf.find(score => score.key === commandPick.commandId);
73
+ if (tfidfScore) {
74
+ commandPick.tfIdfScore = tfidfScore.score;
75
+ filteredCommandPicks.push(commandPick);
76
+ }
77
+ }
78
+ }
79
+ const mapLabelToCommand = ( new Map());
80
+ for (const commandPick of filteredCommandPicks) {
81
+ const existingCommandForLabel = mapLabelToCommand.get(commandPick.label);
82
+ if (existingCommandForLabel) {
83
+ commandPick.description = commandPick.commandId;
84
+ existingCommandForLabel.description = existingCommandForLabel.commandId;
85
+ }
86
+ else {
87
+ mapLabelToCommand.set(commandPick.label, commandPick);
88
+ }
89
+ }
90
+ filteredCommandPicks.sort((commandPickA, commandPickB) => {
91
+ if (commandPickA.tfIdfScore && commandPickB.tfIdfScore) {
92
+ if (commandPickA.tfIdfScore === commandPickB.tfIdfScore) {
93
+ return commandPickA.label.localeCompare(commandPickB.label);
94
+ }
95
+ return commandPickB.tfIdfScore - commandPickA.tfIdfScore;
96
+ }
97
+ else if (commandPickA.tfIdfScore) {
98
+ return 1;
99
+ }
100
+ else if (commandPickB.tfIdfScore) {
101
+ return -1;
102
+ }
103
+ const commandACounter = this.commandsHistory.peek(commandPickA.commandId);
104
+ const commandBCounter = this.commandsHistory.peek(commandPickB.commandId);
105
+ if (commandACounter && commandBCounter) {
106
+ return commandACounter > commandBCounter ? -1 : 1;
107
+ }
108
+ if (commandACounter) {
109
+ return -1;
110
+ }
111
+ if (commandBCounter) {
112
+ return 1;
113
+ }
114
+ if (this.options.suggestedCommandIds) {
115
+ const commandASuggestion = ( this.options.suggestedCommandIds.has(commandPickA.commandId));
116
+ const commandBSuggestion = ( this.options.suggestedCommandIds.has(commandPickB.commandId));
117
+ if (commandASuggestion && commandBSuggestion) {
118
+ return 0;
119
+ }
120
+ if (commandASuggestion) {
121
+ return -1;
122
+ }
123
+ if (commandBSuggestion) {
124
+ return 1;
125
+ }
126
+ }
127
+ return commandPickA.label.localeCompare(commandPickB.label);
128
+ });
129
+ const commandPicks = [];
130
+ let addOtherSeparator = false;
131
+ let addSuggestedSeparator = true;
132
+ let addCommonlyUsedSeparator = !!this.options.suggestedCommandIds;
133
+ for (let i = 0; i < filteredCommandPicks.length; i++) {
134
+ const commandPick = filteredCommandPicks[i];
135
+ if (i === 0 && this.commandsHistory.peek(commandPick.commandId)) {
136
+ commandPicks.push({ type: 'separator', label: ( localizeWithPath(
137
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
138
+ 'recentlyUsed',
139
+ "recently used"
140
+ )) });
141
+ addOtherSeparator = true;
142
+ }
143
+ if (addSuggestedSeparator && commandPick.tfIdfScore !== undefined) {
144
+ commandPicks.push({ type: 'separator', label: ( localizeWithPath(
145
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
146
+ 'suggested',
147
+ "similar commands"
148
+ )) });
149
+ addSuggestedSeparator = false;
150
+ }
151
+ if (addCommonlyUsedSeparator && commandPick.tfIdfScore === undefined && !this.commandsHistory.peek(commandPick.commandId) && this.options.suggestedCommandIds?.has(commandPick.commandId)) {
152
+ commandPicks.push({ type: 'separator', label: ( localizeWithPath(
153
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
154
+ 'commonlyUsed',
155
+ "commonly used"
156
+ )) });
157
+ addOtherSeparator = true;
158
+ addCommonlyUsedSeparator = false;
159
+ }
160
+ if (addOtherSeparator && commandPick.tfIdfScore === undefined && !this.commandsHistory.peek(commandPick.commandId) && !this.options.suggestedCommandIds?.has(commandPick.commandId)) {
161
+ commandPicks.push({ type: 'separator', label: ( localizeWithPath(
162
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
163
+ 'morecCommands',
164
+ "other commands"
165
+ )) });
166
+ addOtherSeparator = false;
167
+ }
168
+ commandPicks.push(this.toCommandPick(commandPick, runOptions));
169
+ }
170
+ if (!this.hasAdditionalCommandPicks(filter, token)) {
171
+ return commandPicks;
172
+ }
173
+ return {
174
+ picks: commandPicks,
175
+ additionalPicks: (async () => {
176
+ const additionalCommandPicks = await this.getAdditionalCommandPicks(allCommandPicks, filteredCommandPicks, filter, token);
177
+ if (token.isCancellationRequested) {
178
+ return [];
179
+ }
180
+ const commandPicks = ( additionalCommandPicks.map(commandPick => this.toCommandPick(commandPick, runOptions)));
181
+ if (addSuggestedSeparator && commandPicks[0]?.type !== 'separator') {
182
+ commandPicks.unshift({ type: 'separator', label: ( localizeWithPath(
183
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
184
+ 'suggested',
185
+ "similar commands"
186
+ )) });
187
+ }
188
+ return commandPicks;
189
+ })()
190
+ };
191
+ }
192
+ toCommandPick(commandPick, runOptions) {
193
+ if (commandPick.type === 'separator') {
194
+ return commandPick;
195
+ }
196
+ const keybinding = this.keybindingService.lookupKeybinding(commandPick.commandId);
197
+ const ariaLabel = keybinding ?
198
+ ( localizeWithPath(
199
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
200
+ 'commandPickAriaLabelWithKeybinding',
201
+ "{0}, {1}",
202
+ commandPick.label,
203
+ keybinding.getAriaLabel()
204
+ )) :
205
+ commandPick.label;
206
+ return {
207
+ ...commandPick,
208
+ ariaLabel,
209
+ detail: this.options.showAlias && commandPick.commandAlias !== commandPick.label ? commandPick.commandAlias : undefined,
210
+ keybinding,
211
+ accept: async () => {
212
+ this.commandsHistory.push(commandPick.commandId);
213
+ this.telemetryService.publicLog2('workbenchActionExecuted', {
214
+ id: commandPick.commandId,
215
+ from: runOptions?.from ?? 'quick open'
216
+ });
217
+ try {
218
+ commandPick.args?.length
219
+ ? await this.commandService.executeCommand(commandPick.commandId, ...commandPick.args)
220
+ : await this.commandService.executeCommand(commandPick.commandId);
221
+ }
222
+ catch (error) {
223
+ if (!isCancellationError(error)) {
224
+ this.dialogService.error(( localizeWithPath(
225
+ 'vs/platform/quickinput/browser/commandsQuickAccess',
226
+ 'canNotRun',
227
+ "Command '{0}' resulted in an error",
228
+ commandPick.label
229
+ )), toErrorMessage(error));
230
+ }
231
+ }
232
+ }
233
+ };
234
+ }
235
+ };
236
+ AbstractCommandsQuickAccessProvider = AbstractCommandsQuickAccessProvider_1 = ( __decorate([
237
+ ( __param(1, IInstantiationService)),
238
+ ( __param(2, IKeybindingService)),
239
+ ( __param(3, ICommandService)),
240
+ ( __param(4, ITelemetryService)),
241
+ ( __param(5, IDialogService))
242
+ ], AbstractCommandsQuickAccessProvider));
243
+ let CommandsHistory = class CommandsHistory extends Disposable {
244
+ static { CommandsHistory_1 = this; }
245
+ static { this.DEFAULT_COMMANDS_HISTORY_LENGTH = 50; }
246
+ static { this.PREF_KEY_CACHE = 'commandPalette.mru.cache'; }
247
+ static { this.PREF_KEY_COUNTER = 'commandPalette.mru.counter'; }
248
+ static { this.counter = 1; }
249
+ constructor(storageService, configurationService) {
250
+ super();
251
+ this.storageService = storageService;
252
+ this.configurationService = configurationService;
253
+ this.configuredCommandsHistoryLength = 0;
254
+ this.updateConfiguration();
255
+ this.load();
256
+ this.registerListeners();
257
+ }
258
+ registerListeners() {
259
+ this._register(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration(e)));
260
+ }
261
+ updateConfiguration(e) {
262
+ if (e && !e.affectsConfiguration('workbench.commandPalette.history')) {
263
+ return;
264
+ }
265
+ this.configuredCommandsHistoryLength = CommandsHistory_1.getConfiguredCommandHistoryLength(this.configurationService);
266
+ if (CommandsHistory_1.cache && CommandsHistory_1.cache.limit !== this.configuredCommandsHistoryLength) {
267
+ CommandsHistory_1.cache.limit = this.configuredCommandsHistoryLength;
268
+ CommandsHistory_1.saveState(this.storageService);
269
+ }
270
+ }
271
+ load() {
272
+ const raw = this.storageService.get(CommandsHistory_1.PREF_KEY_CACHE, 0 );
273
+ let serializedCache;
274
+ if (raw) {
275
+ try {
276
+ serializedCache = JSON.parse(raw);
277
+ }
278
+ catch (error) {
279
+ }
280
+ }
281
+ const cache = CommandsHistory_1.cache = ( new LRUCache(this.configuredCommandsHistoryLength, 1));
282
+ if (serializedCache) {
283
+ let entries;
284
+ if (serializedCache.usesLRU) {
285
+ entries = serializedCache.entries;
286
+ }
287
+ else {
288
+ entries = serializedCache.entries.sort((a, b) => a.value - b.value);
289
+ }
290
+ entries.forEach(entry => cache.set(entry.key, entry.value));
291
+ }
292
+ CommandsHistory_1.counter = this.storageService.getNumber(CommandsHistory_1.PREF_KEY_COUNTER, 0 , CommandsHistory_1.counter);
293
+ }
294
+ push(commandId) {
295
+ if (!CommandsHistory_1.cache) {
296
+ return;
297
+ }
298
+ CommandsHistory_1.cache.set(commandId, CommandsHistory_1.counter++);
299
+ CommandsHistory_1.saveState(this.storageService);
300
+ }
301
+ peek(commandId) {
302
+ return CommandsHistory_1.cache?.peek(commandId);
303
+ }
304
+ static saveState(storageService) {
305
+ if (!CommandsHistory_1.cache) {
306
+ return;
307
+ }
308
+ const serializedCache = { usesLRU: true, entries: [] };
309
+ CommandsHistory_1.cache.forEach((value, key) => serializedCache.entries.push({ key, value }));
310
+ storageService.store(CommandsHistory_1.PREF_KEY_CACHE, JSON.stringify(serializedCache), 0 , 0 );
311
+ storageService.store(CommandsHistory_1.PREF_KEY_COUNTER, CommandsHistory_1.counter, 0 , 0 );
312
+ }
313
+ static getConfiguredCommandHistoryLength(configurationService) {
314
+ const config = configurationService.getValue();
315
+ const configuredCommandHistoryLength = config.workbench?.commandPalette?.history;
316
+ if (typeof configuredCommandHistoryLength === 'number') {
317
+ return configuredCommandHistoryLength;
318
+ }
319
+ return CommandsHistory_1.DEFAULT_COMMANDS_HISTORY_LENGTH;
320
+ }
321
+ static clearHistory(configurationService, storageService) {
322
+ const commandHistoryLength = CommandsHistory_1.getConfiguredCommandHistoryLength(configurationService);
323
+ CommandsHistory_1.cache = ( new LRUCache(commandHistoryLength));
324
+ CommandsHistory_1.counter = 1;
325
+ CommandsHistory_1.saveState(storageService);
326
+ }
327
+ };
328
+ CommandsHistory = CommandsHistory_1 = ( __decorate([
329
+ ( __param(0, IStorageService)),
330
+ ( __param(1, IConfigurationService))
331
+ ], CommandsHistory));
332
+
333
+ export { AbstractCommandsQuickAccessProvider, CommandsHistory };