Skip to content

Commit b31d5b3

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into feature/eslint
2 parents 49f1a79 + 029f7a3 commit b31d5b3

10 files changed

+1109
-35
lines changed

src/services/goToDefinition.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace ts.GoToDefinition {
3939
return [sigInfo];
4040
}
4141
else {
42-
const defs = getDefinitionFromSymbol(typeChecker, symbol, node) || emptyArray;
42+
const defs = getDefinitionFromSymbol(typeChecker, symbol, node, calledDeclaration) || emptyArray;
4343
// For a 'super()' call, put the signature first, else put the variable first.
4444
return node.kind === SyntaxKind.SuperKeyword ? [sigInfo, ...defs] : [...defs, sigInfo];
4545
}
@@ -232,10 +232,11 @@ namespace ts.GoToDefinition {
232232
}
233233
}
234234

235-
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node): DefinitionInfo[] | undefined {
235+
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node, declarationNode?: Node): DefinitionInfo[] | undefined {
236236
// There are cases when you extend a function by adding properties to it afterwards,
237-
// we want to strip those extra properties
238-
const filteredDeclarations = filter(symbol.declarations, d => !isAssignmentDeclaration(d) || d === symbol.valueDeclaration) || undefined;
237+
// we want to strip those extra properties.
238+
// For deduping purposes, we also want to exclude any declarationNodes if provided.
239+
const filteredDeclarations = filter(symbol.declarations, d => d !== declarationNode && (!isAssignmentDeclaration(d) || d === symbol.valueDeclaration)) || undefined;
239240
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(filteredDeclarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
240241

241242
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
@@ -258,8 +259,13 @@ namespace ts.GoToDefinition {
258259
return undefined;
259260
}
260261
const declarations = signatureDeclarations.filter(selectConstructors ? isConstructorDeclaration : isFunctionLike);
262+
const declarationsWithBody = declarations.filter(d => !!(<FunctionLikeDeclaration>d).body);
263+
264+
// declarations defined on the global scope can be defined on multiple files. Get all of them.
261265
return declarations.length
262-
? [createDefinitionInfo(find(declarations, d => !!(<FunctionLikeDeclaration>d).body) || last(declarations), typeChecker, symbol, node)]
266+
? declarationsWithBody.length !== 0
267+
? declarationsWithBody.map(x => createDefinitionInfo(x, typeChecker, symbol, node))
268+
: [createDefinitionInfo(last(declarations), typeChecker, symbol, node)]
263269
: undefined;
264270
}
265271
}

src/services/navigationBar.ts

Lines changed: 236 additions & 18 deletions
Large diffs are not rendered by default.

tests/cases/fourslash/goToDefinitionAcrossMultipleProjects.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77
////var /*def2*/x: number;
88

99
//@Filename: c.ts
10+
////var /*def3*/x: number;
11+
12+
//@Filename: d.ts
13+
////var /*def4*/x: number;
14+
15+
//@Filename: e.ts
1016
/////// <reference path="a.ts" />
1117
/////// <reference path="b.ts" />
18+
/////// <reference path="c.ts" />
19+
/////// <reference path="d.ts" />
1220
////[|/*use*/x|]++;
1321

14-
verify.goToDefinition("use", ["def1", "def2"]);
22+
verify.goToDefinition("use", ["def1", "def2", "def3", "def4"]);

tests/cases/fourslash/navigationBarFunctionPrototype.ts

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,69 @@
33
// @Filename: foo.js
44
////function f() {}
55
////f.prototype.x = 0;
6+
////f.y = 0;
7+
////f.prototype.method = function () {};
8+
////Object.defineProperty(f, 'staticProp', {
9+
//// set: function() {},
10+
//// get: function(){
11+
//// }
12+
////});
13+
////Object.defineProperty(f.prototype, 'name', {
14+
//// set: function() {},
15+
//// get: function(){
16+
//// }
17+
////});
618

