Skip to content

Commit

Permalink
Use Number.MAX_SAFE_INTEGER in file quick search (#11232)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Jun 7, 2022
1 parent ac05b61 commit 0730d3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/api-tests/src/file-search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('file-search', function () {
});

it('should not place very good matches above exact matches', () => {
const exactMatch = 'aa_bb_cc_dd.file';
const veryGoodMatch = 'aa_bb_cc_ed_fd.file';
const exactMatch = 'almost_absurdly_long_file_name_with_many_parts.file';
const veryGoodMatch = 'almost_absurdly_long_file_name_with_many_parts_plus_one.file';
quickFileOpenService['filterAndRange'] = { filter: exactMatch };
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
const a = { label: exactMatch, uri: new Uri.default(exactMatch) };
Expand Down
4 changes: 2 additions & 2 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { OpenerService, KeybindingRegistry, QuickAccessRegistry, QuickAccessProv
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import URI from '@theia/core/lib/common/uri';
import { FileSearchService, WHITESPACE_QUERY_SEPARATOR } from '../common/file-search-service';
import { CancellationToken, Command, nls, MAX_SAFE_INTEGER } from '@theia/core/lib/common';
import { CancellationToken, Command, nls } from '@theia/core/lib/common';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import { NavigationLocationService } from '@theia/editor/lib/browser/navigation/navigation-location-service';
import * as fuzzy from '@theia/core/shared/fuzzy';
Expand Down Expand Up @@ -245,7 +245,7 @@ export class QuickFileOpenService implements QuickAccessProvider {
// Check fuzzy matches.
const fuzzyMatch = fuzzy.match(queryJoin, str) ?? { score: 0 };
if (fuzzyMatch.score === Infinity && exactMatch) {
return MAX_SAFE_INTEGER;
return Number.MAX_SAFE_INTEGER;
}

return fuzzyMatch.score + partialMatches + (exactMatch ? QuickFileOpenService.Scores.exact : 0);
Expand Down

0 comments on commit 0730d3b

Please sign in to comment.