Skip to content

Commit 72e92a0

Browse files
author
Andy
authored
Remove unused properties from patternMatcher (#23076)
1 parent 8cdd1ae commit 72e92a0

File tree

3 files changed

+18
-92
lines changed

3 files changed

+18
-92
lines changed

src/harness/unittests/services/patternMatcher.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ describe("PatternMatcher", () => {
127127

128128
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
129129
assert.equal(true, match.isCaseSensitive);
130-
assertInRange(match.camelCaseWeight, 1, 1 << 30);
131130
});
132131

133132
it("PreferCaseSensitiveCamelCaseMatchPartialPattern", () => {
@@ -237,30 +236,6 @@ describe("PatternMatcher", () => {
237236
assert.equal(false, match.isCaseSensitive);
238237
});
239238

240-
it("PreferCaseSensitiveRelativeWeights1", () => {
241-
const match1 = getFirstMatch("FogBarBaz", "FB");
242-
const match2 = getFirstMatch("FooFlobBaz", "FB");
243-
244-
// We should prefer something that starts at the beginning if possible
245-
assertInRange(match1.camelCaseWeight, match2.camelCaseWeight + 1, 1 << 30);
246-
});
247-
248-
it("PreferCaseSensitiveRelativeWeights2", () => {
249-
const match1 = getFirstMatch("BazBarFooFooFoo", "FFF");
250-
const match2 = getFirstMatch("BazFogBarFooFoo", "FFF");
251-
252-
// Contiguous things should also be preferred
253-
assertInRange(match1.camelCaseWeight, match2.camelCaseWeight + 1, 1 << 30);
254-
});
255-
256-
it("PreferCaseSensitiveRelativeWeights3", () => {
257-
const match1 = getFirstMatch("FogBarFooFoo", "FFF");
258-
const match2 = getFirstMatch("BarFooFooFoo", "FFF");
259-
260-
// The weight of being first should be greater than the weight of being contiguous
261-
assertInRange(match1.camelCaseWeight, match2.camelCaseWeight + 1, 1 << 30);
262-
});
263-
264239
it("AllLowerPattern1", () => {
265240
const match = getFirstMatch("FogBarChangedEventArgs", "changedeventargs");
266241

@@ -507,11 +482,6 @@ describe("PatternMatcher", () => {
507482
}
508483
}
509484

510-
function assertInRange(val: number, low: number, high: number) {
511-
assert.isTrue(val >= low);
512-
assert.isTrue(val <= high);
513-
}
514-
515485
function verifyBreakIntoCharacterSpans(original: string, ...parts: string[]): void {
516486
assertArrayEquals(parts, breakIntoCharacterSpans(original));
517487
}

src/services/navigateTo.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ namespace ts.NavigateTo {
5656
}
5757
}
5858

59-
const matchKind = Math.min(...matches.map(m => m.kind));
60-
const isCaseSensitive = allMatchesAreCaseSensitive(containerMatches);
61-
rawItems.push({ name, fileName, matchKind, isCaseSensitive, declaration });
59+
rawItems.push({ name, fileName, matchKind: Math.min(...matches.map(m => m.kind)), isCaseSensitive: matches.every(m => m.isCaseSensitive), declaration });
6260
}
6361
}
6462

@@ -75,19 +73,6 @@ namespace ts.NavigateTo {
7573
}
7674
}
7775

78-
function allMatchesAreCaseSensitive(matches: ReadonlyArray<PatternMatch>): boolean {
79-
Debug.assert(matches.length > 0);
80-
81-
// This is a case sensitive match, only if all the submatches were case sensitive.
82-
for (const match of matches) {
83-
if (!match.isCaseSensitive) {
84-
return false;
85-
}
86-
}
87-
88-
return true;
89-
}
90-
9176
function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]): boolean {
9277
const name = getNameOfDeclaration(declaration);
9378
if (name && isPropertyNameLiteral(name)) {

src/services/patternMatcher.ts

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,10 @@ namespace ts {
1515
// better than substring matches which are better than CamelCase matches.
1616
kind: PatternMatchKind;
1717

18-
// If this was a camel case match, how strong the match is. Higher number means
19-
// it was a better match.
20-
camelCaseWeight?: number;
21-
2218
// If this was a match where all constituent parts of the candidate and search pattern
2319
// matched case sensitively or case insensitively. Case sensitive matches of the kind
2420
// are better matches than insensitive matches.
2521
isCaseSensitive: boolean;
26-
27-
// Whether or not this match occurred with the punctuation from the search pattern stripped
28-
// out or not. Matches without the punctuation stripped are better than ones with punctuation
29-
// stripped.
30-
punctuationStripped: boolean;
3122
}
3223

3324
// The pattern matcher maintains an internal cache of information as it is used. Therefore,
@@ -99,12 +90,10 @@ namespace ts {
9990
characterSpans: TextSpan[];
10091
}
10192

102-
function createPatternMatch(kind: PatternMatchKind, punctuationStripped: boolean, isCaseSensitive: boolean, camelCaseWeight?: number): PatternMatch {
93+
function createPatternMatch(kind: PatternMatchKind, isCaseSensitive: boolean): PatternMatch {
10394
return {
10495
kind,
105-
punctuationStripped,
106-
isCaseSensitive,
107-
camelCaseWeight
96+
isCaseSensitive
10897
};
10998
}
11099

@@ -195,18 +184,18 @@ namespace ts {
195184
return spans;
196185
}
197186

198-
function matchTextChunk(candidate: string, chunk: TextChunk, punctuationStripped: boolean): PatternMatch {
187+
function matchTextChunk(candidate: string, chunk: TextChunk): PatternMatch {
199188
const index = indexOfIgnoringCase(candidate, chunk.textLowerCase);
200189
if (index === 0) {
201190
if (chunk.text.length === candidate.length) {
202191
// a) Check if the part matches the candidate entirely, in an case insensitive or
203192
// sensitive manner. If it does, return that there was an exact match.
204-
return createPatternMatch(PatternMatchKind.exact, punctuationStripped, /*isCaseSensitive:*/ candidate === chunk.text);
193+
return createPatternMatch(PatternMatchKind.exact, /*isCaseSensitive:*/ candidate === chunk.text);
205194
}
206195
else {
207196
// b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive
208197
// manner. If it does, return that there was a prefix match.
209-
return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
198+
return createPatternMatch(PatternMatchKind.prefix, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
210199
}
211200
}
212201

@@ -223,8 +212,7 @@ namespace ts {
223212
const wordSpans = getWordSpans(candidate);
224213
for (const span of wordSpans) {
225214
if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) {
226-
return createPatternMatch(PatternMatchKind.substring, punctuationStripped,
227-
/*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
215+
return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
228216
}
229217
}
230218
}
@@ -234,22 +222,18 @@ namespace ts {
234222
// candidate in a case *sensitive* manner. If so, return that there was a substring
235223
// match.
236224
if (candidate.indexOf(chunk.text) > 0) {
237-
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ true);
225+
return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ true);
238226
}
239227
}
240228

241229
if (!isLowercase) {
242230
// e) If the part was not entirely lowercase, then attempt a camel cased match as well.
243231
if (chunk.characterSpans.length > 0) {
244232
const candidateParts = getWordSpans(candidate);
245-
let camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false);
246-
if (camelCaseWeight !== undefined) {
247-
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ true, /*camelCaseWeight:*/ camelCaseWeight);
248-
}
249-
250-
camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ true);
251-
if (camelCaseWeight !== undefined) {
252-
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ false, /*camelCaseWeight:*/ camelCaseWeight);
233+
const isCaseSensitive = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false) ? true
234+
: tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ true) ? false : undefined;
235+
if (isCaseSensitive !== undefined) {
236+
return createPatternMatch(PatternMatchKind.camelCase, isCaseSensitive);
253237
}
254238
}
255239
}
@@ -264,7 +248,7 @@ namespace ts {
264248
// (Pattern: fogbar, Candidate: quuxfogbarFogBar).
265249
if (chunk.text.length < candidate.length) {
266250
if (index > 0 && isUpperCaseLetter(candidate.charCodeAt(index))) {
267-
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ false);
251+
return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ false);
268252
}
269253
}
270254
}
@@ -292,7 +276,7 @@ namespace ts {
292276
// Note: if the segment contains a space or an asterisk then we must assume that it's a
293277
// multi-word segment.
294278
if (!containsSpaceOrAsterisk(segment.totalTextChunk.text)) {
295-
const match = matchTextChunk(candidate, segment.totalTextChunk, /*punctuationStripped:*/ false);
279+
const match = matchTextChunk(candidate, segment.totalTextChunk);
296280
if (match) {
297281
return [match];
298282
}
@@ -340,7 +324,7 @@ namespace ts {
340324

341325
for (const subWordTextChunk of subWordTextChunks) {
342326
// Try to match the candidate with this word
343-
const result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true);
327+
const result = matchTextChunk(candidate, subWordTextChunk);
344328
if (!result) {
345329
return undefined;
346330
}
@@ -383,7 +367,7 @@ namespace ts {
383367
return true;
384368
}
385369

386-
function tryCamelCaseMatch(candidate: string, candidateParts: TextSpan[], chunk: TextChunk, ignoreCase: boolean): number {
370+
function tryCamelCaseMatch(candidate: string, candidateParts: TextSpan[], chunk: TextChunk, ignoreCase: boolean): boolean {
387371
const chunkCharacterSpans = chunk.characterSpans;
388372

389373
// Note: we may have more pattern parts than candidate parts. This is because multiple
@@ -399,24 +383,11 @@ namespace ts {
399383
while (true) {
400384
// Let's consider our termination cases
401385
if (currentChunkSpan === chunkCharacterSpans.length) {
402-
// We did match! We shall assign a weight to this
403-
let weight = 0;
404-
405-
// Was this contiguous?
406-
if (contiguous) {
407-
weight += 1;
408-
}
409-
410-
// Did we start at the beginning of the candidate?
411-
if (firstMatch === 0) {
412-
weight += 2;
413-
}
414-
415-
return weight;
386+
return true;
416387
}
417388
else if (currentCandidate === candidateParts.length) {
418389
// No match, since we still have more of the pattern to hit
419-
return undefined;
390+
return false;
420391
}
421392

422393
let candidatePart = candidateParts[currentCandidate];

0 commit comments

Comments
 (0)