Skip to content

Commit ef2087a

Browse files
Merge branch 'master' into layering
2 parents 67b2f13 + af9b56b commit ef2087a

10 files changed

Lines changed: 188 additions & 126 deletions

src/harness/fourslash.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,14 @@ module FourSlash {
15151515
}
15161516
}
15171517

1518+
public verifyDefinitionsCount(negative: boolean, expectedCount: number) {
1519+
var assertFn = negative ? assert.notEqual : assert.equal;
1520+
1521+
var definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
1522+
1523+
assertFn(definitions.length, expectedCount, this.messageAtLastKnownMarker("Definitions Count"));
1524+
}
1525+
15181526
public verifyDefinitionsName(negative: boolean, expectedName: string, expectedContainerName: string) {
15191527
this.taoInvalidReason = 'verifyDefinititionsInfo NYI';
15201528

@@ -1523,10 +1531,10 @@ module FourSlash {
15231531
var actualDefinitionContainerName = definitions && definitions.length ? definitions[0].containerName : "";
15241532
if (negative) {
15251533
assert.notEqual(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Name"));
1526-
assert.notEqual(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Container Name"));
1534+
assert.notEqual(actualDefinitionContainerName, expectedContainerName, this.messageAtLastKnownMarker("Definition Info Container Name"));
15271535
} else {
15281536
assert.equal(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Name"));
1529-
assert.equal(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Container Name"));
1537+
assert.equal(actualDefinitionContainerName, expectedContainerName, this.messageAtLastKnownMarker("Definition Info Container Name"));
15301538
}
15311539
}
15321540

src/services/services.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ module ts {
25852585
}
25862586

25872587
// TODO(drosen): use contextual SemanticMeaning.
2588-
function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker, location?: Node): string {
2588+
function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker, location: Node): string {
25892589
var flags = symbol.getFlags();
25902590

25912591
if (flags & SymbolFlags.Class) return ScriptElementKind.classElement;
@@ -3084,62 +3084,6 @@ module ts {
30843084

30853085
/// Goto definition
30863086
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[] {
3087-
function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo {
3088-
return {
3089-
fileName: node.getSourceFile().filename,
3090-
textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()),
3091-
kind: symbolKind,
3092-
name: symbolName,
3093-
containerKind: undefined,
3094-
containerName
3095-
};
3096-
}
3097-
3098-
function tryAddSignature(signatureDeclarations: Declaration[], selectConstructors: boolean, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3099-
var declarations: Declaration[] = [];
3100-
var definition: Declaration;
3101-
3102-
forEach(signatureDeclarations, d => {
3103-
if ((selectConstructors && d.kind === SyntaxKind.Constructor) ||
3104-
(!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.MethodDeclaration || d.kind === SyntaxKind.MethodSignature))) {
3105-
declarations.push(d);
3106-
if ((<FunctionLikeDeclaration>d).body) definition = d;
3107-
}
3108-
});
3109-
3110-
if (definition) {
3111-
result.push(getDefinitionInfo(definition, symbolKind, symbolName, containerName));
3112-
return true;
3113-
}
3114-
else if (declarations.length) {
3115-
result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
3116-
return true;
3117-
}
3118-
3119-
return false;
3120-
}
3121-
3122-
function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3123-
// Applicable only if we are in a new expression, or we are on a constructor declaration
3124-
// and in either case the symbol has a construct signature definition, i.e. class
3125-
if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) {
3126-
if (symbol.flags & SymbolFlags.Class) {
3127-
var classDeclaration = <ClassDeclaration>symbol.getDeclarations()[0];
3128-
Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration);
3129-
3130-
return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result);
3131-
}
3132-
}
3133-
return false;
3134-
}
3135-
3136-
function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3137-
if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) {
3138-
return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result);
3139-
}
3140-
return false;
3141-
}
3142-
31433087
synchronizeHostData();
31443088

