@theia/file-search 1.58.3 → 1.59.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.
@@ -0,0 +1,276 @@
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 QuickFileSelectService_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.QuickFileSelectService = exports.FileQuickPickItem = void 0;
20
+ const tslib_1 = require("tslib");
21
+ const browser_1 = require("@theia/core/lib/browser");
22
+ const label_provider_1 = require("@theia/core/lib/browser/label-provider");
23
+ const quick_input_service_1 = require("@theia/core/lib/browser/quick-input/quick-input-service");
24
+ const common_1 = require("@theia/core/lib/common");
25
+ const message_service_1 = require("@theia/core/lib/common/message-service");
26
+ const uri_1 = require("@theia/core/lib/common/uri");
27
+ const fuzzy = require("@theia/core/shared/fuzzy");
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const browser_2 = require("@theia/editor/lib/browser");
30
+ const navigation_location_service_1 = require("@theia/editor/lib/browser/navigation/navigation-location-service");
31
+ const browser_3 = require("@theia/filesystem/lib/browser");
32
+ const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
33
+ const file_search_service_1 = require("../common/file-search-service");
34
+ // Supports patterns of <path><#|:><line><#|:|,><col?>
35
+ const LINE_COLON_PATTERN = /\s?[#:\(](?:line )?(\d*)(?:[#:,](\d*))?\)?\s*$/;
36
+ var FileQuickPickItem;
37
+ (function (FileQuickPickItem) {
38
+ function is(obj) {
39
+ return obj && 'uri' in obj;
40
+ }
41
+ FileQuickPickItem.is = is;
42
+ })(FileQuickPickItem || (exports.FileQuickPickItem = FileQuickPickItem = {}));
43
+ let QuickFileSelectService = QuickFileSelectService_1 = class QuickFileSelectService {
44
+ async getPicks(fileFilter = '', token = common_1.CancellationToken.None, options = {
45
+ hideIgnoredFiles: true
46
+ }) {
47
+ const roots = this.workspaceService.tryGetRoots();
48
+ const alreadyCollected = new Set();
49
+ const recentlyUsedItems = [];
50
+ if (this.preferences.get('search.quickOpen.includeHistory')) {
51
+ const locations = [...this.navigationLocationService.locations()].reverse();
52
+ for (const location of locations) {
53
+ const uriString = location.uri.toString();
54
+ if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
55
+ if (recentlyUsedItems.length === 0) {
56
+ recentlyUsedItems.push({
57
+ type: 'separator',
58
+ label: common_1.nls.localizeByDefault('recently opened')
59
+ });
60
+ }
61
+ const item = this.toItem(fileFilter, location.uri);
62
+ recentlyUsedItems.push(item);
63
+ alreadyCollected.add(uriString);
64
+ }
65
+ }
66
+ }
67
+ if (fileFilter.length > 0) {
68
+ const handler = async (results) => {
69
+ if (token.isCancellationRequested || results.length <= 0) {
70
+ return [];
71
+ }
72
+ const result = [...recentlyUsedItems];
73
+ const fileSearchResultItems = [];
74
+ for (const fileUri of results) {
75
+ if (!alreadyCollected.has(fileUri)) {
76
+ const item = this.toItem(fileFilter, fileUri, options.onSelect);
77
+ fileSearchResultItems.push(item);
78
+ alreadyCollected.add(fileUri);
79
+ }
80
+ }
81
+ // Create a copy of the file search results and sort.
82
+ const sortedResults = fileSearchResultItems.slice();
83
+ sortedResults.sort((a, b) => this.compareItems(a, b, fileFilter));
84
+ if (sortedResults.length > 0) {
85
+ result.push({
86
+ type: 'separator',
87
+ label: common_1.nls.localizeByDefault('file results')
88
+ });
89
+ result.push(...sortedResults);
90
+ }
91
+ // Return the recently used items, followed by the search results.
92
+ return result;
93
+ };
94
+ return this.fileSearchService.find(fileFilter, {
95
+ rootUris: roots.map(r => r.resource.toString()),
96
+ fuzzyMatch: true,
97
+ limit: 200,
98
+ useGitIgnore: options.hideIgnoredFiles,
99
+ excludePatterns: options.hideIgnoredFiles
100
+ ? Object.keys(this.fsPreferences['files.exclude'])
101
+ : undefined,
102
+ }, token).then(handler);
103
+ }
104
+ else {
105
+ return roots.length !== 0 ? recentlyUsedItems : [];
106
+ }
107
+ }
108
+ compareItems(left, right, fileFilter) {
109
+ /**
110
+ * Score a given string.
111
+ *
112
+ * @param str the string to score on.
113
+ * @returns the score.
114
+ */
115
+ function score(str) {
116
+ var _a;
117
+ if (!str) {
118
+ return 0;
119
+ }
120
+ let exactMatch = true;
121
+ const partialMatches = querySplit.reduce((matched, part) => {
122
+ const partMatches = str.includes(part);
123
+ exactMatch = exactMatch && partMatches;
124
+ return partMatches ? matched + QuickFileSelectService_1.Scores.partial : matched;
125
+ }, 0);
126
+ // Check fuzzy matches.
127
+ const fuzzyMatch = (_a = fuzzy.match(queryJoin, str)) !== null && _a !== void 0 ? _a : { score: 0 };
128
+ if (fuzzyMatch.score === Infinity && exactMatch) {
129
+ return Number.MAX_SAFE_INTEGER;
130
+ }
131
+ return fuzzyMatch.score + partialMatches + (exactMatch ? QuickFileSelectService_1.Scores.exact : 0);
132
+ }
133
+ const query = normalize(fileFilter);
134
+ // Adjust for whitespaces in the query.
135
+ const querySplit = query.split(file_search_service_1.WHITESPACE_QUERY_SEPARATOR);
136
+ const queryJoin = querySplit.join('');
137
+ const compareByLabelScore = (l, r) => score(r.label) - score(l.label);
138
+ const compareByLabelIndex = (l, r) => r.label.indexOf(query) - l.label.indexOf(query);
139
+ const compareByLabel = (l, r) => l.label.localeCompare(r.label);
140
+ const compareByPathScore = (l, r) => score(r.uri.path.toString()) - score(l.uri.path.toString());
141
+ const compareByPathIndex = (l, r) => r.uri.path.toString().indexOf(query) - l.uri.path.toString().indexOf(query);
142
+ const compareByPathLabel = (l, r) => l.uri.path.toString().localeCompare(r.uri.path.toString());
143
+ return compareWithDiscriminators(left, right, compareByLabelScore, compareByLabelIndex, compareByLabel, compareByPathScore, compareByPathIndex, compareByPathLabel);
144
+ }
145
+ toItem(lookFor, uriOrString, onSelect) {
146
+ const uri = uriOrString instanceof uri_1.default ? uriOrString : new uri_1.default(uriOrString);
147
+ const label = this.labelProvider.getName(uri);
148
+ const description = this.getItemDescription(uri);
149
+ const iconClasses = this.getItemIconClasses(uri);
150
+ const item = {
151
+ label,
152
+ description,
153
+ highlights: {
154
+ label: (0, quick_input_service_1.findMatches)(label, lookFor),
155
+ description: (0, quick_input_service_1.findMatches)(description, lookFor)
156
+ },
157
+ iconClasses,
158
+ uri
159
+ };
160
+ return {
161
+ ...item,
162
+ execute: () => onSelect ? onSelect(item) : undefined
163
+ };
164
+ }
165
+ getItemIconClasses(uri) {
166
+ const icon = this.labelProvider.getIcon(uri).split(' ').filter(v => v.length > 0);
167
+ if (icon.length > 0) {
168
+ icon.push('file-icon');
169
+ }
170
+ return icon;
171
+ }
172
+ getItemDescription(uri) {
173
+ return this.labelProvider.getDetails(uri);
174
+ }
175
+ /**
176
+ * Splits the given expression into a structure of search-file-filter and
177
+ * location-range.
178
+ *
179
+ * @param expression patterns of <path><#|:><line><#|:|,><col?>
180
+ */
181
+ splitFilterAndRange(expression) {
182
+ var _a, _b;
183
+ let filter = expression;
184
+ let range = undefined;
185
+ // Find line and column number from the expression using RegExp.
186
+ const patternMatch = LINE_COLON_PATTERN.exec(expression);
187
+ if (patternMatch) {
188
+ const line = parseInt((_a = patternMatch[1]) !== null && _a !== void 0 ? _a : '', 10);
189
+ if (Number.isFinite(line)) {
190
+ const lineNumber = line > 0 ? line - 1 : 0;
191
+ const column = parseInt((_b = patternMatch[2]) !== null && _b !== void 0 ? _b : '', 10);
192
+ const startColumn = Number.isFinite(column) && column > 0 ? column - 1 : 0;
193
+ const position = browser_2.Position.create(lineNumber, startColumn);
194
+ filter = expression.substring(0, patternMatch.index);
195
+ range = browser_2.Range.create(position, position);
196
+ }
197
+ }
198
+ return { filter, range };
199
+ }
200
+ };
201
+ exports.QuickFileSelectService = QuickFileSelectService;
202
+ /**
203
+ * The score constants when comparing file search results.
204
+ */
205
+ QuickFileSelectService.Scores = {
206
+ max: 1000, // represents the maximum score from fuzzy matching (Infinity).
207
+ exact: 500, // represents the score assigned to exact matching.
208
+ partial: 250 // represents the score assigned to partial matching.
209
+ };
210
+ tslib_1.__decorate([
211
+ (0, inversify_1.inject)(browser_1.KeybindingRegistry),
212
+ tslib_1.__metadata("design:type", browser_1.KeybindingRegistry)
213
+ ], QuickFileSelectService.prototype, "keybindingRegistry", void 0);
214
+ tslib_1.__decorate([
215
+ (0, inversify_1.inject)(workspace_service_1.WorkspaceService),
216
+ tslib_1.__metadata("design:type", workspace_service_1.WorkspaceService)
217
+ ], QuickFileSelectService.prototype, "workspaceService", void 0);
218
+ tslib_1.__decorate([
219
+ (0, inversify_1.inject)(browser_1.OpenerService),
220
+ tslib_1.__metadata("design:type", Object)
221
+ ], QuickFileSelectService.prototype, "openerService", void 0);
222
+ tslib_1.__decorate([
223
+ (0, inversify_1.inject)(quick_input_service_1.QuickInputService),
224
+ (0, inversify_1.optional)(),
225
+ tslib_1.__metadata("design:type", Object)
226
+ ], QuickFileSelectService.prototype, "quickInputService", void 0);
227
+ tslib_1.__decorate([
228
+ (0, inversify_1.inject)(browser_1.QuickAccessRegistry),
229
+ tslib_1.__metadata("design:type", Object)
230
+ ], QuickFileSelectService.prototype, "quickAccessRegistry", void 0);
231
+ tslib_1.__decorate([
232
+ (0, inversify_1.inject)(file_search_service_1.FileSearchService),
233
+ tslib_1.__metadata("design:type", Object)
234
+ ], QuickFileSelectService.prototype, "fileSearchService", void 0);
235
+ tslib_1.__decorate([
236
+ (0, inversify_1.inject)(label_provider_1.LabelProvider),
237
+ tslib_1.__metadata("design:type", label_provider_1.LabelProvider)
238
+ ], QuickFileSelectService.prototype, "labelProvider", void 0);
239
+ tslib_1.__decorate([
240
+ (0, inversify_1.inject)(navigation_location_service_1.NavigationLocationService),
241
+ tslib_1.__metadata("design:type", navigation_location_service_1.NavigationLocationService)
242
+ ], QuickFileSelectService.prototype, "navigationLocationService", void 0);
243
+ tslib_1.__decorate([
244
+ (0, inversify_1.inject)(message_service_1.MessageService),
245
+ tslib_1.__metadata("design:type", message_service_1.MessageService)
246
+ ], QuickFileSelectService.prototype, "messageService", void 0);
247
+ tslib_1.__decorate([
248
+ (0, inversify_1.inject)(browser_3.FileSystemPreferences),
249
+ tslib_1.__metadata("design:type", Object)
250
+ ], QuickFileSelectService.prototype, "fsPreferences", void 0);
251
+ tslib_1.__decorate([
252
+ (0, inversify_1.inject)(browser_1.PreferenceService),
253
+ tslib_1.__metadata("design:type", Object)
254
+ ], QuickFileSelectService.prototype, "preferences", void 0);
255
+ exports.QuickFileSelectService = QuickFileSelectService = QuickFileSelectService_1 = tslib_1.__decorate([
256
+ (0, inversify_1.injectable)()
257
+ ], QuickFileSelectService);
258
+ /**
259
+ * Normalize a given string.
260
+ *
261
+ * @param str the raw string value.
262
+ * @returns the normalized string value.
263
+ */
264
+ function normalize(str) {
265
+ return str.trim().toLowerCase();
266
+ }
267
+ function compareWithDiscriminators(left, right, ...discriminators) {
268
+ let comparisonValue = 0;
269
+ let i = 0;
270
+ while (comparisonValue === 0 && i < discriminators.length) {
271
+ comparisonValue = discriminators[i](left, right);
272
+ i++;
273
+ }
274
+ return comparisonValue;
275
+ }
276
+ //# sourceMappingURL=quick-file-select-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quick-file-select-service.js","sourceRoot":"","sources":["../../src/browser/quick-file-select-service.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8E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AC;IACD,OAAO,eAAe,CAAC;AAC3B,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@theia/file-search",
3
- "version": "1.58.3",
3
+ "version": "1.59.0-next.72+f41d8efcd",
4
4
  "description": "Theia - File Search Extension",
