Ensure range for string literal references are within the quotes to ensure rename is successful

This commit is contained in:
Mohamed Hegazy
2014-08-22 22:07:45 -07:00
parent c741e26031
commit 8fcc8b26ba
4 changed files with 37 additions and 2 deletions

View File

@@ -596,6 +596,29 @@ module FourSlash {
}
}
public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) {
this.taoInvalidReason = 'verifyReferencesAtPositionListContains NYI';
var references = this.getReferencesAtCaret();
if (!references || references.length === 0) {
throw new Error('verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.');
}
for (var i = 0; i < references.length; i++) {
var reference = references[i];
if (reference && reference.fileName === fileName && reference.minChar === start && reference.limChar === end) {
if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) {
throw new Error('verifyReferencesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.');
}
return;
}
}
var missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess };
throw new Error('verifyReferencesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(references) + ')');
}
public verifyReferencesCountIs(count: number, localFilesOnly: boolean = true) {
this.taoInvalidReason = 'verifyReferences NYI';

View File

@@ -2466,8 +2466,8 @@ module ts {
function getReferenceEntry(node: Node): ReferenceEntry {
return {
fileName: node.getSourceFile().filename,
minChar: node.getStart(),
limChar: node.getEnd(),
minChar: node.kind === SyntaxKind.StringLiteral ? node.getStart() + 1 : node.getStart(),
limChar: node.kind === SyntaxKind.StringLiteral ? node.getEnd() - 1 : node.getEnd(),
isWriteAccess: isWriteAccess(node)
};
}