Skip to content

Commit 6ec9786

Browse files
Merge pull request #639 from Microsoft/getOccurrencesConstructor
Implemented getOccurrences for 'constructor' keywords.
2 parents e1f8aa7 + 6cc0305 commit 6ec9786

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

src/services/services.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,11 @@ module ts {
21852185
return getBreakStatementOccurences(<BreakOrContinueStatement>node.parent);
21862186
}
21872187
break;
2188+
case SyntaxKind.ConstructorKeyword:
2189+
if (hasKind(node.parent, SyntaxKind.Constructor)) {
2190+
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
2191+
}
2192+
break;
21882193
}
21892194

21902195
return undefined;
@@ -2249,7 +2254,7 @@ module ts {
22492254
return result;
22502255
}
22512256

2252-
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[]{
2257+
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[] {
22532258
var func = <FunctionDeclaration>getContainingFunction(returnStatement);
22542259

22552260
// If we didn't find a containing function with a block body, bail out.
@@ -2317,7 +2322,7 @@ module ts {
23172322
return map(keywords, getReferenceEntryFromNode);
23182323
}
23192324

2320-
function getBreakStatementOccurences(breakStatement: BreakOrContinueStatement): ReferenceEntry[]{
2325+
function getBreakStatementOccurences(breakStatement: BreakOrContinueStatement): ReferenceEntry[] {
23212326
// TODO (drosen): Deal with labeled statements.
23222327
if (breakStatement.label) {
23232328
return undefined;
@@ -2345,6 +2350,20 @@ module ts {
23452350
return undefined;
23462351
}
23472352

2353+
function getConstructorOccurrences(constructorDeclaration: ConstructorDeclaration): ReferenceEntry[] {
2354+
var declarations = constructorDeclaration.symbol.getDeclarations()
2355+
2356+
var keywords: Node[] = [];
2357+
2358+
forEach(declarations, declaration => {
2359+
forEach(declaration.getChildren(), token => {
2360+
return pushKeywordIf(keywords, token, SyntaxKind.ConstructorKeyword);
2361+
});
2362+
});
2363+
2364+
return map(keywords, getReferenceEntryFromNode);
2365+
}
2366+
23482367
// returns true if 'node' is defined and has a matching 'kind'.
23492368
function hasKind(node: Node, kind: SyntaxKind) {
23502369
return !!(node && node.kind === kind);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
//// [|const/**/ructor|]();
5+
//// [|constructor|](x: number);
6+
//// [|constructor|](y: string, x: number);
7+
//// [|constructor|](a?: any, ...r: any[]) {
8+
//// if (a === undefined && r.length === 0) {
9+
//// return;
10+
//// }
11+
////
12+
//// return;
13+
//// }
14+
////}
15+
////
16+
////class D {
17+
//// constructor(public x: number, public y: number) {
18+
//// }
19+
////}
20+
21+
test.ranges().forEach(r => {
22+
goTo.position(r.start);
23+
24+
test.ranges().forEach(range => {
25+
verify.occurrencesAtPositionContains(range, false);
26+
});
27+
});
28+
29+
goTo.marker();
30+
test.ranges().forEach(range => {
31+
verify.occurrencesAtPositionContains(range, false);
32+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
//// constructor();
5+
//// constructor(x: number);
6+
//// constructor(y: string, x: number);
7+
//// constructor(a?: any, ...r: any[]) {
8+
//// if (a === undefined && r.length === 0) {
9+
//// return;
10+
//// }
11+
////
12+
//// return;
13+
//// }
14+
////}
15+
////
16+
////class D {
17+
//// [|con/**/structor|](public x: number, public y: number) {
18+
//// }
19+
////}
20+
21+
test.ranges().forEach(r => {
22+
goTo.position(r.start);
23+
24+
test.ranges().forEach(range => {
25+
verify.occurrencesAtPositionContains(range, false);
26+
});
27+
});
28+
29+
goTo.marker();
30+
test.ranges().forEach(range => {
31+
verify.occurrencesAtPositionContains(range, false);
32+
});

0 commit comments

Comments
 (0)