@codingame/monaco-vscode-quickaccess-service-override 4.1.0 → 4.1.1
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.
- package/override/vs/platform/dialogs/common/dialogs.js +10 -0
- package/package.json +2 -2
- package/quickaccess.js +6 -6
- package/vscode/src/vs/editor/contrib/quickAccess/browser/commandsQuickAccess.js +25 -0
- package/vscode/src/vs/platform/quickinput/browser/commandsQuickAccess.js +357 -0
- package/vscode/src/vs/platform/quickinput/browser/helpQuickAccess.js +67 -0
- package/vscode/src/vs/workbench/browser/actions/quickAccessActions.js +228 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/quickaccess/gotoLineQuickAccess.js +88 -0
- package/vscode/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.js +295 -0
- package/vscode/src/vs/workbench/contrib/quickaccess/browser/quickAccess.contribution.js +168 -0
- package/vscode/src/vs/workbench/contrib/quickaccess/browser/viewQuickAccess.js +266 -0
- package/vscode/src/vs/workbench/contrib/url/browser/externalUriResolver.js +28 -0
- package/vscode/src/vs/workbench/contrib/url/browser/trustedDomains.js +200 -0
- package/vscode/src/vs/workbench/contrib/url/browser/trustedDomainsFileSystemProvider.js +137 -0
- package/vscode/src/vs/workbench/contrib/url/browser/trustedDomainsValidator.js +205 -0
- package/vscode/src/vs/workbench/contrib/url/browser/url.contribution.js +67 -0
- package/vscode/src/vs/workbench/services/quickinput/browser/quickInputService.js +39 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AbstractDialogHandler, IDialogService, IFileDialogService, getFileNamesMessage } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
|
|
2
|
+
|
|
3
|
+
var ConfirmResult;
|
|
4
|
+
( (function(ConfirmResult) {
|
|
5
|
+
ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
|
|
6
|
+
ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
|
|
7
|
+
ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
|
|
8
|
+
})(ConfirmResult || (ConfirmResult = {})));
|
|
9
|
+
|
|
10
|
+
export { ConfirmResult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-quickaccess-service-override",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.1.
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.1.1"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/quickaccess.js
CHANGED
|
@@ -5,15 +5,15 @@ import { CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
|
|
|
5
5
|
import { StandaloneQuickInputService } from 'vscode/vscode/vs/editor/standalone/browser/quickInput/standaloneQuickInputService';
|
|
6
6
|
import { StandaloneServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
|
|
7
7
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
8
|
-
import { QuickInputService } from 'vscode/
|
|
8
|
+
import { QuickInputService } from './vscode/src/vs/workbench/services/quickinput/browser/quickInputService.js';
|
|
9
9
|
import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
|
|
10
10
|
import { StandaloneCodeEditor } from 'vscode/vscode/vs/editor/standalone/browser/standaloneCodeEditor';
|
|
11
|
-
import { CommandsQuickAccessProvider } from 'vscode/
|
|
12
|
-
import 'vscode/
|
|
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
13
|
import 'vscode/vscode/vs/workbench/contrib/codeEditor/browser/quickaccess/gotoSymbolQuickAccess';
|
|
14
|
-
import 'vscode/
|
|
15
|
-
import 'vscode/
|
|
16
|
-
import 'vscode/
|
|
14
|
+
import './vscode/src/vs/workbench/browser/actions/quickAccessActions.js';
|
|
15
|
+
import './vscode/src/vs/workbench/contrib/quickaccess/browser/quickAccess.contribution.js';
|
|
16
|
+
import './vscode/src/vs/workbench/contrib/url/browser/url.contribution.js';
|
|
17
17
|
import 'vscode/vscode/vs/workbench/browser/workbench.contribution';
|
|
18
18
|
|
|
19
19
|
let isKeybindingConfigurationVisible = () => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { stripIcons } from 'vscode/vscode/vs/base/common/iconLabels';
|
|
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,357 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { toErrorMessage } from 'vscode/vscode/vs/base/common/errorMessage';
|
|
3
|
+
import { isCancellationError } from 'vscode/vscode/vs/base/common/errors';
|
|
4
|
+
import { or, matchesPrefix, matchesWords, matchesContiguousSubString } from 'vscode/vscode/vs/base/common/filters';
|
|
5
|
+
import { createSingleCallFunction } from 'vscode/vscode/vs/base/common/functional';
|
|
6
|
+
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
7
|
+
import { LRUCache } from 'vscode/vscode/vs/base/common/map';
|
|
8
|
+
import { TfIdfCalculator, normalizeTfIdfScores } from 'vscode/vscode/vs/base/common/tfIdf';
|
|
9
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
10
|
+
import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
|
|
11
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
12
|
+
import '../../../../../../override/vs/platform/dialogs/common/dialogs.js';
|
|
13
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
14
|
+
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
|
|
15
|
+
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
16
|
+
import { PickerQuickAccessProvider } from 'vscode/vscode/vs/platform/quickinput/browser/pickerQuickAccess';
|
|
17
|
+
import { WillSaveStateReason, IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
18
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
19
|
+
import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
|
|
20
|
+
|
|
21
|
+
var AbstractCommandsQuickAccessProvider_1, CommandsHistory_1;
|
|
22
|
+
let AbstractCommandsQuickAccessProvider = class AbstractCommandsQuickAccessProvider extends PickerQuickAccessProvider {
|
|
23
|
+
static { AbstractCommandsQuickAccessProvider_1 = this; }
|
|
24
|
+
static { this.PREFIX = '>'; }
|
|
25
|
+
static { this.TFIDF_THRESHOLD = 0.5; }
|
|
26
|
+
static { this.TFIDF_MAX_RESULTS = 5; }
|
|
27
|
+
static { this.WORD_FILTER = or(matchesPrefix, matchesWords, matchesContiguousSubString); }
|
|
28
|
+
constructor(options, instantiationService, keybindingService, commandService, telemetryService, dialogService) {
|
|
29
|
+
super(AbstractCommandsQuickAccessProvider_1.PREFIX, options);
|
|
30
|
+
this.instantiationService = instantiationService;
|
|
31
|
+
this.keybindingService = keybindingService;
|
|
32
|
+
this.commandService = commandService;
|
|
33
|
+
this.telemetryService = telemetryService;
|
|
34
|
+
this.dialogService = dialogService;
|
|
35
|
+
this.commandsHistory = this._register(this.instantiationService.createInstance(CommandsHistory));
|
|
36
|
+
this.options = options;
|
|
37
|
+
}
|
|
38
|
+
async _getPicks(filter, _disposables, token, runOptions) {
|
|
39
|
+
const allCommandPicks = await this.getCommandPicks(token);
|
|
40
|
+
if (token.isCancellationRequested) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const runTfidf = createSingleCallFunction(() => {
|
|
44
|
+
const tfidf = ( new TfIdfCalculator());
|
|
45
|
+
tfidf.updateDocuments(( allCommandPicks.map(commandPick => ({
|
|
46
|
+
key: commandPick.commandId,
|
|
47
|
+
textChunks: [this.getTfIdfChunk(commandPick)]
|
|
48
|
+
}))));
|
|
49
|
+
const result = tfidf.calculateScores(filter, token);
|
|
50
|
+
return normalizeTfIdfScores(result)
|
|
51
|
+
.filter(score => score.score > AbstractCommandsQuickAccessProvider_1.TFIDF_THRESHOLD)
|
|
52
|
+
.slice(0, AbstractCommandsQuickAccessProvider_1.TFIDF_MAX_RESULTS);
|
|
53
|
+
});
|
|
54
|
+
const filteredCommandPicks = [];
|
|
55
|
+
for (const commandPick of allCommandPicks) {
|
|
56
|
+
const labelHighlights = AbstractCommandsQuickAccessProvider_1.WORD_FILTER(filter, commandPick.label) ?? undefined;
|
|
57
|
+
const aliasHighlights = commandPick.commandAlias ? AbstractCommandsQuickAccessProvider_1.WORD_FILTER(filter, commandPick.commandAlias) ?? undefined : undefined;
|
|
58
|
+
if (labelHighlights || aliasHighlights) {
|
|
59
|
+
commandPick.highlights = {
|
|
60
|
+
label: labelHighlights,
|
|
61
|
+
detail: this.options.showAlias ? aliasHighlights : undefined
|
|
62
|
+
};
|
|
63
|
+
filteredCommandPicks.push(commandPick);
|
|
64
|
+
}
|
|
65
|
+
else if (filter === commandPick.commandId) {
|
|
66
|
+
filteredCommandPicks.push(commandPick);
|
|
67
|
+
}
|
|
68
|
+
else if (filter.length >= 3) {
|
|
69
|
+
const tfidf = runTfidf();
|
|
70
|
+
if (token.isCancellationRequested) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const tfidfScore = tfidf.find(score => score.key === commandPick.commandId);
|
|
74
|
+
if (tfidfScore) {
|
|
75
|
+
commandPick.tfIdfScore = tfidfScore.score;
|
|
76
|
+
filteredCommandPicks.push(commandPick);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const mapLabelToCommand = ( new Map());
|
|
81
|
+
for (const commandPick of filteredCommandPicks) {
|
|
82
|
+
const existingCommandForLabel = mapLabelToCommand.get(commandPick.label);
|
|
83
|
+
if (existingCommandForLabel) {
|
|
84
|
+
commandPick.description = commandPick.commandId;
|
|
85
|
+
existingCommandForLabel.description = existingCommandForLabel.commandId;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
mapLabelToCommand.set(commandPick.label, commandPick);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
filteredCommandPicks.sort((commandPickA, commandPickB) => {
|
|
92
|
+
if (commandPickA.tfIdfScore && commandPickB.tfIdfScore) {
|
|
93
|
+
if (commandPickA.tfIdfScore === commandPickB.tfIdfScore) {
|
|
94
|
+
return commandPickA.label.localeCompare(commandPickB.label);
|
|
95
|
+
}
|
|
96
|
+
return commandPickB.tfIdfScore - commandPickA.tfIdfScore;
|
|
97
|
+
}
|
|
98
|
+
else if (commandPickA.tfIdfScore) {
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
else if (commandPickB.tfIdfScore) {
|
|
102
|
+
return -1;
|
|
103
|
+
}
|
|
104
|
+
const commandACounter = this.commandsHistory.peek(commandPickA.commandId);
|
|
105
|
+
const commandBCounter = this.commandsHistory.peek(commandPickB.commandId);
|
|
106
|
+
if (commandACounter && commandBCounter) {
|
|
107
|
+
return commandACounter > commandBCounter ? -1 : 1;
|
|
108
|
+
}
|
|
109
|
+
if (commandACounter) {
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
if (commandBCounter) {
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
if (this.options.suggestedCommandIds) {
|
|
116
|
+
const commandASuggestion = ( this.options.suggestedCommandIds.has(commandPickA.commandId));
|
|
117
|
+
const commandBSuggestion = ( this.options.suggestedCommandIds.has(commandPickB.commandId));
|
|
118
|
+
if (commandASuggestion && commandBSuggestion) {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
if (commandASuggestion) {
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
124
|
+
if (commandBSuggestion) {
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return commandPickA.label.localeCompare(commandPickB.label);
|
|
129
|
+
});
|
|
130
|
+
const commandPicks = [];
|
|
131
|
+
let addOtherSeparator = false;
|
|
132
|
+
let addSuggestedSeparator = true;
|
|
133
|
+
let addCommonlyUsedSeparator = !!this.options.suggestedCommandIds;
|
|
134
|
+
for (let i = 0; i < filteredCommandPicks.length; i++) {
|
|
135
|
+
const commandPick = filteredCommandPicks[i];
|
|
136
|
+
if (i === 0 && this.commandsHistory.peek(commandPick.commandId)) {
|
|
137
|
+
commandPicks.push({ type: 'separator', label: ( localizeWithPath(
|
|
138
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
139
|
+
'recentlyUsed',
|
|
140
|
+
"recently used"
|
|
141
|
+
)) });
|
|
142
|
+
addOtherSeparator = true;
|
|
143
|
+
}
|
|
144
|
+
if (addSuggestedSeparator && commandPick.tfIdfScore !== undefined) {
|
|
145
|
+
commandPicks.push({ type: 'separator', label: ( localizeWithPath(
|
|
146
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
147
|
+
'suggested',
|
|
148
|
+
"similar commands"
|
|
149
|
+
)) });
|
|
150
|
+
addSuggestedSeparator = false;
|
|
151
|
+
}
|
|
152
|
+
if (addCommonlyUsedSeparator && commandPick.tfIdfScore === undefined && !this.commandsHistory.peek(commandPick.commandId) && this.options.suggestedCommandIds?.has(commandPick.commandId)) {
|
|
153
|
+
commandPicks.push({ type: 'separator', label: ( localizeWithPath(
|
|
154
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
155
|
+
'commonlyUsed',
|
|
156
|
+
"commonly used"
|
|
157
|
+
)) });
|
|
158
|
+
addOtherSeparator = true;
|
|
159
|
+
addCommonlyUsedSeparator = false;
|
|
160
|
+
}
|
|
161
|
+
if (addOtherSeparator && commandPick.tfIdfScore === undefined && !this.commandsHistory.peek(commandPick.commandId) && !this.options.suggestedCommandIds?.has(commandPick.commandId)) {
|
|
162
|
+
commandPicks.push({ type: 'separator', label: ( localizeWithPath(
|
|
163
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
164
|
+
'morecCommands',
|
|
165
|
+
"other commands"
|
|
166
|
+
)) });
|
|
167
|
+
addOtherSeparator = false;
|
|
168
|
+
}
|
|
169
|
+
commandPicks.push(this.toCommandPick(commandPick, runOptions));
|
|
170
|
+
}
|
|
171
|
+
if (!this.hasAdditionalCommandPicks(filter, token)) {
|
|
172
|
+
return commandPicks;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
picks: commandPicks,
|
|
176
|
+
additionalPicks: (async () => {
|
|
177
|
+
const additionalCommandPicks = await this.getAdditionalCommandPicks(allCommandPicks, filteredCommandPicks, filter, token);
|
|
178
|
+
if (token.isCancellationRequested) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
const commandPicks = ( additionalCommandPicks.map(commandPick => this.toCommandPick(commandPick, runOptions)));
|
|
182
|
+
if (addSuggestedSeparator && commandPicks[0]?.type !== 'separator') {
|
|
183
|
+
commandPicks.unshift({ type: 'separator', label: ( localizeWithPath(
|
|
184
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
185
|
+
'suggested',
|
|
186
|
+
"similar commands"
|
|
187
|
+
)) });
|
|
188
|
+
}
|
|
189
|
+
return commandPicks;
|
|
190
|
+
})()
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
toCommandPick(commandPick, runOptions) {
|
|
194
|
+
if (commandPick.type === 'separator') {
|
|
195
|
+
return commandPick;
|
|
196
|
+
}
|
|
197
|
+
const keybinding = this.keybindingService.lookupKeybinding(commandPick.commandId);
|
|
198
|
+
const ariaLabel = keybinding ?
|
|
199
|
+
( localizeWithPath(
|
|
200
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
201
|
+
'commandPickAriaLabelWithKeybinding',
|
|
202
|
+
"{0}, {1}",
|
|
203
|
+
commandPick.label,
|
|
204
|
+
keybinding.getAriaLabel()
|
|
205
|
+
)) :
|
|
206
|
+
commandPick.label;
|
|
207
|
+
return {
|
|
208
|
+
...commandPick,
|
|
209
|
+
ariaLabel,
|
|
210
|
+
detail: this.options.showAlias && commandPick.commandAlias !== commandPick.label ? commandPick.commandAlias : undefined,
|
|
211
|
+
keybinding,
|
|
212
|
+
accept: async () => {
|
|
213
|
+
this.commandsHistory.push(commandPick.commandId);
|
|
214
|
+
this.telemetryService.publicLog2('workbenchActionExecuted', {
|
|
215
|
+
id: commandPick.commandId,
|
|
216
|
+
from: runOptions?.from ?? 'quick open'
|
|
217
|
+
});
|
|
218
|
+
try {
|
|
219
|
+
commandPick.args?.length
|
|
220
|
+
? await this.commandService.executeCommand(commandPick.commandId, ...commandPick.args)
|
|
221
|
+
: await this.commandService.executeCommand(commandPick.commandId);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
if (!isCancellationError(error)) {
|
|
225
|
+
this.dialogService.error(( localizeWithPath(
|
|
226
|
+
'vs/platform/quickinput/browser/commandsQuickAccess',
|
|
227
|
+
'canNotRun',
|
|
228
|
+
"Command '{0}' resulted in an error",
|
|
229
|
+
commandPick.label
|
|
230
|
+
)), toErrorMessage(error));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
getTfIdfChunk({ label, commandAlias, commandDescription }) {
|
|
237
|
+
let chunk = label;
|
|
238
|
+
if (commandAlias && commandAlias !== label) {
|
|
239
|
+
chunk += ` - ${commandAlias}`;
|
|
240
|
+
}
|
|
241
|
+
if (commandDescription && commandDescription.value !== label) {
|
|
242
|
+
chunk += ` - ${commandDescription.value === commandDescription.original ? commandDescription.value : `${commandDescription.value} (${commandDescription.original})`}`;
|
|
243
|
+
}
|
|
244
|
+
return chunk;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
AbstractCommandsQuickAccessProvider = AbstractCommandsQuickAccessProvider_1 = ( __decorate([
|
|
248
|
+
( __param(1, IInstantiationService)),
|
|
249
|
+
( __param(2, IKeybindingService)),
|
|
250
|
+
( __param(3, ICommandService)),
|
|
251
|
+
( __param(4, ITelemetryService)),
|
|
252
|
+
( __param(5, IDialogService))
|
|
253
|
+
], AbstractCommandsQuickAccessProvider));
|
|
254
|
+
let CommandsHistory = class CommandsHistory extends Disposable {
|
|
255
|
+
static { CommandsHistory_1 = this; }
|
|
256
|
+
static { this.DEFAULT_COMMANDS_HISTORY_LENGTH = 50; }
|
|
257
|
+
static { this.PREF_KEY_CACHE = 'commandPalette.mru.cache'; }
|
|
258
|
+
static { this.PREF_KEY_COUNTER = 'commandPalette.mru.counter'; }
|
|
259
|
+
static { this.counter = 1; }
|
|
260
|
+
static { this.hasChanges = false; }
|
|
261
|
+
constructor(storageService, configurationService, logService) {
|
|
262
|
+
super();
|
|
263
|
+
this.storageService = storageService;
|
|
264
|
+
this.configurationService = configurationService;
|
|
265
|
+
this.logService = logService;
|
|
266
|
+
this.configuredCommandsHistoryLength = 0;
|
|
267
|
+
this.updateConfiguration();
|
|
268
|
+
this.load();
|
|
269
|
+
this.registerListeners();
|
|
270
|
+
}
|
|
271
|
+
registerListeners() {
|
|
272
|
+
this._register(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration(e)));
|
|
273
|
+
this._register(this.storageService.onWillSaveState(e => {
|
|
274
|
+
if (e.reason === WillSaveStateReason.SHUTDOWN) {
|
|
275
|
+
this.saveState();
|
|
276
|
+
}
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
updateConfiguration(e) {
|
|
280
|
+
if (e && !e.affectsConfiguration('workbench.commandPalette.history')) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this.configuredCommandsHistoryLength = CommandsHistory_1.getConfiguredCommandHistoryLength(this.configurationService);
|
|
284
|
+
if (CommandsHistory_1.cache && CommandsHistory_1.cache.limit !== this.configuredCommandsHistoryLength) {
|
|
285
|
+
CommandsHistory_1.cache.limit = this.configuredCommandsHistoryLength;
|
|
286
|
+
CommandsHistory_1.hasChanges = true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
load() {
|
|
290
|
+
const raw = this.storageService.get(CommandsHistory_1.PREF_KEY_CACHE, 0 );
|
|
291
|
+
let serializedCache;
|
|
292
|
+
if (raw) {
|
|
293
|
+
try {
|
|
294
|
+
serializedCache = JSON.parse(raw);
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
this.logService.error(`[CommandsHistory] invalid data: ${error}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const cache = CommandsHistory_1.cache = ( new LRUCache(this.configuredCommandsHistoryLength, 1));
|
|
301
|
+
if (serializedCache) {
|
|
302
|
+
let entries;
|
|
303
|
+
if (serializedCache.usesLRU) {
|
|
304
|
+
entries = serializedCache.entries;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
entries = serializedCache.entries.sort((a, b) => a.value - b.value);
|
|
308
|
+
}
|
|
309
|
+
entries.forEach(entry => cache.set(entry.key, entry.value));
|
|
310
|
+
}
|
|
311
|
+
CommandsHistory_1.counter = this.storageService.getNumber(CommandsHistory_1.PREF_KEY_COUNTER, 0 , CommandsHistory_1.counter);
|
|
312
|
+
}
|
|
313
|
+
push(commandId) {
|
|
314
|
+
if (!CommandsHistory_1.cache) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
CommandsHistory_1.cache.set(commandId, CommandsHistory_1.counter++);
|
|
318
|
+
CommandsHistory_1.hasChanges = true;
|
|
319
|
+
}
|
|
320
|
+
peek(commandId) {
|
|
321
|
+
return CommandsHistory_1.cache?.peek(commandId);
|
|
322
|
+
}
|
|
323
|
+
saveState() {
|
|
324
|
+
if (!CommandsHistory_1.cache) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (!CommandsHistory_1.hasChanges) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const serializedCache = { usesLRU: true, entries: [] };
|
|
331
|
+
CommandsHistory_1.cache.forEach((value, key) => serializedCache.entries.push({ key, value }));
|
|
332
|
+
this.storageService.store(CommandsHistory_1.PREF_KEY_CACHE, JSON.stringify(serializedCache), 0 , 0 );
|
|
333
|
+
this.storageService.store(CommandsHistory_1.PREF_KEY_COUNTER, CommandsHistory_1.counter, 0 , 0 );
|
|
334
|
+
CommandsHistory_1.hasChanges = false;
|
|
335
|
+
}
|
|
336
|
+
static getConfiguredCommandHistoryLength(configurationService) {
|
|
337
|
+
const config = configurationService.getValue();
|
|
338
|
+
const configuredCommandHistoryLength = config.workbench?.commandPalette?.history;
|
|
339
|
+
if (typeof configuredCommandHistoryLength === 'number') {
|
|
340
|
+
return configuredCommandHistoryLength;
|
|
341
|
+
}
|
|
342
|
+
return CommandsHistory_1.DEFAULT_COMMANDS_HISTORY_LENGTH;
|
|
343
|
+
}
|
|
344
|
+
static clearHistory(configurationService, storageService) {
|
|
345
|
+
const commandHistoryLength = CommandsHistory_1.getConfiguredCommandHistoryLength(configurationService);
|
|
346
|
+
CommandsHistory_1.cache = ( new LRUCache(commandHistoryLength));
|
|
347
|
+
CommandsHistory_1.counter = 1;
|
|
348
|
+
CommandsHistory_1.hasChanges = true;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
CommandsHistory = CommandsHistory_1 = ( __decorate([
|
|
352
|
+
( __param(0, IStorageService)),
|
|
353
|
+
( __param(1, IConfigurationService)),
|
|
354
|
+
( __param(2, ILogService))
|
|
355
|
+
], CommandsHistory));
|
|
356
|
+
|
|
357
|
+
export { AbstractCommandsQuickAccessProvider, CommandsHistory };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
3
|
+
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
4
|
+
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
|
|
6
|
+
import { Extensions } from 'vscode/vscode/vs/platform/quickinput/common/quickAccess';
|
|
7
|
+
import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
|
|
8
|
+
|
|
9
|
+
var HelpQuickAccessProvider_1;
|
|
10
|
+
let HelpQuickAccessProvider = class HelpQuickAccessProvider {
|
|
11
|
+
static { HelpQuickAccessProvider_1 = this; }
|
|
12
|
+
static { this.PREFIX = '?'; }
|
|
13
|
+
constructor(quickInputService, keybindingService) {
|
|
14
|
+
this.quickInputService = quickInputService;
|
|
15
|
+
this.keybindingService = keybindingService;
|
|
16
|
+
this.registry = ( Registry.as(Extensions.Quickaccess));
|
|
17
|
+
}
|
|
18
|
+
provide(picker) {
|
|
19
|
+
const disposables = ( new DisposableStore());
|
|
20
|
+
disposables.add(picker.onDidAccept(() => {
|
|
21
|
+
const [item] = picker.selectedItems;
|
|
22
|
+
if (item) {
|
|
23
|
+
this.quickInputService.quickAccess.show(item.prefix, { preserveValue: true });
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
disposables.add(picker.onDidChangeValue(value => {
|
|
27
|
+
const providerDescriptor = this.registry.getQuickAccessProvider(value.substr(HelpQuickAccessProvider_1.PREFIX.length));
|
|
28
|
+
if (providerDescriptor && providerDescriptor.prefix && providerDescriptor.prefix !== HelpQuickAccessProvider_1.PREFIX) {
|
|
29
|
+
this.quickInputService.quickAccess.show(providerDescriptor.prefix, { preserveValue: true });
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
picker.items = this.getQuickAccessProviders().filter(p => p.prefix !== HelpQuickAccessProvider_1.PREFIX);
|
|
33
|
+
return disposables;
|
|
34
|
+
}
|
|
35
|
+
getQuickAccessProviders() {
|
|
36
|
+
const providers = this.registry
|
|
37
|
+
.getQuickAccessProviders()
|
|
38
|
+
.sort((providerA, providerB) => providerA.prefix.localeCompare(providerB.prefix))
|
|
39
|
+
.flatMap(provider => this.createPicks(provider));
|
|
40
|
+
return providers;
|
|
41
|
+
}
|
|
42
|
+
createPicks(provider) {
|
|
43
|
+
return ( provider.helpEntries.map(helpEntry => {
|
|
44
|
+
const prefix = helpEntry.prefix || provider.prefix;
|
|
45
|
+
const label = prefix || '\u2026' ;
|
|
46
|
+
return {
|
|
47
|
+
prefix,
|
|
48
|
+
label,
|
|
49
|
+
keybinding: helpEntry.commandId ? this.keybindingService.lookupKeybinding(helpEntry.commandId) : undefined,
|
|
50
|
+
ariaLabel: ( localizeWithPath(
|
|
51
|
+
'vs/platform/quickinput/browser/helpQuickAccess',
|
|
52
|
+
'helpPickAriaLabel',
|
|
53
|
+
"{0}, {1}",
|
|
54
|
+
label,
|
|
55
|
+
helpEntry.description
|
|
56
|
+
)),
|
|
57
|
+
description: helpEntry.description
|
|
58
|
+
};
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
HelpQuickAccessProvider = HelpQuickAccessProvider_1 = ( __decorate([
|
|
63
|
+
( __param(0, IQuickInputService)),
|
|
64
|
+
( __param(1, IKeybindingService))
|
|
65
|
+
], HelpQuickAccessProvider));
|
|
66
|
+
|
|
67
|
+
export { HelpQuickAccessProvider };
|