Implemented getOccsAtPos for try-catch-finally.

This commit is contained in:
Daniel Rosenwasser 2014-08-26 11:48:31 -07:00
parent 5d15cd22b1
commit 558be4ea22
4 changed files with 101 additions and 0 deletions

View File

@ -2169,10 +2169,30 @@ module ts {
}
switch (node.kind) {
case SyntaxKind.TryKeyword:
case SyntaxKind.CatchKeyword:
case SyntaxKind.FinallyKeyword:
return getTryCatchFinallyOccurrences(<TryStatement>node.parent.parent);
}
return undefined;
function getTryCatchFinallyOccurrences(tryStatement: TryStatement): ReferenceEntry[] {
var keywords: Node[] = [];
keywords.push(tryStatement.getFirstToken())
if (tryStatement.catchBlock) {
keywords.push(tryStatement.catchBlock.getFirstToken());
}
if (tryStatement.finallyBlock) {
keywords.push(tryStatement.finallyBlock.getFirstToken());
}
return keywordsToReferenceEntries(keywords);
}
function keywordsToReferenceEntries(keywords: Node[]): ReferenceEntry[]{
return keywords.map(keyword =>
new ReferenceEntry(filename, TypeScript.TextSpan.fromBounds(keyword.getStart(), keyword.end), /* isWriteAccess */ false)

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
/////*1*/[|try|] {
//// try {
//// }
//// catch (x) {
//// }
////
//// try {
//// }
//// finally {
//// }
////}
////[|cat/*2*/ch|] (e) {
////}
////[|fina/*3*/lly|] {
////}
for (var i = 1; i <= test.markers().length; i++) {
goTo.marker("" + i);
verify.occurrencesAtPositionCount(3);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
}

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
////try {
//// [|t/*1*/r/*2*/y|] {
//// }
//// [|c/*3*/atch|] (x) {
//// }
////
//// try {
//// }
//// finally {
//// }
////}
////catch (e) {
////}
////finally {
////}
for (var i = 1; i <= test.markers().length; i++) {
goTo.marker("" + i);
verify.occurrencesAtPositionCount(2);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
}

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
////try {
//// try {
//// }
//// catch (x) {
//// }
////
//// [|t/*1*/r/*2*/y|] {
//// }
//// [|finall/*3*/y|] {
//// }
////}
////catch (e) {
////}
////finally {
////}
for (var i = 1; i <= test.markers().length; i++) {
goTo.marker("" + i);
verify.occurrencesAtPositionCount(2);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
}