Merge pull request #2111 from Microsoft/navToPatternMatcher

Move NavigateTo over to using the new pattern matcher.
This commit is contained in:
CyrusNajmabadi 2015-02-23 16:01:23 -08:00
commit 5141f1d4c9
18 changed files with 260 additions and 153 deletions

View file

@ -229,6 +229,7 @@ module ts.server {
kind: entry.kind,
kindModifiers: entry.kindModifiers,
matchKind: entry.matchKind,
isCaseSensitive: entry.isCaseSensitive,
fileName: fileName,
textSpan: ts.createTextSpanFromBounds(start, end)
};

View file

@ -711,6 +711,11 @@ declare module ts.server.protocol {
* exact, substring, or prefix.
*/
matchKind?: string;
/**
* If this was a case sensitive or insensitive match.
*/
isCaseSensitive?: boolean;
/**
* Optional modifiers for the kind (such as 'public').

View file

@ -1,35 +1,46 @@
module ts.NavigateTo {
type RawNavigateToItem = { name: string; fileName: string; matchKind: MatchKind; declaration: Declaration };
enum MatchKind {
none = 0,
exact = 1,
substring = 2,
prefix = 3
}
export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[]{
// Split search value in terms array
var terms = searchValue.split(" ");
// default NavigateTo approach: if search term contains only lower-case chars - use case-insensitive search, otherwise switch to case-sensitive version
var searchTerms = map(terms, t => ({ caseSensitive: hasAnyUpperCaseCharacter(t), term: t }));
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[] {
var patternMatcher = createPatternMatcher(searchValue);
var rawItems: RawNavigateToItem[] = [];
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
forEach(program.getSourceFiles(), sourceFile => {
cancellationToken.throwIfCancellationRequested();
var fileName = sourceFile.fileName;
var declarations = sourceFile.getNamedDeclarations();
for (var i = 0, n = declarations.length; i < n; i++) {
var declaration = declarations[i];
// TODO(jfreeman): Skip this declaration if it has a computed name
var name = (<Identifier>declaration.name).text;
var matchKind = getMatchKind(searchTerms, name);
if (matchKind !== MatchKind.none) {
rawItems.push({ name, fileName, matchKind, declaration });
var name = getDeclarationName(declaration);
if (name !== undefined) {
// First do a quick check to see if the name of the declaration matches the
// last portion of the (possibly) dotted name they're searching for.
var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name);
if (!matches) {
continue;
}
// It was a match! If the pattern has dots in it, then also see if hte
// declaration container matches as well.
if (patternMatcher.patternContainsDots) {
var containers = getContainers(declaration);
if (!containers) {
return undefined;
}
matches = patternMatcher.getMatches(containers, name);
if (!matches) {
continue;
}
}
var fileName = sourceFile.fileName;
var matchKind = bestMatchKind(matches);
rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration });
}
}
});
@ -43,6 +54,129 @@ module ts.NavigateTo {
return items;
function allMatchesAreCaseSensitive(matches: PatternMatch[]): boolean {
Debug.assert(matches.length > 0);
// This is a case sensitive match, only if all the submatches were case sensitive.
for (var i = 0, n = matches.length; i < n; i++) {
if (!matches[i].isCaseSensitive) {
return false;
}
}
return true;
}
function getDeclarationName(declaration: Declaration): string {
var result = getTextOfIdentifierOrLiteral(declaration.name);
if (result !== undefined) {
return result;
}
if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
var expr = (<ComputedPropertyName>declaration.name).expression;
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
return (<PropertyAccessExpression>expr).name.text;
}
return getTextOfIdentifierOrLiteral(expr);
}
return undefined;
}
function getTextOfIdentifierOrLiteral(node: Node) {
if (node.kind === SyntaxKind.Identifier ||
node.kind === SyntaxKind.StringLiteral ||
node.kind === SyntaxKind.NumericLiteral) {
return (<Identifier | LiteralExpression>node).text;
}
return undefined;
}
function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]) {
if (declaration && declaration.name) {
var text = getTextOfIdentifierOrLiteral(declaration.name);
if (text !== undefined) {
containers.unshift(text);
}
else if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
return tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion:*/ true);
}
else {
// Don't know how to add this.
return false
}
}
return true;
}
// Only added the names of computed properties if they're simple dotted expressions, like:
//
// [X.Y.Z]() { }
function tryAddComputedPropertyName(expression: Expression, containers: string[], includeLastPortion: boolean): boolean {
var text = getTextOfIdentifierOrLiteral(expression);
if (text !== undefined) {
if (includeLastPortion) {
containers.unshift(text);
}
return true;
}
if (expression.kind === SyntaxKind.PropertyAccessExpression) {
var propertyAccess = <PropertyAccessExpression>expression;
if (includeLastPortion) {
containers.unshift(propertyAccess.name.text);
}
return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion:*/ true);
}
return false;
}
function getContainers(declaration: Declaration) {
var containers: string[] = [];
// First, if we started with a computed property name, then add all but the last
// portion into the container array.
if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
if (!tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion:*/ false)) {
return undefined;
}
}
// Now, walk up our containers, adding all their names to the container array.
declaration = getContainerNode(declaration);
while (declaration) {
if (!tryAddSingleDeclarationName(declaration, containers)) {
return undefined;
}
declaration = getContainerNode(declaration);
}
return containers;
}
function bestMatchKind(matches: PatternMatch[]) {
Debug.assert(matches.length > 0);
var bestMatchKind = PatternMatchKind.camelCase;
for (var i = 0, n = matches.length; i < n; i++) {
var kind = matches[i].kind;
if (kind < bestMatchKind) {
bestMatchKind = kind;
}
}
return bestMatchKind;
}
// This means "compare in a case insensitive manner."
var baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
function compareNavigateToItems(i1: RawNavigateToItem, i2: RawNavigateToItem) {
@ -62,7 +196,8 @@ module ts.NavigateTo {
name: rawItem.name,
kind: getNodeKind(declaration),
kindModifiers: getNodeModifiers(declaration),
matchKind: MatchKind[rawItem.matchKind],
matchKind: PatternMatchKind[rawItem.matchKind],
isCaseSensitive: rawItem.isCaseSensitive,
fileName: rawItem.fileName,
textSpan: createTextSpanFromBounds(declaration.getStart(), declaration.getEnd()),
// TODO(jfreeman): What should be the containerName when the container has a computed name?
@ -70,48 +205,5 @@ module ts.NavigateTo {
containerKind: container && container.name ? getNodeKind(container) : ""
};
}
function hasAnyUpperCaseCharacter(s: string): boolean {
for (var i = 0, n = s.length; i < n; i++) {
var c = s.charCodeAt(i);
if ((CharacterCodes.A <= c && c <= CharacterCodes.Z) ||
(c >= CharacterCodes.maxAsciiCharacter && s.charAt(i).toLocaleLowerCase() !== s.charAt(i))) {
return true;
}
}
return false;
}
function getMatchKind(searchTerms: { caseSensitive: boolean; term: string }[], name: string): MatchKind {
var matchKind = MatchKind.none;
if (name) {
for (var j = 0, n = searchTerms.length; j < n; j++) {
var searchTerm = searchTerms[j];
var nameToSearch = searchTerm.caseSensitive ? name : name.toLocaleLowerCase();
// in case of case-insensitive search searchTerm.term will already be lower-cased
var index = nameToSearch.indexOf(searchTerm.term);
if (index < 0) {
// Didn't match.
return MatchKind.none;
}
var termKind = MatchKind.substring;
if (index === 0) {
// here we know that match occur at the beginning of the string.
// if search term and declName has the same length - we have an exact match, otherwise declName have longer length and this will be prefix match
termKind = name.length === searchTerm.term.length ? MatchKind.exact : MatchKind.prefix;
}
// Update our match kind if we don't have one, or if this match is better.
if (matchKind === MatchKind.none || termKind < matchKind) {
matchKind = termKind;
}
}
}
return matchKind;
}
}
}

