mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Implemented getOccsAtPos for try-catch-finally.
This commit is contained in:
parent
5d15cd22b1
commit
558be4ea22
@ -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)
|
||||
|
||||
27
tests/cases/fourslash/getOccurrencesTryCatchFinally.ts
Normal file
27
tests/cases/fourslash/getOccurrencesTryCatchFinally.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
27
tests/cases/fourslash/getOccurrencesTryCatchFinally2.ts
Normal file
27
tests/cases/fourslash/getOccurrencesTryCatchFinally2.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
27
tests/cases/fourslash/getOccurrencesTryCatchFinally3.ts
Normal file
27
tests/cases/fourslash/getOccurrencesTryCatchFinally3.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user