Skip to content

Commit b2d2f08

Browse files
authored
improve response time of invalid rename attempts (microsoft#46158)
* improve response time in invalid rename attempts * account for simplifiedResult and revert unrelated change
1 parent a02a7ab commit b2d2f08

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

src/server/session.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,19 +1536,21 @@ namespace ts.server {
15361536
const file = toNormalizedPath(args.file);
15371537
const position = this.getPositionInFile(args, file);
15381538
const projects = this.getProjects(args);
1539+
const defaultProject = this.getDefaultProject(args);
1540+
const renameInfo: protocol.RenameInfo = this.mapRenameInfo(
1541+
defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), Debug.checkDefined(this.projectService.getScriptInfo(file)));
1542+
1543+
if (!renameInfo.canRename) return simplifiedResult ? { info: renameInfo, locs: [] } : [];
15391544

15401545
const locations = combineProjectOutputForRenameLocations(
15411546
projects,
1542-
this.getDefaultProject(args),
1547+
defaultProject,
15431548
{ fileName: args.file, pos: position },
15441549
!!args.findInStrings,
15451550
!!args.findInComments,
15461551
this.getPreferences(file)
15471552
);
15481553
if (!simplifiedResult) return locations;
1549-
1550-
const defaultProject = this.getDefaultProject(args);
1551-
const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), Debug.checkDefined(this.projectService.getScriptInfo(file)));
15521554
return { info: renameInfo, locs: this.toSpanGroups(locations) };
15531555
}
15541556

src/services/rename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace ts.Rename {
111111
return createTextSpan(start, width);
112112
}
113113

114-
function nodeIsEligibleForRename(node: Node): boolean {
114+
export function nodeIsEligibleForRename(node: Node): boolean {
115115
switch (node.kind) {
116116
case SyntaxKind.Identifier:
117117
case SyntaxKind.PrivateIdentifier:

src/services/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,7 @@ namespace ts {
17501750
synchronizeHostData();
17511751
const sourceFile = getValidSourceFile(fileName);
17521752
const node = getAdjustedRenameLocation(getTouchingPropertyName(sourceFile, position));
1753+
if (!Rename.nodeIsEligibleForRename(node)) return undefined;
17531754
if (isIdentifier(node) && (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) && isIntrinsicJsxName(node.escapedText)) {
17541755
const { openingElement, closingElement } = node.parent.parent;
17551756
return [openingElement, closingElement].map((node): RenameLocation => {

src/testRunner/unittests/tsserver/rename.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ namespace ts.projectSystem {
1414
canRename: false,
1515
localizedErrorMessage: "You cannot rename this element."
1616
},
17-
locs: [{
18-
file: bTs.path,
19-
locs: [
20-
protocolRenameSpanFromSubstring({
21-
fileText: bTs.content,
22-
text: "./a",
23-
contextText: bTs.content
24-
})
25-
]
26-
}],
17+
locs: [],
2718
});
2819

2920
// rename succeeds with allowRenameOfImportPath enabled in host

0 commit comments

Comments
 (0)