Allow to find all references of the 'this 'keyword

This commit is contained in:
Andy Hanson
2016-06-17 13:21:47 -07:00
parent ba78d1e35c
commit e7acef125d
6 changed files with 116 additions and 29 deletions

View File

@@ -0,0 +1,33 @@
/// <reference path='fourslash.ts' />
// @noLib: true
////[|this|];
////function f([|this|]) {
//// return [|this|];
//// function g([|this|]) { return [|this|]; }
////}
////class C {
//// static x() {
//// [|this|];
//// }
//// static y() {
//// () => [|this|];
//// }
//// constructor() {
//// [|this|];
//// }
//// method() {
//// () => [|this|];
//// }
////}
////// These are *not* real uses of the 'this' keyword, they are identifiers.
////const x = { [|this|]: 0 }
////x.[|this|];
const [global, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges();
verify.referencesOf(global, [global]);
verify.rangesReferenceEachOther([f0, f1]);
verify.rangesReferenceEachOther([g0, g1]);
verify.rangesReferenceEachOther([x, y]);
verify.rangesReferenceEachOther([constructor, method]);
verify.rangesReferenceEachOther([propDef, propUse]);

View File

@@ -1,18 +1,15 @@
/// <reference path='fourslash.ts' />
// @Filename: file1.ts
////this; this;
////[|this|]; [|this|];
// @Filename: file2.ts
////this;
////this;
////[|this|];
////[|this|];
// @Filename: file3.ts
//// ((x = this, y) => t/**/his)(this, this);
//// ((x = [|this|], y) => [|this|])([|this|], [|this|]);
//// // different 'this'
//// function f(this) { return this; }
goTo.file("file1.ts");
goTo.marker();
// TODO (drosen): The CURRENT behavior is that findAllRefs doesn't work on 'this' or 'super' keywords.
// This should change down the line.
verify.referencesCountIs(0);
verify.rangesReferenceEachOther();

View File

@@ -216,7 +216,7 @@ declare namespace FourSlashInterface {
}[]): void;
renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string): void;
renameInfoFailed(message?: string): void;
renameLocations(findInStrings: boolean, findInComments: boolean): void;
renameLocations(findInStrings: boolean, findInComments: boolean, ranges?: Range[]): void;
verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: {
start: number;
length: number;

View File

@@ -0,0 +1,22 @@
/// <reference path='fourslash.ts'/>
////function f([|this|]) {
//// return [|this|];
////}
////this/**/;
////const _ = { [|this|]: 0 }.[|this|];
let [r0, r1, r2, r3] = test.ranges()
for (let range of [r0, r1]) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [r0, r1]);
}
// Trying to rename a legitimate 'this' should fail
goTo.marker();
verify.renameInfoFailed("You cannot rename this element.");
for (let range of [r2, r3]) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [r2, r3]);
}