Implemented getOccurrences for 'constructor' keywords.
This commit is contained in:
parent
e1f8aa7b8f
commit
6cc0305a5d
3 changed files with 85 additions and 2 deletions
|
@ -2185,6 +2185,11 @@ module ts {
|
||||||
return getBreakStatementOccurences(<BreakOrContinueStatement>node.parent);
|
return getBreakStatementOccurences(<BreakOrContinueStatement>node.parent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SyntaxKind.ConstructorKeyword:
|
||||||
|
if (hasKind(node.parent, SyntaxKind.Constructor)) {
|
||||||
|
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -2249,7 +2254,7 @@ module ts {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[]{
|
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[] {
|
||||||
var func = <FunctionDeclaration>getContainingFunction(returnStatement);
|
var func = <FunctionDeclaration>getContainingFunction(returnStatement);
|
||||||
|
|
||||||
// If we didn't find a containing function with a block body, bail out.
|
// If we didn't find a containing function with a block body, bail out.
|
||||||
|
@ -2317,7 +2322,7 @@ module ts {
|
||||||
return map(keywords, getReferenceEntryFromNode);
|
return map(keywords, getReferenceEntryFromNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBreakStatementOccurences(breakStatement: BreakOrContinueStatement): ReferenceEntry[]{
|
function getBreakStatementOccurences(breakStatement: BreakOrContinueStatement): ReferenceEntry[] {
|
||||||
// TODO (drosen): Deal with labeled statements.
|
// TODO (drosen): Deal with labeled statements.
|
||||||
if (breakStatement.label) {
|
if (breakStatement.label) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -2345,6 +2350,20 @@ module ts {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConstructorOccurrences(constructorDeclaration: ConstructorDeclaration): ReferenceEntry[] {
|
||||||
|
var declarations = constructorDeclaration.symbol.getDeclarations()
|
||||||
|
|
||||||
|
var keywords: Node[] = [];
|
||||||
|
|
||||||
|
forEach(declarations, declaration => {
|
||||||
|
forEach(declaration.getChildren(), token => {
|
||||||
|
return pushKeywordIf(keywords, token, SyntaxKind.ConstructorKeyword);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return map(keywords, getReferenceEntryFromNode);
|
||||||
|
}
|
||||||
|
|
||||||
// returns true if 'node' is defined and has a matching 'kind'.
|
// returns true if 'node' is defined and has a matching 'kind'.
|
||||||
function hasKind(node: Node, kind: SyntaxKind) {
|
function hasKind(node: Node, kind: SyntaxKind) {
|
||||||
return !!(node && node.kind === kind);
|
return !!(node && node.kind === kind);
|
||||||
|
|
32
tests/cases/fourslash/getOccurrencesConstructor.ts
Normal file
32
tests/cases/fourslash/getOccurrencesConstructor.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
////class C {
|
||||||
|
//// [|const/**/ructor|]();
|
||||||
|
//// [|constructor|](x: number);
|
||||||
|
//// [|constructor|](y: string, x: number);
|
||||||
|
//// [|constructor|](a?: any, ...r: any[]) {
|
||||||
|
//// if (a === undefined && r.length === 0) {
|
||||||
|
//// return;
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// return;
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
////
|
||||||
|
////class D {
|
||||||
|
//// constructor(public x: number, public y: number) {
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
|
||||||
|
test.ranges().forEach(r => {
|
||||||
|
goTo.position(r.start);
|
||||||
|
|
||||||
|
test.ranges().forEach(range => {
|
||||||
|
verify.occurrencesAtPositionContains(range, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
goTo.marker();
|
||||||
|
test.ranges().forEach(range => {
|
||||||
|
verify.occurrencesAtPositionContains(range, false);
|
||||||
|
});
|
32
tests/cases/fourslash/getOccurrencesConstructor2.ts
Normal file
32
tests/cases/fourslash/getOccurrencesConstructor2.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
////class C {
|
||||||
|
//// constructor();
|
||||||
|
//// constructor(x: number);
|
||||||
|
//// constructor(y: string, x: number);
|
||||||
|
//// constructor(a?: any, ...r: any[]) {
|
||||||
|
//// if (a === undefined && r.length === 0) {
|
||||||
|
//// return;
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// return;
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
////
|
||||||
|
////class D {
|
||||||
|
//// [|con/**/structor|](public x: number, public y: number) {
|
||||||
|
//// }
|
||||||
|
////}
|
||||||
|
|
||||||
|
test.ranges().forEach(r => {
|
||||||
|
goTo.position(r.start);
|
||||||
|
|
||||||
|
test.ranges().forEach(range => {
|
||||||
|
verify.occurrencesAtPositionContains(range, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
goTo.marker();
|
||||||
|
test.ranges().forEach(range => {
|
||||||
|
verify.occurrencesAtPositionContains(range, false);
|
||||||
|
});
|
Loading…
Reference in a new issue