Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit cbadc78

Browse files
authored
Return all symbols in navto for empty string pattern (microsoft#55550)
1 parent fe82a61 commit cbadc78

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

src/harness/fourslashImpl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,8 @@ export class TestState {
37663766

37673767
public verifyNavigateTo(options: readonly FourSlashInterface.VerifyNavigateToOptions[]): void {
37683768
for (const { pattern, expected, fileName } of options) {
3769-
const items = this.languageService.getNavigateToItems(pattern, /*maxResultCount*/ undefined, fileName);
3769+
const file = fileName && this.findFile(fileName).fileName;
3770+
const items = this.languageService.getNavigateToItems(pattern, /*maxResultCount*/ undefined, file);
37703771
this.assertObjectsEqual(
37713772
items,
37723773
expected.map((e): ts.NavigateToItem => ({

src/services/patternMatcher.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ export function createPatternMatcher(pattern: string): PatternMatcher | undefine
121121
const stringToWordSpans = new Map<string, TextSpan[]>();
122122

123123
const dotSeparatedSegments = pattern.trim().split(".").map(p => createSegment(p.trim()));
124+
125+
// The pattern is an empty string, and it matches everything.
126+
if (dotSeparatedSegments.length === 1 && dotSeparatedSegments[0].totalTextChunk.text === "") {
127+
return {
128+
getMatchForLastSegmentOfPattern: () => createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive*/ true),
129+
getFullMatch: () => createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive*/ true),
130+
patternContainsDots: false,
131+
};
132+
}
124133
// A segment is considered invalid if we couldn't find any words in it.
125134
if (dotSeparatedSegments.some(segment => !segment.subWordTextChunks.length)) return undefined;
126135

src/testRunner/unittests/services/patternMatcher.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,6 @@ describe("unittests:: services:: PatternMatcher", () => {
248248
assertSegmentMatch("AddMetadataReference", "AMRe", { kind: ts.PatternMatchKind.camelCase, isCaseSensitive: true });
249249
});
250250

251-
it("BlankPattern", () => {
252-
assertInvalidPattern("");
253-
});
254-
255-
it("WhitespaceOnlyPattern", () => {
256-
assertInvalidPattern(" ");
257-
});
258-
259251
it("EachWordSeparately1", () => {
260252
assertSegmentMatch("AddMetadataReference", "add Meta", { kind: ts.PatternMatchKind.prefix, isCaseSensitive: false });
261253
});
@@ -324,10 +316,6 @@ describe("unittests:: services:: PatternMatcher", () => {
324316
assert.deepEqual(ts.createPatternMatcher(pattern)!.getMatchForLastSegmentOfPattern(candidate), expected);
325317
}
326318

327-
function assertInvalidPattern(pattern: string) {
328-
assert.equal(ts.createPatternMatcher(pattern), undefined);
329-
}
330-
331319
function assertFullMatch(dottedContainer: string, candidate: string, pattern: string, expected: ts.PatternMatch | undefined): void {
332320
assert.deepEqual(ts.createPatternMatcher(pattern)!.getFullMatch(dottedContainer.split("."), candidate), expected);
333321
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path="fourslash.ts" />
22

3+
// @filename: index.ts
34
////declare function
45

5-
verify.navigateTo({ pattern: "", expected: [] });
6+
verify.navigateTo({ pattern: "", fileName: "index.ts", expected: [] });

tests/cases/fourslash/incorrectJsDocObjectLiteralType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @Filename: /a.ts
44
////
55

6-
verify.navigateTo({ pattern: "", expected: [] });
6+
verify.navigateTo({ pattern: "", fileName: "/a.ts", expected: [] });
77
edit.insert("/**\n * @typedef {Object} foo\n * @property {any} [obj]\n */\nexport default function foo() {\n}");
88
verify.navigateTo({
99
pattern: "foo",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @filename: foo.ts
4+
//// const [|x: number = 1|];
5+
//// [|function y(x: string): string { return x; }|]
6+
7+
8+
const [x, y] = test.ranges();
9+
10+
verify.navigateTo({
11+
pattern: "",
12+
fileName: "foo.ts",
13+
expected: [{
14+
name: "x",
15+
kind: "const",
16+
range: x,
17+
matchKind: "substring",
18+
},
19+
{
20+
name: "y",
21+
kind: "function",
22+
range: y,
23+
matchKind: "substring",
24+
}],
25+
});

0 commit comments

Comments
 (0)