@theia/file-search 1.45.1 → 1.46.0-next.72

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.
@@ -1,381 +1,381 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- 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;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var QuickFileOpenService_1;
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.QuickFileOpenService = exports.quickFileOpen = void 0;
29
- const inversify_1 = require("@theia/core/shared/inversify");
30
- const browser_1 = require("@theia/core/lib/browser");
31
- const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
32
- const uri_1 = require("@theia/core/lib/common/uri");
33
- const file_search_service_1 = require("../common/file-search-service");
34
- const common_1 = require("@theia/core/lib/common");
35
- const label_provider_1 = require("@theia/core/lib/browser/label-provider");
36
- const navigation_location_service_1 = require("@theia/editor/lib/browser/navigation/navigation-location-service");
37
- const fuzzy = require("@theia/core/shared/fuzzy");
38
- const message_service_1 = require("@theia/core/lib/common/message-service");
39
- const browser_2 = require("@theia/filesystem/lib/browser");
40
- const browser_3 = require("@theia/editor/lib/browser");
41
- const quick_input_service_1 = require("@theia/core/lib/browser/quick-input/quick-input-service");
42
- exports.quickFileOpen = common_1.Command.toDefaultLocalizedCommand({
43
- id: 'file-search.openFile',
44
- category: browser_1.CommonCommands.FILE_CATEGORY,
45
- label: 'Open File...'
46
- });
47
- // Supports patterns of <path><#|:><line><#|:|,><col?>
48
- const LINE_COLON_PATTERN = /\s?[#:\(](?:line )?(\d*)(?:[#:,](\d*))?\)?\s*$/;
49
- let QuickFileOpenService = QuickFileOpenService_1 = class QuickFileOpenService {
50
- constructor() {
51
- /**
52
- * Whether to hide .gitignored (and other ignored) files.
53
- */
54
- this.hideIgnoredFiles = true;
55
- /**
56
- * Whether the dialog is currently open.
57
- */
58
- this.isOpen = false;
59
- this.updateIsOpen = true;
60
- this.filterAndRangeDefault = { filter: '', range: undefined };
61
- /**
62
- * Tracks the user file search filter and location range e.g. fileFilter:line:column or fileFilter:line,column
63
- */
64
- this.filterAndRange = this.filterAndRangeDefault;
65
- }
66
- registerQuickAccessProvider() {
67
- this.quickAccessRegistry.registerQuickAccessProvider({
68
- getInstance: () => this,
69
- prefix: QuickFileOpenService_1.PREFIX,
70
- placeholder: this.getPlaceHolder(),
71
- helpEntries: [{ description: 'Open File', needsEditor: false }]
72
- });
73
- }
74
- init() {
75
- var _a;
76
- (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.onHide(() => {
77
- if (this.updateIsOpen) {
78
- this.isOpen = false;
79
- }
80
- else {
81
- this.updateIsOpen = true;
82
- }
83
- });
84
- }
85
- isEnabled() {
86
- return this.workspaceService.opened;
87
- }
88
- open() {
89
- var _a;
90
- // Triggering the keyboard shortcut while the dialog is open toggles
91
- // showing the ignored files.
92
- if (this.isOpen) {
93
- this.hideIgnoredFiles = !this.hideIgnoredFiles;
94
- this.hideQuickPick();
95
- }
96
- else {
97
- this.hideIgnoredFiles = true;
98
- this.filterAndRange = this.filterAndRangeDefault;
99
- this.isOpen = true;
100
- }
101
- (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.open(this.filterAndRange.filter);
102
- }
103
- hideQuickPick() {
104
- var _a;
105
- this.updateIsOpen = false;
106
- (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.hide();
107
- }
108
- /**
109
- * Get a string (suitable to show to the user) representing the keyboard
110
- * shortcut used to open the quick file open menu.
111
- */
112
- getKeyCommand() {
113
- const keyCommand = this.keybindingRegistry.getKeybindingsForCommand(exports.quickFileOpen.id);
114
- if (keyCommand) {
115
- // We only consider the first keybinding.
116
- const accel = this.keybindingRegistry.acceleratorFor(keyCommand[0], '+');
117
- return accel.join(' ');
118
- }
119
- return undefined;
120
- }
121
- async getPicks(filter, token) {
122
- const roots = this.workspaceService.tryGetRoots();
123
- this.filterAndRange = this.splitFilterAndRange(filter);
124
- const fileFilter = this.filterAndRange.filter;
125
- const alreadyCollected = new Set();
126
- const recentlyUsedItems = [];
127
- if (this.preferences.get('search.quickOpen.includeHistory')) {
128
- const locations = [...this.navigationLocationService.locations()].reverse();
129
- for (const location of locations) {
130
- const uriString = location.uri.toString();
131
- if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
132
- if (recentlyUsedItems.length === 0) {
133
- recentlyUsedItems.push({
134
- type: 'separator',
135
- label: common_1.nls.localizeByDefault('recently opened')
136
- });
137
- }
138
- const item = this.toItem(fileFilter, location.uri);
139
- recentlyUsedItems.push(item);
140
- alreadyCollected.add(uriString);
141
- }
142
- }
143
- }
144
- if (fileFilter.length > 0) {
145
- const handler = async (results) => {
146
- if (token.isCancellationRequested || results.length <= 0) {
147
- return [];
148
- }
149
- const result = [...recentlyUsedItems];
150
- const fileSearchResultItems = [];
151
- for (const fileUri of results) {
152
- if (!alreadyCollected.has(fileUri)) {
153
- const item = this.toItem(fileFilter, fileUri);
154
- fileSearchResultItems.push(item);
155
- alreadyCollected.add(fileUri);
156
- }
157
- }
158
- // Create a copy of the file search results and sort.
159
- const sortedResults = fileSearchResultItems.slice();
160
- sortedResults.sort((a, b) => this.compareItems(a, b));
161
- if (sortedResults.length > 0) {
162
- result.push({
163
- type: 'separator',
164
- label: common_1.nls.localizeByDefault('file results')
165
- });
166
- result.push(...sortedResults);
167
- }
168
- // Return the recently used items, followed by the search results.
169
- return result;
170
- };
171
- return this.fileSearchService.find(fileFilter, {
172
- rootUris: roots.map(r => r.resource.toString()),
173
- fuzzyMatch: true,
174
- limit: 200,
175
- useGitIgnore: this.hideIgnoredFiles,
176
- excludePatterns: this.hideIgnoredFiles
177
- ? Object.keys(this.fsPreferences['files.exclude'])
178
- : undefined,
179
- }, token).then(handler);
180
- }
181
- else {
182
- return roots.length !== 0 ? recentlyUsedItems : [];
183
- }
184
- }
185
- compareItems(left, right) {
186
- /**
187
- * Score a given string.
188
- *
189
- * @param str the string to score on.
190
- * @returns the score.
191
- */
192
- function score(str) {
193
- var _a;
194
- if (!str) {
195
- return 0;
196
- }
197
- let exactMatch = true;
198
- const partialMatches = querySplit.reduce((matched, part) => {
199
- const partMatches = str.includes(part);
200
- exactMatch = exactMatch && partMatches;
201
- return partMatches ? matched + QuickFileOpenService_1.Scores.partial : matched;
202
- }, 0);
203
- // Check fuzzy matches.
204
- const fuzzyMatch = (_a = fuzzy.match(queryJoin, str)) !== null && _a !== void 0 ? _a : { score: 0 };
205
- if (fuzzyMatch.score === Infinity && exactMatch) {
206
- return Number.MAX_SAFE_INTEGER;
207
- }
208
- return fuzzyMatch.score + partialMatches + (exactMatch ? QuickFileOpenService_1.Scores.exact : 0);
209
- }
210
- const query = normalize(this.filterAndRange.filter);
211
- // Adjust for whitespaces in the query.
212
- const querySplit = query.split(file_search_service_1.WHITESPACE_QUERY_SEPARATOR);
213
- const queryJoin = querySplit.join('');
214
- const compareByLabelScore = (l, r) => score(r.label) - score(l.label);
215
- const compareByLabelIndex = (l, r) => r.label.indexOf(query) - l.label.indexOf(query);
216
- const compareByLabel = (l, r) => l.label.localeCompare(r.label);
217
- const compareByPathScore = (l, r) => score(r.uri.path.toString()) - score(l.uri.path.toString());
218
- const compareByPathIndex = (l, r) => r.uri.path.toString().indexOf(query) - l.uri.path.toString().indexOf(query);
219
- const compareByPathLabel = (l, r) => l.uri.path.toString().localeCompare(r.uri.path.toString());
220
- return compareWithDiscriminators(left, right, compareByLabelScore, compareByLabelIndex, compareByLabel, compareByPathScore, compareByPathIndex, compareByPathLabel);
221
- }
222
- openFile(uri) {
223
- const options = this.buildOpenerOptions();
224
- const closedEditor = this.navigationLocationService.closedEditorsStack.find(editor => editor.uri.path.toString() === uri.path.toString());
225
- this.openerService.getOpener(uri, options)
226
- .then(opener => opener.open(uri, options))
227
- .then(widget => {
228
- // Attempt to restore the editor state if it exists, and no selection is explicitly requested.
229
- if (widget instanceof browser_3.EditorWidget && closedEditor && !options.selection) {
230
- widget.editor.restoreViewState(closedEditor.viewState);
231
- }
232
- })
233
- .catch(error => {
234
- console.warn(error);
235
- this.messageService.error(common_1.nls.localizeByDefault("Unable to open '{0}'", uri.path.toString()));
236
- });
237
- }
238
- buildOpenerOptions() {
239
- return { selection: this.filterAndRange.range };
240
- }
241
- toItem(lookFor, uriOrString) {
242
- const uri = uriOrString instanceof uri_1.default ? uriOrString : new uri_1.default(uriOrString);
243
- const label = this.labelProvider.getName(uri);
244
- const description = this.getItemDescription(uri);
245
- const iconClasses = this.getItemIconClasses(uri);
246
- return {
247
- label,
248
- description,
249
- highlights: {
250
- label: (0, quick_input_service_1.findMatches)(label, lookFor),
251
- description: (0, quick_input_service_1.findMatches)(description, lookFor)
252
- },
253
- iconClasses,
254
- uri,
255
- execute: () => this.openFile(uri)
256
- };
257
- }
258
- getItemIconClasses(uri) {
259
- const icon = this.labelProvider.getIcon(uri);
260
- return icon !== '' ? [icon + ' file-icon'] : [];
261
- }
262
- getItemDescription(uri) {
263
- return this.labelProvider.getDetails(uri);
264
- }
265
- getPlaceHolder() {
266
- let placeholder = common_1.nls.localizeByDefault('Search files by name (append {0} to go to line or {1} to go to symbol)', ':', '@');
267
- const keybinding = this.getKeyCommand();
268
- if (keybinding) {
269
- placeholder += common_1.nls.localize('theia/file-search/toggleIgnoredFiles', ' (Press {0} to show/hide ignored files)', keybinding);
270
- }
271
- return placeholder;
272
- }
273
- /**
274
- * Splits the given expression into a structure of search-file-filter and
275
- * location-range.
276
- *
277
- * @param expression patterns of <path><#|:><line><#|:|,><col?>
278
- */
279
- splitFilterAndRange(expression) {
280
- var _a, _b;
281
- let filter = expression;
282
- let range = undefined;
283
- // Find line and column number from the expression using RegExp.
284
- const patternMatch = LINE_COLON_PATTERN.exec(expression);
285
- if (patternMatch) {
286
- const line = parseInt((_a = patternMatch[1]) !== null && _a !== void 0 ? _a : '', 10);
287
- if (Number.isFinite(line)) {
288
- const lineNumber = line > 0 ? line - 1 : 0;
289
- const column = parseInt((_b = patternMatch[2]) !== null && _b !== void 0 ? _b : '', 10);
290
- const startColumn = Number.isFinite(column) && column > 0 ? column - 1 : 0;
291
- const position = browser_3.Position.create(lineNumber, startColumn);
292
- filter = expression.substring(0, patternMatch.index);
293
- range = browser_3.Range.create(position, position);
294
- }
295
- }
296
- return { filter, range };
297
- }
298
- };
299
- QuickFileOpenService.PREFIX = '';
300
- /**
301
- * The score constants when comparing file search results.
302
- */
303
- QuickFileOpenService.Scores = {
304
- max: 1000,
305
- exact: 500,
306
- partial: 250 // represents the score assigned to partial matching.
307
- };
308
- __decorate([
309
- (0, inversify_1.inject)(browser_1.KeybindingRegistry),
310
- __metadata("design:type", browser_1.KeybindingRegistry)
311
- ], QuickFileOpenService.prototype, "keybindingRegistry", void 0);
312
- __decorate([
313
- (0, inversify_1.inject)(workspace_service_1.WorkspaceService),
314
- __metadata("design:type", workspace_service_1.WorkspaceService)
315
- ], QuickFileOpenService.prototype, "workspaceService", void 0);
316
- __decorate([
317
- (0, inversify_1.inject)(browser_1.OpenerService),
318
- __metadata("design:type", Object)
319
- ], QuickFileOpenService.prototype, "openerService", void 0);
320
- __decorate([
321
- (0, inversify_1.inject)(quick_input_service_1.QuickInputService),
322
- (0, inversify_1.optional)(),
323
- __metadata("design:type", Object)
324
- ], QuickFileOpenService.prototype, "quickInputService", void 0);
325
- __decorate([
326
- (0, inversify_1.inject)(browser_1.QuickAccessRegistry),
327
- __metadata("design:type", Object)
328
- ], QuickFileOpenService.prototype, "quickAccessRegistry", void 0);
329
- __decorate([
330
- (0, inversify_1.inject)(file_search_service_1.FileSearchService),
331
- __metadata("design:type", Object)
332
- ], QuickFileOpenService.prototype, "fileSearchService", void 0);
333
- __decorate([
334
- (0, inversify_1.inject)(label_provider_1.LabelProvider),
335
- __metadata("design:type", label_provider_1.LabelProvider)
336
- ], QuickFileOpenService.prototype, "labelProvider", void 0);
337
- __decorate([
338
- (0, inversify_1.inject)(navigation_location_service_1.NavigationLocationService),
339
- __metadata("design:type", navigation_location_service_1.NavigationLocationService)
340
- ], QuickFileOpenService.prototype, "navigationLocationService", void 0);
341
- __decorate([
342
- (0, inversify_1.inject)(message_service_1.MessageService),
343
- __metadata("design:type", message_service_1.MessageService)
344
- ], QuickFileOpenService.prototype, "messageService", void 0);
345
- __decorate([
346
- (0, inversify_1.inject)(browser_2.FileSystemPreferences),
347
- __metadata("design:type", Object)
348
- ], QuickFileOpenService.prototype, "fsPreferences", void 0);
349
- __decorate([
350
- (0, inversify_1.inject)(browser_1.PreferenceService),
351
- __metadata("design:type", Object)
352
- ], QuickFileOpenService.prototype, "preferences", void 0);
353
- __decorate([
354
- (0, inversify_1.postConstruct)(),
355
- __metadata("design:type", Function),
356
- __metadata("design:paramtypes", []),
357
- __metadata("design:returntype", void 0)
358
- ], QuickFileOpenService.prototype, "init", null);
359
- QuickFileOpenService = QuickFileOpenService_1 = __decorate([
360
- (0, inversify_1.injectable)()
361
- ], QuickFileOpenService);
362
- exports.QuickFileOpenService = QuickFileOpenService;
363
- /**
364
- * Normalize a given string.
365
- *
366
- * @param str the raw string value.
367
- * @returns the normalized string value.
368
- */
369
- function normalize(str) {
370
- return str.trim().toLowerCase();
371
- }
372
- function compareWithDiscriminators(left, right, ...discriminators) {
373
- let comparisonValue = 0;
374
- let i = 0;
375
- while (comparisonValue === 0 && i < discriminators.length) {
376
- comparisonValue = discriminators[i](left, right);
377
- i++;
378
- }
379
- return comparisonValue;
380
- }
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ 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;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ var QuickFileOpenService_1;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.QuickFileOpenService = exports.quickFileOpen = void 0;
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const browser_1 = require("@theia/core/lib/browser");
31
+ const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
32
+ const uri_1 = require("@theia/core/lib/common/uri");
33
+ const file_search_service_1 = require("../common/file-search-service");
34
+ const common_1 = require("@theia/core/lib/common");
35
+ const label_provider_1 = require("@theia/core/lib/browser/label-provider");
36
+ const navigation_location_service_1 = require("@theia/editor/lib/browser/navigation/navigation-location-service");
37
+ const fuzzy = require("@theia/core/shared/fuzzy");
38
+ const message_service_1 = require("@theia/core/lib/common/message-service");
39
+ const browser_2 = require("@theia/filesystem/lib/browser");
40
+ const browser_3 = require("@theia/editor/lib/browser");
41
+ const quick_input_service_1 = require("@theia/core/lib/browser/quick-input/quick-input-service");
42
+ exports.quickFileOpen = common_1.Command.toDefaultLocalizedCommand({
43
+ id: 'file-search.openFile',
44
+ category: browser_1.CommonCommands.FILE_CATEGORY,
45
+ label: 'Open File...'
46
+ });
47
+ // Supports patterns of <path><#|:><line><#|:|,><col?>
48
+ const LINE_COLON_PATTERN = /\s?[#:\(](?:line )?(\d*)(?:[#:,](\d*))?\)?\s*$/;
49
+ let QuickFileOpenService = QuickFileOpenService_1 = class QuickFileOpenService {
50
+ constructor() {
51
+ /**
52
+ * Whether to hide .gitignored (and other ignored) files.
53
+ */
54
+ this.hideIgnoredFiles = true;
55
+ /**
56
+ * Whether the dialog is currently open.
57
+ */
58
+ this.isOpen = false;
59
+ this.updateIsOpen = true;
60
+ this.filterAndRangeDefault = { filter: '', range: undefined };
61
+ /**
62
+ * Tracks the user file search filter and location range e.g. fileFilter:line:column or fileFilter:line,column
63
+ */
64
+ this.filterAndRange = this.filterAndRangeDefault;
65
+ }
66
+ registerQuickAccessProvider() {
67
+ this.quickAccessRegistry.registerQuickAccessProvider({
68
+ getInstance: () => this,
69
+ prefix: QuickFileOpenService_1.PREFIX,
70
+ placeholder: this.getPlaceHolder(),
71
+ helpEntries: [{ description: 'Open File', needsEditor: false }]
72
+ });
73
+ }
74
+ init() {
75
+ var _a;
76
+ (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.onHide(() => {
77
+ if (this.updateIsOpen) {
78
+ this.isOpen = false;
79
+ }
80
+ else {
81
+ this.updateIsOpen = true;
82
+ }
83
+ });
84
+ }
85
+ isEnabled() {
86
+ return this.workspaceService.opened;
87
+ }
88
+ open() {
89
+ var _a;
90
+ // Triggering the keyboard shortcut while the dialog is open toggles
91
+ // showing the ignored files.
92
+ if (this.isOpen) {
93
+ this.hideIgnoredFiles = !this.hideIgnoredFiles;
94
+ this.hideQuickPick();
95
+ }
96
+ else {
97
+ this.hideIgnoredFiles = true;
98
+ this.filterAndRange = this.filterAndRangeDefault;
99
+ this.isOpen = true;
100
+ }
101
+ (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.open(this.filterAndRange.filter);
102
+ }
103
+ hideQuickPick() {
104
+ var _a;
105
+ this.updateIsOpen = false;
106
+ (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.hide();
107
+ }
108
+ /**
109
+ * Get a string (suitable to show to the user) representing the keyboard
110
+ * shortcut used to open the quick file open menu.
111
+ */
112
+ getKeyCommand() {
113
+ const keyCommand = this.keybindingRegistry.getKeybindingsForCommand(exports.quickFileOpen.id);
114
+ if (keyCommand) {
115
+ // We only consider the first keybinding.
116
+ const accel = this.keybindingRegistry.acceleratorFor(keyCommand[0], '+');
117
+ return accel.join(' ');
118
+ }
119
+ return undefined;
120
+ }
121
+ async getPicks(filter, token) {
122
+ const roots = this.workspaceService.tryGetRoots();
123
+ this.filterAndRange = this.splitFilterAndRange(filter);
124
+ const fileFilter = this.filterAndRange.filter;
125
+ const alreadyCollected = new Set();
126
+ const recentlyUsedItems = [];
127
+ if (this.preferences.get('search.quickOpen.includeHistory')) {
128
+ const locations = [...this.navigationLocationService.locations()].reverse();
129
+ for (const location of locations) {
130
+ const uriString = location.uri.toString();
131
+ if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
132
+ if (recentlyUsedItems.length === 0) {
133
+ recentlyUsedItems.push({
134
+ type: 'separator',
135
+ label: common_1.nls.localizeByDefault('recently opened')
136
+ });
137
+ }
138
+ const item = this.toItem(fileFilter, location.uri);
139
+ recentlyUsedItems.push(item);
140
+ alreadyCollected.add(uriString);
141
+ }
142
+ }
143
+ }
144
+ if (fileFilter.length > 0) {
145
+ const handler = async (results) => {
146
+ if (token.isCancellationRequested || results.length <= 0) {
147
+ return [];
148
+ }
149
+ const result = [...recentlyUsedItems];
150
+ const fileSearchResultItems = [];
151
+ for (const fileUri of results) {
152
+ if (!alreadyCollected.has(fileUri)) {
153
+ const item = this.toItem(fileFilter, fileUri);
154
+ fileSearchResultItems.push(item);
155
+ alreadyCollected.add(fileUri);
156
+ }
157
+ }
158
+ // Create a copy of the file search results and sort.
159
+ const sortedResults = fileSearchResultItems.slice();
160
+ sortedResults.sort((a, b) => this.compareItems(a, b));
161
+ if (sortedResults.length > 0) {
162
+ result.push({
163
+ type: 'separator',
164
+ label: common_1.nls.localizeByDefault('file results')
165
+ });
166
+ result.push(...sortedResults);
167
+ }
168
+ // Return the recently used items, followed by the search results.
169
+ return result;
170
+ };
171
+ return this.fileSearchService.find(fileFilter, {
172
+ rootUris: roots.map(r => r.resource.toString()),
173
+ fuzzyMatch: true,
174
+ limit: 200,
175
+ useGitIgnore: this.hideIgnoredFiles,
176
+ excludePatterns: this.hideIgnoredFiles
177
+ ? Object.keys(this.fsPreferences['files.exclude'])
178
+ : undefined,
179
+ }, token).then(handler);
180
+ }
181
+ else {
182
+ return roots.length !== 0 ? recentlyUsedItems : [];
183
+ }
184
+ }
185
+ compareItems(left, right) {
186
+ /**
187
+ * Score a given string.
188
+ *
189
+ * @param str the string to score on.
190
+ * @returns the score.
191
+ */
192
+ function score(str) {
193
+ var _a;
194
+ if (!str) {
195
+ return 0;
196
+ }
197
+ let exactMatch = true;
198
+ const partialMatches = querySplit.reduce((matched, part) => {
199
+ const partMatches = str.includes(part);
200
+ exactMatch = exactMatch && partMatches;
201
+ return partMatches ? matched + QuickFileOpenService_1.Scores.partial : matched;
202
+ }, 0);
203
+ // Check fuzzy matches.
204
+ const fuzzyMatch = (_a = fuzzy.match(queryJoin, str)) !== null && _a !== void 0 ? _a : { score: 0 };
205
+ if (fuzzyMatch.score === Infinity && exactMatch) {
206
+ return Number.MAX_SAFE_INTEGER;
207
+ }
208
+ return fuzzyMatch.score + partialMatches + (exactMatch ? QuickFileOpenService_1.Scores.exact : 0);
209
+ }
210
+ const query = normalize(this.filterAndRange.filter);
211
+ // Adjust for whitespaces in the query.
212
+ const querySplit = query.split(file_search_service_1.WHITESPACE_QUERY_SEPARATOR);
213
+ const queryJoin = querySplit.join('');
214
+ const compareByLabelScore = (l, r) => score(r.label) - score(l.label);
215
+ const compareByLabelIndex = (l, r) => r.label.indexOf(query) - l.label.indexOf(query);
216
+ const compareByLabel = (l, r) => l.label.localeCompare(r.label);
217
+ const compareByPathScore = (l, r) => score(r.uri.path.toString()) - score(l.uri.path.toString());
218
+ const compareByPathIndex = (l, r) => r.uri.path.toString().indexOf(query) - l.uri.path.toString().indexOf(query);
219
+ const compareByPathLabel = (l, r) => l.uri.path.toString().localeCompare(r.uri.path.toString());
220
+ return compareWithDiscriminators(left, right, compareByLabelScore, compareByLabelIndex, compareByLabel, compareByPathScore, compareByPathIndex, compareByPathLabel);
221
+ }
222
+ openFile(uri) {
223
+ const options = this.buildOpenerOptions();
224
+ const closedEditor = this.navigationLocationService.closedEditorsStack.find(editor => editor.uri.path.toString() === uri.path.toString());
225
+ this.openerService.getOpener(uri, options)
226
+ .then(opener => opener.open(uri, options))
227
+ .then(widget => {
228
+ // Attempt to restore the editor state if it exists, and no selection is explicitly requested.
229
+ if (widget instanceof browser_3.EditorWidget && closedEditor && !options.selection) {
230
+ widget.editor.restoreViewState(closedEditor.viewState);
231
+ }
232
+ })
233
+ .catch(error => {
234
+ console.warn(error);
235
+ this.messageService.error(common_1.nls.localizeByDefault("Unable to open '{0}'", uri.path.toString()));
236
+ });
237
+ }
238
+ buildOpenerOptions() {
239
+ return { selection: this.filterAndRange.range };
240
+ }
241
+ toItem(lookFor, uriOrString) {
242
+ const uri = uriOrString instanceof uri_1.default ? uriOrString : new uri_1.default(uriOrString);
243
+ const label = this.labelProvider.getName(uri);
244
+ const description = this.getItemDescription(uri);
245
+ const iconClasses = this.getItemIconClasses(uri);
246
+ return {
247
+ label,
248
+ description,
249
+ highlights: {
250
+ label: (0, quick_input_service_1.findMatches)(label, lookFor),
251
+ description: (0, quick_input_service_1.findMatches)(description, lookFor)
252
+ },
253
+ iconClasses,
254
+ uri,
255
+ execute: () => this.openFile(uri)
256
+ };
257
+ }
258
+ getItemIconClasses(uri) {
259
+ const icon = this.labelProvider.getIcon(uri);
260
+ return icon !== '' ? [icon + ' file-icon'] : [];
261
+ }
262
+ getItemDescription(uri) {
263
+ return this.labelProvider.getDetails(uri);
264
+ }
265
+ getPlaceHolder() {
266
+ let placeholder = common_1.nls.localizeByDefault('Search files by name (append {0} to go to line or {1} to go to symbol)', ':', '@');
267
+ const keybinding = this.getKeyCommand();
268
+ if (keybinding) {
269
+ placeholder += common_1.nls.localize('theia/file-search/toggleIgnoredFiles', ' (Press {0} to show/hide ignored files)', keybinding);
270
+ }
271
+ return placeholder;
272
+ }
273
+ /**
274
+ * Splits the given expression into a structure of search-file-filter and
275
+ * location-range.
276
+ *
277
+ * @param expression patterns of <path><#|:><line><#|:|,><col?>
278
+ */
279
+ splitFilterAndRange(expression) {
280
+ var _a, _b;
281
+ let filter = expression;
282
+ let range = undefined;
283
+ // Find line and column number from the expression using RegExp.
284
+ const patternMatch = LINE_COLON_PATTERN.exec(expression);
285
+ if (patternMatch) {
286
+ const line = parseInt((_a = patternMatch[1]) !== null && _a !== void 0 ? _a : '', 10);
287
+ if (Number.isFinite(line)) {
288
+ const lineNumber = line > 0 ? line - 1 : 0;
289
+ const column = parseInt((_b = patternMatch[2]) !== null && _b !== void 0 ? _b : '', 10);
290
+ const startColumn = Number.isFinite(column) && column > 0 ? column - 1 : 0;
291
+ const position = browser_3.Position.create(lineNumber, startColumn);
292
+ filter = expression.substring(0, patternMatch.index);
293
+ range = browser_3.Range.create(position, position);
294
+ }
295
+ }
296
+ return { filter, range };
297
+ }
298
+ };
299
+ QuickFileOpenService.PREFIX = '';
300
+ /**
301
+ * The score constants when comparing file search results.
302
+ */
303
+ QuickFileOpenService.Scores = {
304
+ max: 1000,
305
+ exact: 500,
306
+ partial: 250 // represents the score assigned to partial matching.
307
+ };
308
+ __decorate([
309
+ (0, inversify_1.inject)(browser_1.KeybindingRegistry),
310
+ __metadata("design:type", browser_1.KeybindingRegistry)
311
+ ], QuickFileOpenService.prototype, "keybindingRegistry", void 0);
312
+ __decorate([
313
+ (0, inversify_1.inject)(workspace_service_1.WorkspaceService),
314
+ __metadata("design:type", workspace_service_1.WorkspaceService)
315
+ ], QuickFileOpenService.prototype, "workspaceService", void 0);
316
+ __decorate([
317
+ (0, inversify_1.inject)(browser_1.OpenerService),
318
+ __metadata("design:type", Object)
319
+ ], QuickFileOpenService.prototype, "openerService", void 0);
320
+ __decorate([
321
+ (0, inversify_1.inject)(quick_input_service_1.QuickInputService),
322
+ (0, inversify_1.optional)(),
323
+ __metadata("design:type", Object)
324
+ ], QuickFileOpenService.prototype, "quickInputService", void 0);
325
+ __decorate([
326
+ (0, inversify_1.inject)(browser_1.QuickAccessRegistry),
327
+ __metadata("design:type", Object)
328
+ ], QuickFileOpenService.prototype, "quickAccessRegistry", void 0);
329
+ __decorate([
330
+ (0, inversify_1.inject)(file_search_service_1.FileSearchService),
331
+ __metadata("design:type", Object)
332
+ ], QuickFileOpenService.prototype, "fileSearchService", void 0);
333
+ __decorate([
334
+ (0, inversify_1.inject)(label_provider_1.LabelProvider),
335
+ __metadata("design:type", label_provider_1.LabelProvider)
336
+ ], QuickFileOpenService.prototype, "labelProvider", void 0);
337
+ __decorate([
338
+ (0, inversify_1.inject)(navigation_location_service_1.NavigationLocationService),
339
+ __metadata("design:type", navigation_location_service_1.NavigationLocationService)
340
+ ], QuickFileOpenService.prototype, "navigationLocationService", void 0);
341
+ __decorate([
342
+ (0, inversify_1.inject)(message_service_1.MessageService),
343
+ __metadata("design:type", message_service_1.MessageService)
344
+ ], QuickFileOpenService.prototype, "messageService", void 0);
345
+ __decorate([
346
+ (0, inversify_1.inject)(browser_2.FileSystemPreferences),
347
+ __metadata("design:type", Object)
348
+ ], QuickFileOpenService.prototype, "fsPreferences", void 0);
349
+ __decorate([
350
+ (0, inversify_1.inject)(browser_1.PreferenceService),
351
+ __metadata("design:type", Object)
352
+ ], QuickFileOpenService.prototype, "preferences", void 0);
353
+ __decorate([
354
+ (0, inversify_1.postConstruct)(),
355
+ __metadata("design:type", Function),
356
+ __metadata("design:paramtypes", []),
357
+ __metadata("design:returntype", void 0)
358
+ ], QuickFileOpenService.prototype, "init", null);
359
+ QuickFileOpenService = QuickFileOpenService_1 = __decorate([
360
+ (0, inversify_1.injectable)()
361
+ ], QuickFileOpenService);
362
+ exports.QuickFileOpenService = QuickFileOpenService;
363
+ /**
364
+ * Normalize a given string.
365
+ *
366
+ * @param str the raw string value.
367
+ * @returns the normalized string value.
368
+ */
369
+ function normalize(str) {
370
+ return str.trim().toLowerCase();
371
+ }
372
+ function compareWithDiscriminators(left, right, ...discriminators) {
373
+ let comparisonValue = 0;
374
+ let i = 0;
375
+ while (comparisonValue === 0 && i < discriminators.length) {
376
+ comparisonValue = discriminators[i](left, right);
377
+ i++;
378
+ }
379
+ return comparisonValue;
380
+ }
381
381
  //# sourceMappingURL=quick-file-open.js.map