diff --git a/src/services/services.ts b/src/services/services.ts index f55c59a1b7b..453542aeb08 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4696,6 +4696,11 @@ namespace ts { return undefined; } } + else if (modifier === SyntaxKind.AbstractKeyword) { + if (!(container.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.ClassDeclaration)) { + return undefined; + } + } else { // unsupported modifier return undefined; @@ -4708,7 +4713,13 @@ namespace ts { switch (container.kind) { case SyntaxKind.ModuleBlock: case SyntaxKind.SourceFile: - nodes = (container).statements; + // Container is either a class declaration or the declaration is a classDeclaration + if (modifierFlag & NodeFlags.Abstract) { + nodes = ((declaration).members).concat(declaration); + } + else { + nodes = (container).statements; + } break; case SyntaxKind.Constructor: nodes = ((container).parameters).concat( @@ -4728,6 +4739,9 @@ namespace ts { nodes = nodes.concat(constructor.parameters); } } + else if (modifierFlag & NodeFlags.Abstract) { + nodes = nodes.concat(container); + } break; default: Debug.fail("Invalid container kind.") @@ -4755,6 +4769,8 @@ namespace ts { return NodeFlags.Export; case SyntaxKind.DeclareKeyword: return NodeFlags.Ambient; + case SyntaxKind.AbstractKeyword: + return NodeFlags.Abstract; default: Debug.fail(); } diff --git a/tests/cases/fourslash/getOccurrencesAbstract01.ts b/tests/cases/fourslash/getOccurrencesAbstract01.ts new file mode 100644 index 00000000000..3e48ba4841a --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesAbstract01.ts @@ -0,0 +1,24 @@ +/// + +////[|abstract|] class Animal { +//// [|abstract|] prop1; // Does not compile +//// [|abstract|] abstract(); +//// [|abstract|] walk(): void; +//// [|abstract|] makeSound(): void; +////} +////// Abstract class below should not get highlighted +////abstract class Foo { +//// abstract foo(): void; +//// abstract bar(): void; +////} + +const ranges = test.ranges(); + +for (let r of ranges) { + goTo.position(r.start); + verify.occurrencesAtPositionCount(ranges.length); + + for (let range of ranges) { + verify.occurrencesAtPositionContains(range, false); + } +} diff --git a/tests/cases/fourslash/getOccurrencesAbstract02.ts b/tests/cases/fourslash/getOccurrencesAbstract02.ts new file mode 100644 index 00000000000..8daafdbdc8e --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesAbstract02.ts @@ -0,0 +1,29 @@ +/// + +////// Not valid TS (abstract methods can only appear in abstract classes) +////class Animal { +//// [|abstract|] walk(): void; +//// [|abstract|] makeSound(): void; +////} +////// abstract cannot appear here, won't get highlighted +////let c = /*1*/abstract class Foo { +//// /*2*/abstract foo(): void; +//// abstract bar(): void; +////} + +const ranges = test.ranges(); + +for (let r of ranges) { + goTo.position(r.start); + verify.occurrencesAtPositionCount(ranges.length); + + for (let range of ranges) { + verify.occurrencesAtPositionContains(range, false); + } +} + +goTo.marker("1"); +verify.occurrencesAtPositionCount(0); + +goTo.marker("2"); +verify.occurrencesAtPositionCount(2);