fuzzyScorer.ts ×7

Frontier kind: Code frontier

unlabeled · c_b70fc09f0815

56 tests · 7192 LOC · 36 files · introduces 0 tests · 44 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
7 ranges44 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1042 ranges7192 lines · 36 files · Browse complete extent
All tests (intent)
56 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 44 introduced LOC across 7 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/fuzzyScorer.ts 44 introduced LOC · 7 ranges

Open complete file

381 const LABEL_SCORE_THRESHOLD = 1 << 16;
382
383 > function getCacheHash(label: string, description: string | undefined, allowNonContiguousMatches: boolean, query: IPreparedQuery) { fuzzyScorer.ts
384 > const values = query.values ? query.values : [query];
385 > const cacheHash = hash({
386 > [query.normalized]: {
387 > values: values.map(v => ({ value: v.normalized, expectContiguousMatch: v.expectContiguousMatch })),
388 > label,
389 > description,
390 > allowNonContiguousMatches
391 > }
392 > });
393 > return cacheHash;
394 > }
395
396 export function scoreItemFuzzy<T>(item: T, query: IPreparedQuery, allowNonContiguousMatches: boolean, accessor: IItemAccessor<T>, cache: FuzzyScorerCache): IItemScore {
398 return NO_ITEM_SCORE; // we need an item and query to score on at least
399 }
401 > const label = accessor.getItemLabel(item);
402 > if (!label) {
403 return NO_ITEM_SCORE; // we need a label at least
404 }
406 > const description = accessor.getItemDescription(item);
407 >
408 > // in order to speed up scoring, we cache the score with a unique hash based on:
409 > // - label
410 > // - description (if provided)
411 > // - whether non-contiguous matching is enabled or not
412 > // - hash of the query (normalized) values
413 > const cacheHash = getCacheHash(label, description, allowNonContiguousMatches, query);
414 > const cached = cache[cacheHash];
415 > if (cached) {
416 return cached;
417 }
419 > const itemScore = doScoreItemFuzzy(label, description, accessor.getItemPath(item), query, allowNonContiguousMatches);
420 > cache[cacheHash] = itemScore;
421 >
422 > return itemScore;
423 > }
424
425 > function doScoreItemFuzzy(label: string, description: string | undefined, path: string | undefined, query: IPreparedQuery, allowNonContiguousMatches: boolean): IItemScore { fuzzyScorer.ts
426 > const preferLabelMatches = !path || !query.containsPathSeparator;
427 >
428 > // Treat identity matches on full path highest
429 > if (path && (isLinux ? query.pathNormalized === path : equalsIgnoreCase(query.pathNormalized, path))) {
430 return { score: PATH_IDENTITY_SCORE, labelMatch: [{ start: 0, end: label.length }], descriptionMatch: description ? [{ start: 0, end: description.length }] : undefined };
431 }
433 > // Score: multiple inputs
434 > if (query.values && query.values.length > 1) {
435 return doScoreItemFuzzyMultiple(label, description, path, query.values, preferLabelMatches, allowNonContiguousMatches);
436 }
472 }
473
474 > function doScoreItemFuzzySingle(label: string, description: string | undefined, path: string | undefined, query: IPreparedQueryPiece, preferLabelMatches: boolean, allowNonContiguousMatches: boolean): IItemScore { fuzzyScorer.ts
475 >
476 > // Prefer label matches if told so or we have no description
477 > if (preferLabelMatches || !description) {
478 const [labelScore, labelPositions] = scoreFuzzy(
479 label,