Skip to content

Commit 302cea8

Browse files
author
Andy
authored
Merge pull request microsoft#9054 from Microsoft/quick_info_meaning
Use proper method of not resolving alias
2 parents 512c671 + 5e72b8a commit 302cea8

4 files changed

Lines changed: 72 additions & 11 deletions

File tree

src/compiler/checker.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16883,10 +16883,7 @@ namespace ts {
1688316883
return getIntrinsicTagSymbol(<JsxOpeningLikeElement>entityName.parent);
1688416884
}
1688516885

16886-
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
16887-
// return the alias symbol.
16888-
const meaning: SymbolFlags = SymbolFlags.Value | SymbolFlags.Alias;
16889-
return resolveEntityName(<Identifier>entityName, meaning);
16886+
return resolveEntityName(<Identifier>entityName, SymbolFlags.Value, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
1689016887
}
1689116888
else if (entityName.kind === SyntaxKind.PropertyAccessExpression) {
1689216889
const symbol = getNodeLinks(entityName).resolvedSymbol;
@@ -16904,11 +16901,8 @@ namespace ts {
1690416901
}
1690516902
}
1690616903
else if (isTypeReferenceIdentifier(<EntityName>entityName)) {
16907-
let meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace;
16908-
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
16909-
// return the alias symbol.
16910-
meaning |= SymbolFlags.Alias;
16911-
return resolveEntityName(<EntityName>entityName, meaning);
16904+
const meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace;
16905+
return resolveEntityName(<EntityName>entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/true);
1691216906
}
1691316907
else if (entityName.parent.kind === SyntaxKind.JsxAttribute) {
1691416908
return getJsxAttributePropertySymbol(<JsxAttribute>entityName.parent);

tests/baselines/reference/typeReferenceDirectives13.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface A {
88

99
x: () => typeof $
1010
>x : Symbol(A.x, Decl(app.ts, 2, 20))
11-
>$ : Symbol($, Decl(app.ts, 1, 8))
11+
>$ : Symbol($, Decl(index.d.ts, 0, 11))
1212
}
1313

1414
=== /ref.d.ts ===

tests/baselines/reference/typeReferenceDirectives5.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface A {
88

99
x: typeof $;
1010
>x : Symbol(A.x, Decl(app.ts, 2, 20))
11-
>$ : Symbol($, Decl(app.ts, 1, 8))
11+
>$ : Symbol($, Decl(index.d.ts, 0, 11))
1212
}
1313
=== /ref.d.ts ===
1414

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// Testing that quickInfo gets information with a corresponding meaning: values to values, types to types.
4+
// For quick info purposes, we don't resolve past aliases.
5+
// However, when we have an alias for a type, the quickInfo for a value with the same should skip the alias, and vice versa.
6+
// goToDefinition should work the same way.
7+
8+
// @Filename: foo.d.ts
9+
////declare const /*foo_value_declaration*/foo: number;
10+
////declare module "foo_module" {
11+
//// interface I { x: number; y: number }
12+
//// export = I;
13+
////}
14+
15+
// @Filename: foo_user.ts
16+
///////<reference path="foo.d.ts" />
17+
/////*foo_type_declaration*/import foo = require("foo_module");
18+
////const x = foo/*foo_value*/;
19+
////const i: foo/*foo_type*/ = { x: 1, y: 2 };
20+
21+
verify.numberOfErrorsInCurrentFile(0);
22+
23+
verify.navigationItemsListCount(2, "foo", "exact");
24+
verify.navigationItemsListContains("foo", "alias", "foo", "exact");
25+
verify.navigationItemsListContains("foo", "const", "foo", "exact");
26+
27+
goTo.marker("foo_value");
28+
verify.quickInfoIs("const foo: number");
29+
goTo.definition();
30+
verify.caretAtMarker("foo_value_declaration");
31+
32+
goTo.marker("foo_type");
33+
verify.quickInfoIs("import foo = require(\"foo_module\")");
34+
goTo.definition();
35+
verify.caretAtMarker("foo_type_declaration");
36+
37+
38+
// Above tested for global const and imported interface. Now test with global interface and imported const.
39+
40+
41+
// @Filename: bar.d.ts
42+
/////*bar_type_declaration*/declare interface bar { x: number; y: number }
43+
////declare module "bar_module" {
44+
//// const x: number;
45+
//// export = x;
46+
////}
47+
48+
// @Filename: bar_user.ts
49+
///////<reference path="bar.d.ts" />
50+
/////*bar_value_declaration*/import bar = require("bar_module");
51+
////const x = bar/*bar_value*/;
52+
////const i: bar/*bar_type*/ = { x: 1, y: 2 };
53+
54+
verify.numberOfErrorsInCurrentFile(0);
55+
verify.navigationItemsListCount(2, "bar", "exact");
56+
verify.navigationItemsListContains("bar", "alias", "bar", "exact");
57+
verify.navigationItemsListContains("bar", "interface", "bar", "exact");
58+
59+
goTo.marker("bar_value");
60+
verify.quickInfoIs("import bar = require(\"bar_module\")");
61+
goTo.definition();
62+
verify.caretAtMarker("bar_value_declaration");
63+
64+
goTo.marker("bar_type");
65+
verify.quickInfoIs("interface bar");
66+
goTo.definition();
67+
verify.caretAtMarker("bar_type_declaration");

0 commit comments

Comments
 (0)