diff --git a/src/services/services.ts b/src/services/services.ts index f158af5f071..663c3903c27 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2169,10 +2169,30 @@ module ts { } switch (node.kind) { + case SyntaxKind.TryKeyword: + case SyntaxKind.CatchKeyword: + case SyntaxKind.FinallyKeyword: + return getTryCatchFinallyOccurrences(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) diff --git a/tests/cases/fourslash/getOccurrencesTryCatchFinally.ts b/tests/cases/fourslash/getOccurrencesTryCatchFinally.ts new file mode 100644 index 00000000000..9037b6f8029 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesTryCatchFinally.ts @@ -0,0 +1,27 @@ +/// + +/////*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); + }); +} diff --git a/tests/cases/fourslash/getOccurrencesTryCatchFinally2.ts b/tests/cases/fourslash/getOccurrencesTryCatchFinally2.ts new file mode 100644 index 00000000000..5d71b133c27 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesTryCatchFinally2.ts @@ -0,0 +1,27 @@ +/// + +////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); + }); +} \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesTryCatchFinally3.ts b/tests/cases/fourslash/getOccurrencesTryCatchFinally3.ts new file mode 100644 index 00000000000..f2a79369364 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesTryCatchFinally3.ts @@ -0,0 +1,27 @@ +/// + +////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); + }); +} \ No newline at end of file