getOccurrences for 'get' and 'set' keywords.

'get'/'set' keywords are highlighted for analogous accessors.
This commit is contained in:
Daniel Rosenwasser
2014-09-29 14:38:03 -07:00
committed by Daniel Rosenwasser
parent debc6539a0
commit c61be112d9
4 changed files with 126 additions and 0 deletions

View File

@@ -2418,6 +2418,11 @@ module ts {
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
}
break;
case SyntaxKind.GetKeyword:
case SyntaxKind.SetKeyword:
if (hasKind(node.parent, SyntaxKind.GetAccessor) || hasKind(node.parent, SyntaxKind.SetAccessor)) {
return getGetAndSetOccurrences(<AccessorDeclaration>node.parent);
}
}
return undefined;
@@ -2648,6 +2653,25 @@ module ts {
return map(keywords, getReferenceEntryFromNode);
}
function getGetAndSetOccurrences(accessorDeclaration: AccessorDeclaration): ReferenceEntry[] {
var keywords: Node[] = [];
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.GetAccessor);
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.SetAccessor);
return map(keywords, getReferenceEntryFromNode);
function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind): void {
var accessor = getDeclarationOfKind(accessorSymbol, accessorKind);
if (!accessor) {
return;
}
forEach(accessor.getChildren(), child => pushKeywordIf(keywords, child, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword));
}
}
// returns true if 'node' is defined and has a matching 'kind'.
function hasKind(node: Node, kind: SyntaxKind) {
return node !== undefined && node.kind === kind;

View File

@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// [|set|] bar(b: any) {
//// }
////
//// public [|get|] bar(): any {
//// return undefined;
//// }
////
//// public set set(s: any) {
//// }
////
//// public get set(): any {
//// return undefined;
//// }
////
//// public set get(g: any) {
//// }
////
//// public get get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});

View File

@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// set bar(b: any) {
//// }
////
//// public get bar(): any {
//// return undefined;
//// }
////
//// public [|set|] set(s: any) {
//// }
////
//// public [|get|] set(): any {
//// return undefined;
//// }
////
//// public set get(g: any) {
//// }
////
//// public get get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});

View File

@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// set bar(b: any) {
//// }
////
//// public get bar(): any {
//// return undefined;
//// }
////
//// public set set(s: any) {
//// }
////
//// public get set(): any {
//// return undefined;
//// }
////
//// public [|set|] get(g: any) {
//// }
////
//// public [|get|] get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});