Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f52c881

Browse filesBrowse files
author
Andy
authored
Improve verify.renameLocations (microsoft#25192)
1 parent 9c71eaf commit f52c881
Copy full SHA for f52c881

2 files changed

+8-34Lines changed: 8 additions & 34 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/harness/fourslash.ts‎

Copy file name to clipboardExpand all lines: src/harness/fourslash.ts
+6-33Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,17 +1388,8 @@ Actual: ${stringify(fullActual)}`);
13881388
}
13891389
}
13901390

1391-
public verifyRenameLocations(startRanges: ArrayOrSingle<Range>, options: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges: Range[] }) {
1392-
let findInStrings: boolean, findInComments: boolean, ranges: Range[];
1393-
if (ts.isArray(options)) {
1394-
findInStrings = findInComments = false;
1395-
ranges = options;
1396-
}
1397-
else {
1398-
findInStrings = !!options.findInStrings;
1399-
findInComments = !!options.findInComments;
1400-
ranges = options.ranges;
1401-
}
1391+
public verifyRenameLocations(startRanges: ArrayOrSingle<Range>, options: ReadonlyArray<Range> | { findInStrings?: boolean, findInComments?: boolean, ranges: ReadonlyArray<Range> }) {
1392+
const { findInStrings = false, findInComments = false, ranges = this.getRanges() } = ts.isArray(options) ? { findInStrings: false, findInComments: false, ranges: options } : options;
14021393

14031394
for (const startRange of toArray(startRanges)) {
14041395
this.goToRangeStart(startRange);
@@ -1409,30 +1400,12 @@ Actual: ${stringify(fullActual)}`);
14091400
break;
14101401
}
14111402

1412-
let references = this.languageService.findRenameLocations(
1403+
const references = this.languageService.findRenameLocations(
14131404
this.activeFile.fileName, this.currentCaretPosition, findInStrings, findInComments);
14141405

1415-
ranges = ranges || this.getRanges();
1416-
1417-
if (!references) {
1418-
if (ranges.length !== 0) {
1419-
this.raiseError(`Expected ${ranges.length} rename locations; got none.`);
1420-
}
1421-
return;
1422-
}
1423-
1424-
if (ranges.length !== references.length) {
1425-
this.raiseError("Rename location count does not match result.\n\nExpected: " + stringify(ranges) + "\n\nActual:" + stringify(references));
1426-
}
1427-
1428-
ranges = ranges.sort((r1, r2) => r1.pos - r2.pos);
1429-
references = references.sort((r1, r2) => r1.textSpan.start - r2.textSpan.start);
1430-
1431-
ts.zipWith(references, ranges, (reference, range) => {
1432-
if (reference.textSpan.start !== range.pos || ts.textSpanEnd(reference.textSpan) !== range.end) {
1433-
this.raiseError("Rename location results do not match.\n\nExpected: " + stringify(ranges) + "\n\nActual:" + stringify(references));
1434-
}
1435-
});
1406+
const sort = (locations: ReadonlyArray<ts.RenameLocation> | undefined) =>
1407+
locations && ts.sort(locations, (r1, r2) => ts.compareStringsCaseSensitive(r1.fileName, r2.fileName) || r1.textSpan.start - r2.textSpan.start);
1408+
assert.deepEqual(sort(references), sort(ranges.map((r): ts.RenameLocation => ({ fileName: r.fileName, textSpan: ts.createTextSpanFromRange(r) }))));
14361409
}
14371410
}
14381411

Collapse file

‎src/services/services.ts‎

Copy file name to clipboardExpand all lines: src/services/services.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,8 @@ namespace ts {
16971697
}
16981698

16991699
function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] | undefined {
1700-
return getReferences(fileName, position, { findInStrings, findInComments, isForRename: true });
1700+
const refs = getReferences(fileName, position, { findInStrings, findInComments, isForRename: true });
1701+
return refs && refs.map(({ fileName, textSpan }): RenameLocation => ({ fileName, textSpan }));
17011702
}
17021703

17031704
function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.