31453089
filename = normalizeSlashes(filename);
@@ -3192,7 +3136,7 @@ module ts {
31923136
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
31933137
var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
31943138
var shorthandDeclarations = shorthandSymbol.getDeclarations();
3195-
var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver);
3139+
var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node);
31963140
var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol);
31973141
var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node);
31983142
forEach(shorthandDeclarations, declaration => {
@@ -3203,7 +3147,7 @@ module ts {
32033147

32043148
var declarations = symbol.getDeclarations();
32053149
var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
3206-
var symbolKind = getSymbolKind(symbol, typeInfoResolver);
3150+
var symbolKind = getSymbolKind(symbol, typeInfoResolver, node);
32073151
var containerSymbol = symbol.parent;
32083152
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : "";
32093153

@@ -3216,6 +3160,62 @@ module ts {
32163160
}
32173161

32183162
return result;
3163+
3164+
function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo {
3165+
return {
3166+
fileName: node.getSourceFile().filename,
3167+
textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()),
3168+
kind: symbolKind,
3169+
name: symbolName,
3170+
containerKind: undefined,
3171+
containerName
3172+
};
3173+
}
3174+
3175+
function tryAddSignature(signatureDeclarations: Declaration[], selectConstructors: boolean, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3176+
var declarations: Declaration[] = [];
3177+
var definition: Declaration;
3178+
3179+
forEach(signatureDeclarations, d => {
3180+
if ((selectConstructors && d.kind === SyntaxKind.Constructor) ||
3181+
(!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.MethodDeclaration || d.kind === SyntaxKind.MethodSignature))) {
3182+
declarations.push(d);
3183+
if ((<FunctionLikeDeclaration>d).body) definition = d;
3184+
}
3185+
});
3186+
3187+
if (definition) {
3188+
result.push(getDefinitionInfo(definition, symbolKind, symbolName, containerName));
3189+
return true;
3190+
}
3191+
else if (declarations.length) {
3192+
result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
3193+
return true;
3194+
}
3195+
3196+
return false;
3197+
}
3198+
3199+
function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3200+
// Applicable only if we are in a new expression, or we are on a constructor declaration
3201+
// and in either case the symbol has a construct signature definition, i.e. class
3202+
if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) {
3203+
if (symbol.flags & SymbolFlags.Class) {
3204+
var classDeclaration = <ClassDeclaration>symbol.getDeclarations()[0];
3205+
Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration);
3206+
3207+
return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result);
3208+
}
3209+
}
3210+
return false;
3211+
}
3212+
3213+
function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) {
3214+
if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) {
3215+
return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result);
3216+
}
3217+
return false;
3218+
}
32193219
}
32203220

