From 70de88696c09cce079dfdb3c92c842c1922df67b Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 28 Jan 2021 09:13:33 +0100 Subject: [PATCH] d'oh, forgot to adjust anyScore to new data format of FuzzyScore, fixes https://github.com/microsoft/vscode/issues/115250 --- src/vs/base/common/filters.ts | 15 +++++++-------- src/vs/base/test/common/filters.test.ts | 8 +++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/vs/base/common/filters.ts b/src/vs/base/common/filters.ts index c75d24620b2..653587dc5e4 100644 --- a/src/vs/base/common/filters.ts +++ b/src/vs/base/common/filters.ts @@ -370,24 +370,23 @@ export function anyScore(pattern: string, lowPattern: string, _patternPos: numbe if (result) { return result; } - let matches = 0; + let matches: number[] = []; let score = 0; let idx = _wordPos; for (let patternPos = 0; patternPos < lowPattern.length && patternPos < _maxLen; ++patternPos) { const wordPos = lowWord.indexOf(lowPattern.charAt(patternPos), idx); if (wordPos >= 0) { score += 1; - matches += 2 ** wordPos; + matches.unshift(wordPos); idx = wordPos + 1; - - } else if (matches !== 0) { + } else if (matches.length > 0) { // once we have started matching things // we need to match the remaining pattern // characters break; } } - return [score, _wordPos, matches]; + return [score, _wordPos, ...matches]; } //#region --- fuzzyScore --- @@ -536,9 +535,9 @@ const enum Arrow { Diag = 1, Left = 2, LeftLeft = 3 } * * 0. the score * 1. the offset at which matching started - * 2. `` - * 3. `` - * 4. `` etc + * 2. `` + * 3. `` + * 4. `` etc */ export type FuzzyScore = [score: number, wordStart: number, ...matches: number[]];// [number, number, number]; diff --git a/src/vs/base/test/common/filters.test.ts b/src/vs/base/test/common/filters.test.ts index 2b6c83c457a..3489c5fdd56 100644 --- a/src/vs/base/test/common/filters.test.ts +++ b/src/vs/base/test/common/filters.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, IMatch, fuzzyScoreGraceful, fuzzyScoreGracefulAggressive, FuzzyScorer, createMatches } from 'vs/base/common/filters'; +import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, IMatch, fuzzyScoreGraceful, fuzzyScoreGracefulAggressive, FuzzyScorer, createMatches, anyScore } from 'vs/base/common/filters'; function filterOk(filter: IFilter, word: string, wordToMatchAgainst: string, highlights?: { start: number; end: number; }[]) { let r = filter(word, wordToMatchAgainst); @@ -549,4 +549,10 @@ suite('Filters', () => { assertMatches('SemanticTokens', 'SemanticTokensEdits', '^S^e^m^a^n^t^i^c^T^o^k^e^n^sEdits', fuzzyScore); assertMatches('SemanticTokens', 'SemanticTokensEdits', '^S^e^m^a^n^t^i^c^T^o^k^e^n^sEdits', fuzzyScoreGracefulAggressive); }); + + test('IntelliSense completion not correctly highlighting text in front of cursor #115250', function () { + assertMatches('lo', 'log', '^l^og', fuzzyScore); + assertMatches('.lo', 'log', '^l^og', anyScore); + assertMatches('.', 'log', 'log', anyScore); + }); });