5
5
  "dependencies": {
6
- "@theia/core": "1.58.3",
7
- "@theia/editor": "1.58.3",
8
- "@theia/filesystem": "1.58.3",
9
- "@theia/process": "1.58.3",
10
- "@theia/workspace": "1.58.3",
6
+ "@theia/core": "1.59.0-next.72+f41d8efcd",
7
+ "@theia/editor": "1.59.0-next.72+f41d8efcd",
8
+ "@theia/filesystem": "1.59.0-next.72+f41d8efcd",
9
+ "@theia/process": "1.59.0-next.72+f41d8efcd",
10
+ "@theia/workspace": "1.59.0-next.72+f41d8efcd",
11
11
  "@vscode/ripgrep": "^1.14.2",
12
12
  "tslib": "^2.6.2"
13
13
  },
@@ -45,10 +45,10 @@
45
45
  "watch": "theiaext watch"
46
46
  },
47
47
  "devDependencies": {
48
- "@theia/ext-scripts": "1.58.3"
48
+ "@theia/ext-scripts": "1.58.0"
49
49
  },
50
50
  "nyc": {
51
51
  "extends": "../../configs/nyc.json"
52
52
  },
53
- "gitHead": "ca70c15332f91e0f61b12cd147b5ff8326e2e6d2"
53
+ "gitHead": "f41d8efcd4abb79167b74bf476eafc7857e97306"
54
54
  }
