Skip to content

Commit 8fcc8b2

Browse files
committed
Ensure range for string literal references are within the quotes to ensure rename is successful
1 parent c741e26 commit 8fcc8b2

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/harness/fourslash.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,29 @@ module FourSlash {
596596
}
597597
}
598598

599+
public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) {
600+
this.taoInvalidReason = 'verifyReferencesAtPositionListContains NYI';
601+
602+
var references = this.getReferencesAtCaret();
603+
604+
if (!references || references.length === 0) {
605+
throw new Error('verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.');
606+
}
607+
608+
for (var i = 0; i < references.length; i++) {
609+
var reference = references[i];
610+
if (reference && reference.fileName === fileName && reference.minChar === start && reference.limChar === end) {
611+
if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) {
612+
throw new Error('verifyReferencesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.');
613+
}
614+
return;
615+
}
616+
}
617+
618+
var missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess };
619+
throw new Error('verifyReferencesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(references) + ')');
620+
}
621+
599622
public verifyReferencesCountIs(count: number, localFilesOnly: boolean = true) {
600623
this.taoInvalidReason = 'verifyReferences NYI';
601624

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,8 +2466,8 @@ module ts {
24662466
function getReferenceEntry(node: Node): ReferenceEntry {
24672467
return {
24682468
fileName: node.getSourceFile().filename,
2469-
minChar: node.getStart(),
2470-
limChar: node.getEnd(),
2469+
minChar: node.kind === SyntaxKind.StringLiteral ? node.getStart() + 1 : node.getStart(),
2470+
limChar: node.kind === SyntaxKind.StringLiteral ? node.getEnd() - 1 : node.getEnd(),
24712471
isWriteAccess: isWriteAccess(node)
24722472
};
24732473
}

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ module FourSlashInterface {
183183
FourSlash.currentTestState.verifyReferencesCountIs(count, /*localFilesOnly*/ false);
184184
}
185185

186+
public referencesAtPositionContains(range: Range, isWriteAccess?: boolean) {
187+
FourSlash.currentTestState.verifyReferencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess);
188+
}
189+
186190
public implementorsCountIs(count: number) {
187191
FourSlash.currentTestState.verifyImplementorsCountIs(count);
188192
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////var x = { "[|someProperty|]": 0 }
4+
////x["[|someProperty|]"] = 3;
5+
////x./*1*/[|someProperty|] = 5;
6+
7+
goTo.marker("1");
8+
test.ranges().forEach(r => verify.referencesAtPositionContains(r));

0 commit comments

Comments
 (0)