719
verify.navigationTree({
820
"text": "<global>",
921
"kind": "script",
1022
"childItems": [
1123
{
1224
"text": "f",
13-
"kind": "function"
14-
},
15-
{
16-
"text": "x",
17-
"kind": "property"
25+
"kind": "class",
26+
"childItems": [
27+
{
28+
"text": "constructor",
29+
"kind": "constructor"
30+
},
31+
{
32+
"text": "x",
33+
"kind": "property"
34+
},
35+
{
36+
"text": "y"
37+
},
38+
{
39+
"text": "method",
40+
"kind": "function"
41+
},
42+
{
43+
"text": "staticProp",
44+
"childItems": [
45+
{
46+
"text": "get",
47+
"kind": "function"
48+
},
49+
{
50+
"text": "set",
51+
"kind": "function"
52+
}
53+
]
54+
},
55+
{
56+
"text": "name",
57+
"childItems": [
58+
{
59+
"text": "get",
60+
"kind": "function"
61+
},
62+
{
63+
"text": "set",
64+
"kind": "function"
65+
}
66+
]
67+
}
68+
]
1869
}
1970
]
2071
});
@@ -26,17 +77,36 @@ verify.navigationBar([
2677
"childItems": [
2778
{
2879
"text": "f",
29-
"kind": "function"
30-
},
31-
{
32-
"text": "x",
33-
"kind": "property"
80+
"kind": "class"
3481
}
3582
]
3683
},
3784
{
3885
"text": "f",
39-
"kind": "function",
86+
"kind": "class",
87+
"childItems": [
88+
{
89+
"text": "constructor",
90+
"kind": "constructor"
91+
},
92+
{
93+
"text": "x",
94+
"kind": "property"
95+
},
96+
{
97+
"text": "y"
98+
},
99+
{
100+
"text": "method",
101+
"kind": "function"
102+
},
103+
{
104+
"text": "staticProp"
105+
},
106+
{
107+
"text": "name"
108+
}
109+
],
40110
"indent": 1
41111
}
42112
]);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////A.prototype.a = function() { };
6+
////A.prototype.b = function() { };
7+
////function A() {}
8+
9+
verify.navigationTree({
10+
"text": "<global>",
11+
"kind": "script",
12+
"childItems": [
13+
{
14+
"text": "A",
15+
"kind": "class",
16+
"childItems": [
17+
{
18+
"text": "a",
19+
"kind": "function"
20+
},
21+
{
22+
"text": "b",
23+
"kind": "function"
24+
},
25+
{
26+
"text": "constructor",
27+
"kind": "constructor"
28+
}
29+
]
30+
}
31+
]
32+
});
33+
34+
verify.navigationBar([
35+
{
36+
"text": "<global>",
37+
"kind": "script",
38+
"childItems": [
39+
{
40+
"text": "A",
41+
"kind": "class"
42+
}
43+
]
44+
},
45+
{
46+
"text": "A",
47+
"kind": "class",
48+
"childItems": [
49+
{
50+
"text": "a",
51+
"kind": "function"
52+
},
53+
{
54+
"text": "b",
55+
"kind": "function"
56+
},
57+
{
58+
"text": "constructor",
59+
"kind": "constructor"
60+
}
61+
],
62+
"indent": 1
63+
}
64+
]);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////var A;
6+
////A.prototype.a = function() { };
7+
////A.b = function() { };
8+
9+
verify.navigationTree({
10+
"text": "<global>",
11+
"kind": "script",
12+
"childItems": [
13+
{
14+
"text": "A",
15+
"kind": "class",
16+
"childItems": [
17+
{
18+
"text": "constructor",
19+
"kind": "constructor"
20+
},
21+
{
22+
"text": "a",
23+
"kind": "function"
24+
},
25+
{
26+
"text": "b",
27+
"kind": "function"
28+
}
29+
]
30+
}
31+
]
32+
});
33+
34+
verify.navigationBar([
35+
{
36+
"text": "<global>",
37+
"kind": "script",
38+
"childItems": [
39+
{
40+
"text": "A",
41+
"kind": "class"
42+
}
43+
]
44+
},
45+
{
46+
"text": "A",
47+
"kind": "class",
48+
"childItems": [
49+
{
50+
"text": "constructor",
51+
"kind": "constructor"
52+
},
53+
{
54+
"text": "a",
55+
"kind": "function"
56+
},
57+
{
58+
"text": "b",
59+
"kind": "function"
60+
}
61+
],
62+
"indent": 1
63+
}
64+
]);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////var A;
6+
////A.prototype = { };
7+
////A.prototype = { m() {} };
8+
////A.prototype.a = function() { };
9+
////A.b = function() { };
10+
11+
verify.navigationTree({
12+
"text": "<global>",
13+
"kind": "script",
14+
"childItems": [
15+
{
16+
"text": "A",
17+
"kind": "class",
18+
"childItems": [
19+
{
20+
"text": "constructor",
21+
"kind": "constructor"
22+
},
23+
{
24+
"text": "m",
25+
"kind": "method"
26+
},
27+
{
28+
"text": "a",
29+
"kind": "function"
30+
},
31+
{
32+
"text": "b",
33+
"kind": "function"
34+
}
35+
]
36+
}
37+
]
38+
});
39+
40+
verify.navigationBar([
41+
{
42+
"text": "<global>",
43+
"kind": "script",
44+
"childItems": [
45+
{
46+
"text": "A",
47+
"kind": "class"
48+
}
49+
]
50+
},
51+
{
52+
"text": "A",
53+
"kind": "class",
54+
"childItems": [
55+
{
56+
"text": "constructor",
57+
"kind": "constructor"
58+
},
59+
{
60+
"text": "m",
61+
"kind": "method"
62+
},
63+
{
64+
"text": "a",
65+
"kind": "function"
66+
},
67+
{
68+
"text": "b",
69+
"kind": "function"
70+
}
71+
],
72+
"indent": 1
73+
}
74+
]);

0 commit comments

Comments
 (0)