Merge pull request #3846 from DickvdBrink/abstract-occurrences

Highlight Abstract occurrences
This commit is contained in:
Daniel Rosenwasser 2015-07-13 17:08:14 -07:00
commit c5aa3ad8a3
3 changed files with 70 additions and 1 deletions

View File

@ -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 = (<Block>container).statements;
// Container is either a class declaration or the declaration is a classDeclaration
if (modifierFlag & NodeFlags.Abstract) {
nodes = (<Node[]>(<ClassDeclaration>declaration).members).concat(declaration);
}
else {
nodes = (<Block>container).statements;
}
break;
case SyntaxKind.Constructor:
nodes = (<Node[]>(<ConstructorDeclaration>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();
}

View File

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
////[|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);
}
}

View File

@ -0,0 +1,29 @@
/// <reference path='fourslash.ts' />
////// 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);