matchTextChunk: combine a) and b) cases (#23083)

This commit is contained in:
Andy 2018-04-02 18:09:09 -07:00 committed by GitHub
parent 1e04bd4168
commit 92dfde0067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -176,21 +176,14 @@ namespace ts {
function matchTextChunk(candidate: string, chunk: TextChunk, stringToWordSpans: Map<TextSpan[]>): PatternMatch | undefined {
const index = indexOfIgnoringCase(candidate, chunk.textLowerCase);
if (index === 0) {
if (chunk.text.length === candidate.length) {
// a) Check if the part matches the candidate entirely, in an case insensitive or
// sensitive manner. If it does, return that there was an exact match.
return createPatternMatch(PatternMatchKind.exact, /*isCaseSensitive:*/ candidate === chunk.text);
}
else {
// b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive
// manner. If it does, return that there was a prefix match.
return createPatternMatch(PatternMatchKind.prefix, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
}
// a) Check if the word is a prefix of the candidate, in a case insensitive or
// sensitive manner. If it does, return that there was an exact match if the word and candidate are the same length, else a prefix match.
return createPatternMatch(chunk.text.length === candidate.length ? PatternMatchKind.exact : PatternMatchKind.prefix, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
}
if (chunk.isLowerCase) {
if (index === -1) return undefined;
// c) If the part is entirely lowercase, then check if it is contained anywhere in the
// b) If the part is entirely lowercase, then check if it is contained anywhere in the
// candidate in a case insensitive manner. If so, return that there was a substring
// match.
//
@ -203,7 +196,7 @@ namespace ts {
return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
}
}
// d) Is the pattern a substring of the candidate starting on one of the candidate's word boundaries?
// c) Is the pattern a substring of the candidate starting on one of the candidate's word boundaries?
// We could check every character boundary start of the candidate for the pattern. However, that's
// an m * n operation in the wost case. Instead, find the first instance of the pattern
// substring, and see if it starts on a capital letter. It seems unlikely that the user will try to
@ -214,13 +207,13 @@ namespace ts {
}
}
else {
// e) If the part was not entirely lowercase, then check if it is contained in the
// d) If the part was not entirely lowercase, then check if it is contained in the
// candidate in a case *sensitive* manner. If so, return that there was a substring
// match.
if (candidate.indexOf(chunk.text) > 0) {
return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ true);
}
// f) If the part was not entirely lowercase, then attempt a camel cased match as well.
// e) If the part was not entirely lowercase, then attempt a camel cased match as well.
if (chunk.characterSpans.length > 0) {
const candidateParts = getWordSpans(candidate, stringToWordSpans);
const isCaseSensitive = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false) ? true
@ -268,14 +261,11 @@ namespace ts {
//
// 3) Matching is as follows:
//
// a) Check if the word matches the candidate entirely, in an case insensitive or
// sensitive manner. If it does, return that there was an exact match.
//
// b) Check if the word is a prefix of the candidate, in a case insensitive or
// sensitive manner. If it does, return that there was a prefix match.
// a) Check if the word is a prefix of the candidate, in a case insensitive or
// sensitive manner. If it does, return that there was an exact match if the word and candidate are the same length, else a prefix match.
//
// If the word is entirely lowercase:
// c) Then check if it is contained anywhere in the
// b) Then check if it is contained anywhere in the
// candidate in a case insensitive manner. If so, return that there was a substring
// match.
//
@ -284,15 +274,15 @@ namespace ts {
// types 'a'. But we would match 'FooAttribute' (since 'Attribute' starts with
// 'a').
//
// d) The word is all lower case. Is it a case insensitive substring of the candidate starting
// c) The word is all lower case. Is it a case insensitive substring of the candidate starting
// on a part boundary of the candidate?
//
// Else:
// e) If the word was not entirely lowercase, then check if it is contained in the
// d) If the word was not entirely lowercase, then check if it is contained in the
// candidate in a case *sensitive* manner. If so, return that there was a substring
// match.
//
// f) If the word was not entirely lowercase, then attempt a camel cased match as
// e) If the word was not entirely lowercase, then attempt a camel cased match as
// well.
//
// Only if all words have some sort of match is the pattern considered matched.