View file

@ -1,10 +1,10 @@
module ts {
// Note(cyrusn): this enum is ordered from strongest match type to weakest match type.
export enum PatternMatchKind {
Exact,
Prefix,
Substring,
CamelCase
exact,
prefix,
substring,
camelCase
}
// Information about a match made by the pattern matcher between a candidate and the
@ -46,7 +46,7 @@ module ts {
// Fully checks a candidate, with an dotted container, against the search pattern.
// The candidate must match the last part of the search pattern, and the dotted container
// must match the preceding segments of the pattern.
getMatches(candidate: string, dottedContainer: string): PatternMatch[];
getMatches(candidateContainers: string[], candidate: string): PatternMatch[];
// Whether or not the pattern contained dots or not. Clients can use this to determine
// If they should call getMatches, or if getMatchesForLastSegmentOfPattern is sufficient.
@ -139,7 +139,7 @@ module ts {
return matchSegment(candidate, lastOrUndefined(dotSeparatedSegments));
}
function getMatches(candidate: string, dottedContainer: string): PatternMatch[] {
function getMatches(candidateContainers: string[], candidate: string): PatternMatch[] {
if (skipMatch(candidate)) {
return undefined;
}
@ -152,27 +152,26 @@ module ts {
return undefined;
}
dottedContainer = dottedContainer || "";
var containerParts = dottedContainer.split(".");
candidateContainers = candidateContainers || [];
// -1 because the last part was checked against the name, and only the rest
// of the parts are checked against the container.
if (dotSeparatedSegments.length - 1 > containerParts.length) {
if (dotSeparatedSegments.length - 1 > candidateContainers.length) {
// There weren't enough container parts to match against the pattern parts.
// So this definitely doesn't match.
return null;
return undefined;
}
// So far so good. Now break up the container for the candidate and check if all
// the dotted parts match up correctly.
var totalMatch = candidateMatch;
for (var i = dotSeparatedSegments.length - 2, j = containerParts.length - 1;
for (var i = dotSeparatedSegments.length - 2, j = candidateContainers.length - 1;
i >= 0;
i--, j--) {
var segment = dotSeparatedSegments[i];
var containerName = containerParts[j];
var containerName = candidateContainers[j];
var containerMatch = matchSegment(containerName, segment);
if (!containerMatch) {
@ -202,12 +201,12 @@ module ts {
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, punctuationStripped, /*isCaseSensitive:*/ candidate === chunk.text);
return createPatternMatch(PatternMatchKind.exact, punctuationStripped, /*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, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text));
}
}
@ -225,7 +224,7 @@ module ts {
for (var i = 0, n = wordSpans.length; i < n; i++) {
var span = wordSpans[i]
if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) {
return createPatternMatch(PatternMatchKind.Substring, punctuationStripped,
return createPatternMatch(PatternMatchKind.substring, punctuationStripped,
/*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
}
}
@ -236,7 +235,7 @@ module ts {
// 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, punctuationStripped, /*isCaseSensitive:*/ true);
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ true);
}
}
@ -246,12 +245,12 @@ module ts {
var candidateParts = getWordSpans(candidate);
var camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false);
if (camelCaseWeight !== undefined) {
return createPatternMatch(PatternMatchKind.CamelCase, punctuationStripped, /*isCaseSensitive:*/ true, /*camelCaseWeight:*/ camelCaseWeight);
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ true, /*camelCaseWeight:*/ camelCaseWeight);
}
camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ true);
if (camelCaseWeight !== undefined) {
return createPatternMatch(PatternMatchKind.CamelCase, punctuationStripped, /*isCaseSensitive:*/ false, /*camelCaseWeight:*/ camelCaseWeight);
return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ false, /*camelCaseWeight:*/ camelCaseWeight);
}
}
}
@ -266,7 +265,7 @@ module ts {
// (Pattern: fogbar, Candidate: quuxfogbarFogBar).
if (chunk.text.length < candidate.length) {
if (index > 0 && isUpperCaseLetter(candidate.charCodeAt(index))) {
return createPatternMatch(PatternMatchKind.Substring, punctuationStripped, /*isCaseSensitive:*/ false);
return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ false);
}
}
}
@ -508,7 +507,7 @@ module ts {
}
function compareCamelCase(result1: PatternMatch, result2: PatternMatch) {
if (result1.kind === PatternMatchKind.CamelCase && result2.kind === PatternMatchKind.CamelCase) {
if (result1.kind === PatternMatchKind.camelCase && result2.kind === PatternMatchKind.camelCase) {
// Swap the values here. If result1 has a higher weight, then we want it to come
// first.
return result2.camelCaseWeight - result1.camelCaseWeight;

View file

@ -970,6 +970,7 @@ module ts {
kind: string;
kindModifiers: string;
matchKind: string;
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;
@ -1957,7 +1958,7 @@ module ts {
});
}
/* @internal */ export function getContainerNode(node: Node): Node {
/* @internal */ export function getContainerNode(node: Node): Declaration {
while (true) {
node = node.parent;
if (!node) {
@ -1975,7 +1976,7 @@ module ts {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
return node;
return <Declaration>node;
}
}
}

View file

@ -1639,6 +1639,7 @@ declare module "typescript" {
kind: string;
kindModifiers: string;
matchKind: string;
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;

View file

@ -5314,6 +5314,9 @@ declare module "typescript" {
matchKind: string;
>matchKind : string
isCaseSensitive: boolean;
>isCaseSensitive : boolean
fileName: string;
>fileName : string

View file

@ -1670,6 +1670,7 @@ declare module "typescript" {
kind: string;
kindModifiers: string;
matchKind: string;
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;

View file

@ -5460,6 +5460,9 @@ declare module "typescript" {
matchKind: string;
>matchKind : string
isCaseSensitive: boolean;
>isCaseSensitive : boolean
fileName: string;
>fileName : string

View file

@ -1671,6 +1671,7 @@ declare module "typescript" {
kind: string;
kindModifiers: string;
matchKind: string;
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;

View file

@ -5410,6 +5410,9 @@ declare module "typescript" {
matchKind: string;
>matchKind : string
isCaseSensitive: boolean;
>isCaseSensitive : boolean
fileName: string;
>fileName : string

View file

@ -1708,6 +1708,7 @@ declare module "typescript" {
kind: string;
kindModifiers: string;
matchKind: string;
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;

View file

@ -5583,6 +5583,9 @@ declare module "typescript" {
matchKind: string;
>matchKind : string
isCaseSensitive: boolean;
>isCaseSensitive : boolean
fileName: string;
>fileName : string

View file

@ -4,4 +4,4 @@
goTo.marker();
//verify there is no empty navigation item.
verify.navigationItemsListCount(0, "^$"/*empty string*/)
verify.navigationItemsListCount(0, "")

View file

@ -1,28 +1,26 @@
/// <reference path="fourslash.ts"/>
/////// Module
////{| "itemName": "Shapes", "kind": "module", "parentName": "", "matchKind": "substring" |}module Shapes {
////{| "itemName": "MyShapes", "kind": "module", "parentName": "", "matchKind": "substring" |}module MyShapes {
////
//// // Class
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes", "matchKind": "substring" |}export class Point {
//// {| "itemName": "MyPoint", "kind": "class", "parentName": "MyShapes", "matchKind": "substring" |}export class MyPoint {
//// // Instance member
//// {| "itemName": "originPointAttheHorizon", "kind": "property", "parentName": "Point", "matchKind": "substring"|}private originPointAttheHorizon = 0.0;
//// {| "itemName": "MyoriginPointAttheHorizon", "kind": "property", "parentName": "MyPoint", "matchKind": "substring"|}private MyoriginPointAttheHorizon = 0.0;
////
//// // Getter
//// {| "itemName": "distanceFromOrigin", "kind": "getter", "parentName": "Point", "matchKind": "substring" |}get distanceFromOrigin(): number { return 0; }
//// {| "itemName": "MydistanceFromOrigin", "kind": "getter", "parentName": "MyPoint", "matchKind": "substring" |}get MydistanceFromOrigin(): number { return 0; }
////
//// }
////}
////
////// Local variables
////{| "itemName": "myPointThatIJustInitiated", "kind": "var", "parentName": "", "matchKind": "substring"|}var myPointThatIJustInitiated = new Shapes.Point();
//// Testing for substring matching of navigationItems
//var searchValue = "FromOrigin horizon INITIATED Shape Point";
////{| "itemName": "MymyPointThatIJustInitiated", "kind": "var", "parentName": "", "matchKind": "substring"|}var MymyPointThatIJustInitiated = new Shapes.Point();
debugger;
test.markers().forEach((marker) => {
if (marker.data) {
var name = marker.data.itemName;
verify.navigationItemsListContains(name, marker.data.kind, name.substr(1), marker.data.matchKind, marker.fileName, marker.data.parentName);
verify.navigationItemsListContains(name, marker.data.kind, name.substr(2), marker.data.matchKind, marker.fileName, marker.data.parentName);
}
});

View file

@ -17,12 +17,12 @@
//// INITIATED123;
//// public horizon(): void;
////}
debugger;
var notFoundSearchValue = "mPointThatIJustInitiated wrongKeyWord";
goTo.marker("file1");
// case sensitive matching for 'Horizon' will fail
verify.navigationItemsListCount(0, "Horizon", "exact");
verify.navigationItemsListCount(1, "Horizon", "exact");
// case insensitive matching will find 'horizon'
verify.navigationItemsListCount(1, "horizon", "exact");
// case sensitive matching will find 'Distance' and INITIATED

View file

@ -1,15 +1,15 @@
/// <reference path="fourslash.ts"/>
/////// Module
////{| "itemName": "Shapes", "kind": "module", "parentName": "", "matchKind": "substring" |}module Shapes {
////{| "itemName": "MyShapes", "kind": "module", "parentName": "", "matchKind": "substring" |}module MyShapes {
////
//// // Class
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes", "matchKind": "substring" |}export class Point {
//// {| "itemName": "MyPoint", "kind": "class", "parentName": "MyShapes", "matchKind": "substring" |}export class MyPoint {
//// // Instance member
//// {| "itemName": "originPointAttheHorizon", "kind": "property", "parentName": "Point", "matchKind": "substring"|}private originPointAttheHorizon = 0.0;
//// {| "itemName": "MyoriginPointAttheHorizon", "kind": "property", "parentName": "MyPoint", "matchKind": "substring"|}private MyoriginPointAttheHorizon = 0.0;
////
//// // Getter
//// {| "itemName": "distanceFromOrigin", "kind": "getter", "parentName": "Point", "matchKind": "substring" |}get distanceFromOrigin(): number { return 0; }
//// {| "itemName": "MydistanceFromOrigin", "kind": "getter", "parentName": "MyPoint", "matchKind": "substring" |}get MydistanceFromOrigin(): number { return 0; }
////
//// }
////}
@ -23,6 +23,6 @@
test.markers().forEach((marker) => {
if (marker.data) {
var name = marker.data.itemName;
verify.navigationItemsListContains(name, marker.data.kind, name.substr(1), marker.data.matchKind, marker.fileName, marker.data.parentName);
verify.navigationItemsListContains(name, marker.data.kind, name.substr(2), marker.data.matchKind, marker.fileName, marker.data.parentName);
}
});

View file

@ -96,39 +96,37 @@ describe('PatternMatcher', function () {
describe("SingleWordPattern", () => {
it("PreferCaseSensitiveExact", () => {
debugger;
var match = getFirstMatch("Foo", "Foo");
assert.equal(ts.PatternMatchKind.Exact, match.kind);
assert.equal(ts.PatternMatchKind.exact, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitiveExactInsensitive", () => {
var match = getFirstMatch("foo", "Foo");
assert.equal(ts.PatternMatchKind.Exact, match.kind);
assert.equal(ts.PatternMatchKind.exact, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitivePrefix", () => {
var match = getFirstMatch("Foo", "Fo");
assert.equal(ts.PatternMatchKind.Prefix, match.kind);
assert.equal(ts.PatternMatchKind.prefix, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitivePrefixCaseInsensitive", () => {
var match = getFirstMatch("Foo", "fo");
assert.equal(ts.PatternMatchKind.Prefix, match.kind);
assert.equal(ts.PatternMatchKind.prefix, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitiveCamelCaseMatchSimple", () => {
debugger;
var match = getFirstMatch("FogBar", "FB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
assertInRange(match.camelCaseWeight, 1, 1 << 30);
});
@ -136,7 +134,7 @@ describe('PatternMatcher', function () {
it("PreferCaseSensitiveCamelCaseMatchPartialPattern", () => {
var match = getFirstMatch("FogBar", "FoB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
@ -167,57 +165,56 @@ describe('PatternMatcher', function () {
it("TwoUppercaseCharacters", () => {
var match = getFirstMatch("SimpleUIElement", "SiUI");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitiveLowercasePattern", () => {
debugger;
var match = getFirstMatch("FogBar", "b");
assert.equal(ts.PatternMatchKind.Substring, match.kind);
assert.equal(ts.PatternMatchKind.substring, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitiveLowercasePattern2", () => {
var match = getFirstMatch("FogBar", "fB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitiveTryUnderscoredName", () => {
var match = getFirstMatch("_fogBar", "_fB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitiveTryUnderscoredName2", () => {
var match = getFirstMatch("_fogBar", "fB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitiveTryUnderscoredNameInsensitive", () => {
var match = getFirstMatch("_FogBar", "_fB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitiveMiddleUnderscore", () => {
var match = getFirstMatch("Fog_Bar", "FB");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("PreferCaseSensitiveMiddleUnderscore2", () => {
var match = getFirstMatch("Fog_Bar", "F_B");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(true, match.isCaseSensitive);
});
@ -230,14 +227,14 @@ describe('PatternMatcher', function () {
it("PreferCaseSensitiveMiddleUnderscore4", () => {
var match = getFirstMatch("Fog_Bar", "f_B");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(false, match.isCaseSensitive);
});
it("PreferCaseSensitiveMiddleUnderscore5", () => {
var match = getFirstMatch("Fog_Bar", "F_b");
assert.equal(ts.PatternMatchKind.CamelCase, match.kind);
assert.equal(ts.PatternMatchKind.camelCase, match.kind);
assert.equal(false, match.isCaseSensitive);
});
@ -266,7 +263,6 @@ describe('PatternMatcher', function () {
});
it("AllLowerPattern1", () => {
debugger;
var match = getFirstMatch("FogBarChangedEventArgs", "changedeventargs");
assert.isTrue(undefined !== match);
@ -295,81 +291,81 @@ describe('PatternMatcher', function () {
it("ExactWithLowercase", () => {
var matches = getAllMatches("AddMetadataReference", "addmetadatareference");
assertContainsKind(ts.PatternMatchKind.Exact, matches);
assertContainsKind(ts.PatternMatchKind.exact, matches);
});
it("SingleLowercasedSearchWord1", () => {
var matches = getAllMatches("AddMetadataReference", "add");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
});
it("SingleLowercasedSearchWord2", () => {
var matches = getAllMatches("AddMetadataReference", "metadata");
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("SingleUppercaseSearchWord1", () => {
var matches = getAllMatches("AddMetadataReference", "Add");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
});
it("SingleUppercaseSearchWord2", () => {
var matches = getAllMatches("AddMetadataReference", "Metadata");
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("SingleUppercaseSearchLetter1", () => {
var matches = getAllMatches("AddMetadataReference", "A");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
});
it("SingleUppercaseSearchLetter2", () => {
var matches = getAllMatches("AddMetadataReference", "M");
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("TwoLowercaseWords", () => {
var matches = getAllMatches("AddMetadataReference", "add metadata");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("TwoLowercaseWords", () => {
var matches = getAllMatches("AddMetadataReference", "A M");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("TwoLowercaseWords", () => {
var matches = getAllMatches("AddMetadataReference", "AM");
assertContainsKind(ts.PatternMatchKind.CamelCase, matches);
assertContainsKind(ts.PatternMatchKind.camelCase, matches);
});
it("TwoLowercaseWords", () => {
var matches = getAllMatches("AddMetadataReference", "ref Metadata")
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.Substring, ts.PatternMatchKind.Substring]);
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.substring, ts.PatternMatchKind.substring]);
});
it("TwoLowercaseWords", () => {
var matches = getAllMatches("AddMetadataReference", "ref M")
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.Substring, ts.PatternMatchKind.Substring]);
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.substring, ts.PatternMatchKind.substring]);
});
it("MixedCamelCase", () => {
var matches = getAllMatches("AddMetadataReference", "AMRe");
assertContainsKind(ts.PatternMatchKind.CamelCase, matches);
assertContainsKind(ts.PatternMatchKind.camelCase, matches);
});
it("BlankPattern", () => {
@ -387,22 +383,22 @@ describe('PatternMatcher', function () {
it("EachWordSeparately1", () => {
var matches = getAllMatches("AddMetadataReference", "add Meta");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("EachWordSeparately2", () => {
var matches = getAllMatches("AddMetadataReference", "Add meta");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("EachWordSeparately3", () => {
var matches = getAllMatches("AddMetadataReference", "Add Meta");
assertContainsKind(ts.PatternMatchKind.Prefix, matches);
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.prefix, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
});
it("MixedCasing", () => {
@ -420,7 +416,7 @@ describe('PatternMatcher', function () {
it("AsteriskSplit", () => {
var matches = getAllMatches("GetKeyWord", "K*W");
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.Substring, ts.PatternMatchKind.Substring]);
assertArrayEquals(ts.map(matches, m => m.kind), [ts.PatternMatchKind.substring, ts.PatternMatchKind.substring]);
});
it("LowercaseSubstring1", () => {
@ -431,7 +427,7 @@ describe('PatternMatcher', function () {
it("LowercaseSubstring2", () => {
var matches = getAllMatches("FooAttribute", "a");
assertContainsKind(ts.PatternMatchKind.Substring, matches);
assertContainsKind(ts.PatternMatchKind.substring, matches);
assert.isFalse(matches[0].isCaseSensitive);
});
});
@ -440,7 +436,7 @@ describe('PatternMatcher', function () {
it("DottedPattern1", () => {
var match = getFirstMatchForDottedPattern("Foo.Bar.Baz", "Quux", "B.Q");
assert.equal(ts.PatternMatchKind.Prefix, match.kind);
assert.equal(ts.PatternMatchKind.prefix, match.kind);
assert.equal(true, match.isCaseSensitive);
});
@ -451,19 +447,19 @@ describe('PatternMatcher', function () {
it("DottedPattern3", () => {
var match = getFirstMatchForDottedPattern("Foo.Bar.Baz", "Quux", "B.B.Q");
assert.equal(ts.PatternMatchKind.Prefix, match.kind);
assert.equal(ts.PatternMatchKind.prefix, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("DottedPattern4", () => {
var match = getFirstMatchForDottedPattern("Foo.Bar.Baz", "Quux", "Baz.Quux");
assert.equal(ts.PatternMatchKind.Exact, match.kind);
assert.equal(ts.PatternMatchKind.exact, match.kind);
assert.equal(true, match.isCaseSensitive);
});
it("DottedPattern5", () => {
var match = getFirstMatchForDottedPattern("Foo.Bar.Baz", "Quux", "F.B.B.Quux");
assert.equal(ts.PatternMatchKind.Exact, match.kind);
assert.equal(ts.PatternMatchKind.exact, match.kind);
assert.equal(true, match.isCaseSensitive);
});
@ -473,7 +469,6 @@ describe('PatternMatcher', function () {
});
it("DottedPattern7", () => {
debugger;
var match = getFirstMatch("UIElement", "UIElement");
var match = getFirstMatch("GetKeyword", "UIElement");
assert.isTrue(match === undefined);
@ -490,7 +485,7 @@ describe('PatternMatcher', function () {
}
function getFirstMatchForDottedPattern(dottedContainer: string, candidate: string, pattern: string): ts.PatternMatch {
var matches = ts.createPatternMatcher(pattern).getMatches(candidate, dottedContainer);
var matches = ts.createPatternMatcher(pattern).getMatches(dottedContainer.split("."), candidate);
return matches ? matches[0] : undefined;
}