32213221
/// References and Occurrences
@@ -5259,7 +5259,7 @@ module ts {
52595259

52605260
// Only allow a symbol to be renamed if it actually has at least one declaration.
52615261
if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) {
5262-
var kind = getSymbolKind(symbol, typeInfoResolver);
5262+
var kind = getSymbolKind(symbol, typeInfoResolver, node);
52635263
if (kind) {
52645264
return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind,
52655265
getSymbolModifiers(symbol),

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ module FourSlashInterface {
217217
FourSlash.currentTestState.verifyQuickInfoExists(this.negative);
218218
}
219219

220+
public definitionCountIs(expectedCount: number) {
221+
FourSlash.currentTestState.verifyDefinitionsCount(this.negative, expectedCount);
222+
}
223+
220224
public definitionLocationExists() {
221225
FourSlash.currentTestState.verifyDefinitionLocationExists(this.negative);
222226
}

tests/cases/fourslash/goToDefinitionExternamModuleName4.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path='fourslash.ts'/>
1+
/// <reference path='fourslash.ts'/>
22

33
// @Filename: b.ts
44
////import n = require('unknown/*1*/');
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/// <reference path='fourslash.ts' />
2-
3-
/////*functionOverload1*/function /*functionOverload*/functionOverload();
4-
/////*functionOverload2*/function functionOverload(value: string);
5-
/////*functionOverloadDefinition*/function functionOverload() {}
6-
////
1+
/// <reference path='fourslash.ts' />
2+
3+
/////*functionOverload1*/function /*functionOverload*/functionOverload();
4+
/////*functionOverload2*/function functionOverload(value: string);
5+
/////*functionOverloadDefinition*/function functionOverload() {}
6+
////
77
/////*functionOverloadReference1*/functionOverload();
88
/////*functionOverloadReference2*/functionOverload("123");
99

10-
goTo.marker('functionOverloadReference1');
11-
goTo.definition();
12-
verify.caretAtMarker('functionOverloadDefinition');
13-
14-
goTo.marker('functionOverloadReference2');
15-
goTo.definition();
16-
verify.caretAtMarker('functionOverloadDefinition');
17-
18-
goTo.marker('functionOverload');
19-
goTo.definition();
20-
verify.caretAtMarker('functionOverloadDefinition');
10+
goTo.marker('functionOverloadReference1');
11+
goTo.definition();
12+
verify.caretAtMarker('functionOverloadDefinition');
13+
14+
goTo.marker('functionOverloadReference2');
15+
goTo.definition();
16+
verify.caretAtMarker('functionOverloadDefinition');
17+
18+
goTo.marker('functionOverload');
19+
goTo.definition();
20+
verify.caretAtMarker('functionOverloadDefinition');
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/// <reference path='fourslash.ts'/>
2-
3-
////class clsInOverload {
4-
//// static fnOverload();
5-
//// static /*staticFunctionOverload*/fnOverload(foo: string);
6-
//// /*staticFunctionOverloadDefinition*/static fnOverload(foo: any) { }
7-
//// public /*functionOverload*/fnOverload(): any;
8-
//// public fnOverload(foo: string);
9-
//// /*functionOverloadDefinition*/public fnOverload(foo: any) { return "foo" }
10-
////
11-
//// constructor() { }
12-
////}
13-
1+
/// <reference path='fourslash.ts'/>
2+
3+
////class clsInOverload {
4+
//// static fnOverload();
5+
//// static /*staticFunctionOverload*/fnOverload(foo: string);
6+
//// /*staticFunctionOverloadDefinition*/static fnOverload(foo: any) { }
7+
//// public /*functionOverload*/fnOverload(): any;
8+
//// public fnOverload(foo: string);
9+
//// /*functionOverloadDefinition*/public fnOverload(foo: any) { return "foo" }
10+
////
11+
//// constructor() { }
12+
////}
13+
1414
// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed
15-
edit.insert('');
16-
17-
goTo.marker('staticFunctionOverload');
18-
goTo.definition();
19-
verify.caretAtMarker('staticFunctionOverloadDefinition');
20-
21-
goTo.marker('functionOverload');
22-
goTo.definition();
15+
edit.insert('');
16+
17+
goTo.marker('staticFunctionOverload');
18+
goTo.definition();
19+
verify.caretAtMarker('staticFunctionOverloadDefinition');
20+
21+
goTo.marker('functionOverload');
22+
goTo.definition();
2323
verify.caretAtMarker('functionOverloadDefinition');

tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts renamed to tests/cases/fourslash/goToDefinitionUnionTypeProperty1.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/// <reference path='fourslash.ts' />
2-
1+
/// <reference path='fourslash.ts' />
2+
33
////interface One {
44
//// /*propertyDefinition1*/commonProperty: number;
55
//// commonFunction(): number;
@@ -13,12 +13,14 @@
1313
////var x : One | Two;
1414
////
1515
////x./*propertyReference*/commonProperty;
16-
////x./*3*/commonFunction;
17-
18-
goTo.marker("propertyReference");
19-
goTo.definition(0);
20-
verify.caretAtMarker("propertyDefinition1");
21-
22-
goTo.marker("propertyReference");
23-
goTo.definition(1);
24-
verify.caretAtMarker("propertyDefinition2");
16+
////x./*3*/commonFunction;
17+
18+
19+
goTo.marker("propertyReference");
20+
verify.definitionCountIs(2);
21+
goTo.definition(0);
22+
verify.caretAtMarker("propertyDefinition1");
23+
24+
goTo.marker("propertyReference");
25+
goTo.definition(1);
26+
verify.caretAtMarker("propertyDefinition2");
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/// <reference path='fourslash.ts' />
2-
////interface HasAOrB {
3-
//// /*propertyDefinition1*/a: string;
4-
//// b: string;
5-
////}
6-
////
1+
/// <reference path='fourslash.ts' />
2+
////interface HasAOrB {
3+
//// /*propertyDefinition1*/a: string;
4+
//// b: string;
5+
////}
6+
////
77
////interface One {
88
//// common: { /*propertyDefinition2*/a : number; };
99
////}
@@ -15,11 +15,12 @@
1515
////var x : One | Two;
1616
////
1717
////x.common./*propertyReference*/a;
18-
19-
goTo.marker("propertyReference");
20-
goTo.definition(0);
21-
verify.caretAtMarker("propertyDefinition2");
22-
23-
goTo.marker("propertyReference");
24-
goTo.definition(1);
25-
verify.caretAtMarker("propertyDefinition1");
18+
19+
goTo.marker("propertyReference");
20+
verify.definitionCountIs(2);
21+
goTo.definition(0);
22+
verify.caretAtMarker("propertyDefinition2");
23+
24+
goTo.marker("propertyReference");
25+
goTo.definition(1);
26+
verify.caretAtMarker("propertyDefinition1");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////interface Array<T> {
4+
//// /*definition*/specialPop(): T
5+
////}
6+
////
7+
////var strings: string[];
8+
////var numbers: number[];
9+
////
10+
////var x = (strings || numbers)./*usage*/specialPop()
11+
12+
goTo.marker("usage");
13+
verify.definitionCountIs(1);
14+
goTo.definition();
15+
verify.caretAtMarker("definition");

0 commit comments

Comments
 (0)