mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 05:55:11 -05:00
Return all symbols in navto for empty string pattern (#55550)
This commit is contained in:
committed by
GitHub
parent
fe82a610cd
commit
cbadc78f96
@@ -3766,7 +3766,8 @@ export class TestState {
|
||||
|
||||
public verifyNavigateTo(options: readonly FourSlashInterface.VerifyNavigateToOptions[]): void {
|
||||
for (const { pattern, expected, fileName } of options) {
|
||||
const items = this.languageService.getNavigateToItems(pattern, /*maxResultCount*/ undefined, fileName);
|
||||
const file = fileName && this.findFile(fileName).fileName;
|
||||
const items = this.languageService.getNavigateToItems(pattern, /*maxResultCount*/ undefined, file);
|
||||
this.assertObjectsEqual(
|
||||
items,
|
||||
expected.map((e): ts.NavigateToItem => ({
|
||||
|
||||
@@ -121,6 +121,15 @@ export function createPatternMatcher(pattern: string): PatternMatcher | undefine
|
||||
const stringToWordSpans = new Map<string, TextSpan[]>();
|
||||
|
||||
const dotSeparatedSegments = pattern.trim().split(".").map(p => createSegment(p.trim()));
|
||||
|
||||
// The pattern is an empty string, and it matches everything.
|
||||
if (dotSeparatedSegments.length === 1 && dotSeparatedSegments[0].totalTextChunk.text === "") {
|
||||
return {
|
||||
getMatchForLastSegmentOfPattern: () => createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive*/ true),
|
||||
getFullMatch: () => createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive*/ true),
|
||||
patternContainsDots: false,
|
||||
};
|
||||
}
|
||||
// A segment is considered invalid if we couldn't find any words in it.
|
||||
if (dotSeparatedSegments.some(segment => !segment.subWordTextChunks.length)) return undefined;
|
||||
|
||||
|
||||
@@ -248,14 +248,6 @@ describe("unittests:: services:: PatternMatcher", () => {
|
||||
assertSegmentMatch("AddMetadataReference", "AMRe", { kind: ts.PatternMatchKind.camelCase, isCaseSensitive: true });
|
||||
});
|
||||
|
||||
it("BlankPattern", () => {
|
||||
assertInvalidPattern("");
|
||||
});
|
||||
|
||||
it("WhitespaceOnlyPattern", () => {
|
||||
assertInvalidPattern(" ");
|
||||
});
|
||||
|
||||
it("EachWordSeparately1", () => {
|
||||
assertSegmentMatch("AddMetadataReference", "add Meta", { kind: ts.PatternMatchKind.prefix, isCaseSensitive: false });
|
||||
});
|
||||
@@ -324,10 +316,6 @@ describe("unittests:: services:: PatternMatcher", () => {
|
||||
assert.deepEqual(ts.createPatternMatcher(pattern)!.getMatchForLastSegmentOfPattern(candidate), expected);
|
||||
}
|
||||
|
||||
function assertInvalidPattern(pattern: string) {
|
||||
assert.equal(ts.createPatternMatcher(pattern), undefined);
|
||||
}
|
||||
|
||||
function assertFullMatch(dottedContainer: string, candidate: string, pattern: string, expected: ts.PatternMatch | undefined): void {
|
||||
assert.deepEqual(ts.createPatternMatcher(pattern)!.getFullMatch(dottedContainer.split("."), candidate), expected);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: index.ts
|
||||
////declare function
|
||||
|
||||
verify.navigateTo({ pattern: "", expected: [] });
|
||||
verify.navigateTo({ pattern: "", fileName: "index.ts", expected: [] });
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @Filename: /a.ts
|
||||
////
|
||||
|
||||
verify.navigateTo({ pattern: "", expected: [] });
|
||||
verify.navigateTo({ pattern: "", fileName: "/a.ts", expected: [] });
|
||||
edit.insert("/**\n * @typedef {Object} foo\n * @property {any} [obj]\n */\nexport default function foo() {\n}");
|
||||
verify.navigateTo({
|
||||
pattern: "foo",
|
||||
|
||||
25
tests/cases/fourslash/navto_emptyPattern.ts
Normal file
25
tests/cases/fourslash/navto_emptyPattern.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @filename: foo.ts
|
||||
//// const [|x: number = 1|];
|
||||
//// [|function y(x: string): string { return x; }|]
|
||||
|
||||
|
||||
const [x, y] = test.ranges();
|
||||
|
||||
verify.navigateTo({
|
||||
pattern: "",
|
||||
fileName: "foo.ts",
|
||||
expected: [{
|
||||
name: "x",
|
||||
kind: "const",
|
||||
range: x,
|
||||
matchKind: "substring",
|
||||
},
|
||||
{
|
||||
name: "y",
|
||||
kind: "function",
|
||||
range: y,
|
||||
matchKind: "substring",
|
||||
}],
|
||||
});
|
||||
Reference in New Issue
Block a user