@@ -21,6 +21,7 @@ import { QuickFileOpenFrontendContribution } from './quick-file-open-contributio
21
21
  import { QuickFileOpenService } from './quick-file-open';
22
22
  import { fileSearchServicePath, FileSearchService } from '../common/file-search-service';
23
23
  import { QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access';
24
+ import { QuickFileSelectService } from './quick-file-select-service';
24
25
 
25
26
  export default new ContainerModule((bind: interfaces.Bind) => {
26
27
  bind(FileSearchService).toDynamicValue(ctx => {
@@ -33,5 +34,6 @@ export default new ContainerModule((bind: interfaces.Bind) => {
33
34
  bind(serviceIdentifier).toService(QuickFileOpenFrontendContribution)
34
35
  );
35
36
 
37
+ bind(QuickFileSelectService).toSelf().inSingletonScope();
36
38
  bind(QuickFileOpenService).toSelf().inSingletonScope();
37
39
  });
@@ -14,19 +14,16 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
18
- import { OpenerService, KeybindingRegistry, QuickAccessRegistry, QuickAccessProvider, CommonCommands, PreferenceService } from '@theia/core/lib/browser';
19
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
20
- import URI from '@theia/core/lib/common/uri';
21
- import { FileSearchService, WHITESPACE_QUERY_SEPARATOR } from '../common/file-search-service';
17
+ import { CommonCommands, KeybindingRegistry, OpenerService, QuickAccessProvider, QuickAccessRegistry } from '@theia/core/lib/browser';
18
+ import { QuickInputService, QuickPickItem, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
22
19
  import { CancellationToken, Command, nls } from '@theia/core/lib/common';
23
- import { LabelProvider } from '@theia/core/lib/browser/label-provider';
24
- import { NavigationLocationService } from '@theia/editor/lib/browser/navigation/navigation-location-service';
25
- import * as fuzzy from '@theia/core/shared/fuzzy';
26
20
  import { MessageService } from '@theia/core/lib/common/message-service';
27
- import { FileSystemPreferences } from '@theia/filesystem/lib/browser';
21
+ import URI from '@theia/core/lib/common/uri';
22
+ import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
28
23
  import { EditorOpenerOptions, EditorWidget, Position, Range } from '@theia/editor/lib/browser';
29
- import { findMatches, QuickInputService, QuickPickItem, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
24
+ import { NavigationLocationService } from '@theia/editor/lib/browser/navigation/navigation-location-service';
25
+ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
26
+ import { QuickFileSelectService } from './quick-file-select-service';
30
27
 
31
28
  export const quickFileOpen = Command.toDefaultLocalizedCommand({
32
29
  id: 'file-search.openFile',
@@ -56,18 +53,12 @@ export class QuickFileOpenService implements QuickAccessProvider {
56
53
  protected readonly quickInputService: QuickInputService;
57
54
  @inject(QuickAccessRegistry)
58
55
  protected readonly quickAccessRegistry: QuickAccessRegistry;
59
- @inject(FileSearchService)
60
- protected readonly fileSearchService: FileSearchService;
61
- @inject(LabelProvider)
62
- protected readonly labelProvider: LabelProvider;
63
56
  @inject(NavigationLocationService)
64
57
  protected readonly navigationLocationService: NavigationLocationService;
65
58
  @inject(MessageService)
66
59
  protected readonly messageService: MessageService;
67
- @inject(FileSystemPreferences)
68
- protected readonly fsPreferences: FileSystemPreferences;
69
- @inject(PreferenceService)
70
- protected readonly preferences: PreferenceService;
60
+ @inject(QuickFileSelectService)
61
+ protected readonly quickFileSelectService: QuickFileSelectService;
71
62
 
72
63
  registerQuickAccessProvider(): void {
73
64
  this.quickAccessRegistry.registerQuickAccessProvider({
@@ -96,15 +87,6 @@ export class QuickFileOpenService implements QuickAccessProvider {
96
87
  */
97
88
  protected filterAndRange: FilterAndRange = this.filterAndRangeDefault;
98
89
 
99
- /**
100
- * The score constants when comparing file search results.
101
- */
102
- private static readonly Scores = {
103
- max: 1000, // represents the maximum score from fuzzy matching (Infinity).
104
- exact: 500, // represents the score assigned to exact matching.
105
- partial: 250 // represents the score assigned to partial matching.
106
- };
107
-
108
90
  @postConstruct()
109
91
  protected init(): void {
110
92
  this.quickInputService?.onHide(() => {
@@ -156,125 +138,13 @@ export class QuickFileOpenService implements QuickAccessProvider {
156
138
  }
157
139
 
158
140
  async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
159
- const roots = this.workspaceService.tryGetRoots();
160
-
161
141
  this.filterAndRange = this.splitFilterAndRange(filter);
162
142
  const fileFilter = this.filterAndRange.filter;
163
-
164
- const alreadyCollected = new Set<string>();
165
- const recentlyUsedItems: QuickPicks = [];
166
-
167
- if (this.preferences.get('search.quickOpen.includeHistory')) {
168
- const locations = [...this.navigationLocationService.locations()].reverse();
169
- for (const location of locations) {
170
- const uriString = location.uri.toString();
171
-
172
- if (location.uri.scheme === 'file' && !alreadyCollected.has(uriString) && fuzzy.test(fileFilter, uriString)) {
173
- if (recentlyUsedItems.length === 0) {
174
- recentlyUsedItems.push({
175
- type: 'separator',
176
- label: nls.localizeByDefault('recently opened')
177
- });
178
- }
179
- const item = this.toItem(fileFilter, location.uri);
180
- recentlyUsedItems.push(item);
181
- alreadyCollected.add(uriString);
182
- }
183
- }
184
- }
185
-
186
- if (fileFilter.length > 0) {
187
- const handler = async (results: string[]) => {
188
- if (token.isCancellationRequested || results.length <= 0) {
189
- return [];
190
- }
191
-
192
- const result = [...recentlyUsedItems];
193
- const fileSearchResultItems: FileQuickPickItem[] = [];
194
-
195
- for (const fileUri of results) {
196
- if (!alreadyCollected.has(fileUri)) {
197
- const item = this.toItem(fileFilter, fileUri);
198
- fileSearchResultItems.push(item);
199
- alreadyCollected.add(fileUri);
200
- }
201
- }
202
-
203
- // Create a copy of the file search results and sort.
204
- const sortedResults = fileSearchResultItems.slice();
205
- sortedResults.sort((a, b) => this.compareItems(a, b));
206
-
207
- if (sortedResults.length > 0) {
208
- result.push({
209
- type: 'separator',
210
- label: nls.localizeByDefault('file results')
211
- });
212
- result.push(...sortedResults);
213
- }
214
-
215
- // Return the recently used items, followed by the search results.
216
- return result;
217
- };
218
-
219
- return this.fileSearchService.find(fileFilter, {
220
- rootUris: roots.map(r => r.resource.toString()),
221
- fuzzyMatch: true,
222
- limit: 200,
223
- useGitIgnore: this.hideIgnoredFiles,
224
- excludePatterns: this.hideIgnoredFiles
225
- ? Object.keys(this.fsPreferences['files.exclude'])
226
- : undefined,
227
- }, token).then(handler);
228
- } else {
229
- return roots.length !== 0 ? recentlyUsedItems : [];
230
- }
231
- }
232
-
233
- protected compareItems(
234
- left: FileQuickPickItem,
235
- right: FileQuickPickItem): number {
236
-
237
- /**
238
- * Score a given string.
239
- *
240
- * @param str the string to score on.
241
- * @returns the score.
242
- */
243
- function score(str: string | undefined): number {
244
- if (!str) {
245
- return 0;
246
- }
247
-
248
- let exactMatch = true;
249
- const partialMatches = querySplit.reduce((matched, part) => {
250
- const partMatches = str.includes(part);
251
- exactMatch = exactMatch && partMatches;
252
- return partMatches ? matched + QuickFileOpenService.Scores.partial : matched;
253
- }, 0);
254
-
255
- // Check fuzzy matches.
256
- const fuzzyMatch = fuzzy.match(queryJoin, str) ?? { score: 0 };
257
- if (fuzzyMatch.score === Infinity && exactMatch) {
258
- return Number.MAX_SAFE_INTEGER;
259
- }
260
-
261
- return fuzzyMatch.score + partialMatches + (exactMatch ? QuickFileOpenService.Scores.exact : 0);
262
- }
263
-
264
- const query: string = normalize(this.filterAndRange.filter);
265
- // Adjust for whitespaces in the query.
266
- const querySplit = query.split(WHITESPACE_QUERY_SEPARATOR);
267
- const queryJoin = querySplit.join('');
268
-
269
- const compareByLabelScore = (l: FileQuickPickItem, r: FileQuickPickItem) => score(r.label) - score(l.label);
270
- const compareByLabelIndex = (l: FileQuickPickItem, r: FileQuickPickItem) => r.label.indexOf(query) - l.label.indexOf(query);
271
- const compareByLabel = (l: FileQuickPickItem, r: FileQuickPickItem) => l.label.localeCompare(r.label);
272
-
273
- const compareByPathScore = (l: FileQuickPickItem, r: FileQuickPickItem) => score(r.uri.path.toString()) - score(l.uri.path.toString());
274
- const compareByPathIndex = (l: FileQuickPickItem, r: FileQuickPickItem) => r.uri.path.toString().indexOf(query) - l.uri.path.toString().indexOf(query);
275
- const compareByPathLabel = (l: FileQuickPickItem, r: FileQuickPickItem) => l.uri.path.toString().localeCompare(r.uri.path.toString());
276
-
277
- return compareWithDiscriminators(left, right, compareByLabelScore, compareByLabelIndex, compareByLabel, compareByPathScore, compareByPathIndex, compareByPathLabel);
143
+ return this.quickFileSelectService.getPicks(fileFilter, token, {
144
+ hideIgnoredFiles: this.hideIgnoredFiles,
145
+ onSelect: item => this.openFile(item.uri)
146
+ },
147
+ );
278
148
  }
279
149
 
280
150
  openFile(uri: URI): void {
@@ -298,37 +168,6 @@ export class QuickFileOpenService implements QuickAccessProvider {
298
168
  return { selection: this.filterAndRange.range };
299
169
  }
300
170
 
301
- private toItem(lookFor: string, uriOrString: URI | string): FileQuickPickItem {
302
- const uri = uriOrString instanceof URI ? uriOrString : new URI(uriOrString);
303
- const label = this.labelProvider.getName(uri);
304
- const description = this.getItemDescription(uri);
305
- const iconClasses = this.getItemIconClasses(uri);
306
-
307
- return {
308
- label,
309
- description,
310
- highlights: {
311
- label: findMatches(label, lookFor),
312
- description: findMatches(description, lookFor)
313
- },
314
- iconClasses,
315
- uri,
316
- execute: () => this.openFile(uri)
317
- };
318
- }
319
-
320
- private getItemIconClasses(uri: URI): string[] | undefined {
321
- const icon = this.labelProvider.getIcon(uri).split(' ').filter(v => v.length > 0);
322
- if (icon.length > 0) {
323
- icon.push('file-icon');
324
- }
325
- return icon;
326
- }
327
-
328
- private getItemDescription(uri: URI): string {
329
- return this.labelProvider.getDetails(uri);
330
- }
331
-
332
171
  private getPlaceHolder(): string {
333
172
  let placeholder = nls.localizeByDefault('Search files by name (append {0} to go to line or {1} to go to symbol)', ':', '@');
334
173
  const keybinding = this.getKeyCommand();
@@ -367,24 +206,3 @@ export class QuickFileOpenService implements QuickAccessProvider {
367
206
  return { filter, range };
368
207
  }
369
208
  }
370
-
371
- /**
372
- * Normalize a given string.
373
- *
374
- * @param str the raw string value.
375
- * @returns the normalized string value.
376
- */
377
- function normalize(str: string): string {
378
- return str.trim().toLowerCase();
379
- }
380
-
381
- function compareWithDiscriminators<T>(left: T, right: T, ...discriminators: ((left: T, right: T) => number)[]): number {
382
- let comparisonValue = 0;
383
- let i = 0;
384
-
385
- while (comparisonValue === 0 && i < discriminators.length) {
386
- comparisonValue = discriminators[i](left, right);
387
- i++;
388
- }
389
- return comparisonValue;
390
- }