Skip to content

Commit c61be11

Browse files
getOccurrences for 'get' and 'set' keywords.
'get'/'set' keywords are highlighted for analogous accessors.
1 parent debc653 commit c61be11

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

src/services/services.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,11 @@ module ts {
24182418
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
24192419
}
24202420
break;
2421+
case SyntaxKind.GetKeyword:
2422+
case SyntaxKind.SetKeyword:
2423+
if (hasKind(node.parent, SyntaxKind.GetAccessor) || hasKind(node.parent, SyntaxKind.SetAccessor)) {
2424+
return getGetAndSetOccurrences(<AccessorDeclaration>node.parent);
2425+
}
24212426
}
24222427

24232428
return undefined;
@@ -2648,6 +2653,25 @@ module ts {
26482653
return map(keywords, getReferenceEntryFromNode);
26492654
}
26502655

2656+
function getGetAndSetOccurrences(accessorDeclaration: AccessorDeclaration): ReferenceEntry[] {
2657+
var keywords: Node[] = [];
2658+
2659+
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.GetAccessor);
2660+
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.SetAccessor);
2661+
2662+
return map(keywords, getReferenceEntryFromNode);
2663+
2664+
function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind): void {
2665+
var accessor = getDeclarationOfKind(accessorSymbol, accessorKind);
2666+
2667+
if (!accessor) {
2668+
return;
2669+
}
2670+
2671+
forEach(accessor.getChildren(), child => pushKeywordIf(keywords, child, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword));
2672+
}
2673+
}
2674+
26512675
// returns true if 'node' is defined and has a matching 'kind'.
26522676
function hasKind(node: Node, kind: SyntaxKind) {
26532677
return node !== undefined && node.kind === kind;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class Foo {
4+
//// [|set|] bar(b: any) {
5+
//// }
6+
////
7+
//// public [|get|] bar(): any {
8+
//// return undefined;
9+
//// }
10+
////
11+
//// public set set(s: any) {
12+
//// }
13+
////
14+
//// public get set(): any {
15+
//// return undefined;
16+
//// }
17+
////
18+
//// public set get(g: any) {
19+
//// }
20+
////
21+
//// public get get(): any {
22+
//// return undefined;
23+
//// }
24+
////}
25+
26+
test.ranges().forEach(r => {
27+
goTo.position(r.start);
28+
29+
test.ranges().forEach(range => {
30+
verify.occurrencesAtPositionContains(range, false);
31+
});
32+
33+
verify.occurrencesAtPositionCount(test.ranges().length);
34+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class Foo {
4+
//// set bar(b: any) {
5+
//// }
6+
////
7+
//// public get bar(): any {
8+
//// return undefined;
9+
//// }
10+
////
11+
//// public [|set|] set(s: any) {
12+
//// }
13+
////
14+
//// public [|get|] set(): any {
15+
//// return undefined;
16+
//// }
17+
////
18+
//// public set get(g: any) {
19+
//// }
20+
////
21+
//// public get get(): any {
22+
//// return undefined;
23+
//// }
24+
////}
25+
26+
test.ranges().forEach(r => {
27+
goTo.position(r.start);
28+
29+
test.ranges().forEach(range => {
30+
verify.occurrencesAtPositionContains(range, false);
31+
});
32+
33+
verify.occurrencesAtPositionCount(test.ranges().length);
34+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class Foo {
4+
//// set bar(b: any) {
5+
//// }
6+
////
7+
//// public get bar(): any {
8+
//// return undefined;
9+
//// }
10+
////
11+
//// public set set(s: any) {
12+
//// }
13+
////
14+
//// public get set(): any {
15+
//// return undefined;
16+
//// }
17+
////
18+
//// public [|set|] get(g: any) {
19+
//// }
20+
////
21+
//// public [|get|] get(): any {
22+
//// return undefined;
23+
//// }
24+
////}
25+
26+
test.ranges().forEach(r => {
27+
goTo.position(r.start);
28+
29+
test.ranges().forEach(range => {
30+
verify.occurrencesAtPositionContains(range, false);
31+
});
32+
33+
verify.occurrencesAtPositionCount(test.ranges().length);
34+
});

0 commit comments

Comments
 (0)