Skip to content

Commit fc54a2c

Browse files
author
Andy
authored
Include triggerSpan in protocol.RenameInfo (#27160)
1 parent cd5b9fa commit fc54a2c

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/server/protocol.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ namespace ts.server.protocol {
11231123
* Optional modifiers for the kind (such as 'public').
11241124
*/
11251125
kindModifiers: string;
1126+
1127+
/** Span of text to rename. */
1128+
triggerSpan: TextSpan;
11261129
}
11271130

11281131
/**

src/server/session.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,12 @@ namespace ts.server {
11611161
if (!simplifiedResult) return locations;
11621162

11631163
const defaultProject = this.getDefaultProject(args);
1164-
const renameInfo = Session.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position));
1164+
const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position), Debug.assertDefined(this.projectService.getScriptInfo(file)));
11651165
return { info: renameInfo, locs: this.toSpanGroups(locations) };
11661166
}
11671167

1168-
// strips 'triggerSpan'
1169-
private static mapRenameInfo({ canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers }: RenameInfo): protocol.RenameInfo {
1170-
return { canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers };
1168+
private mapRenameInfo({ canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers, triggerSpan }: RenameInfo, scriptInfo: ScriptInfo): protocol.RenameInfo {
1169+
return { canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers, triggerSpan: this.toLocationTextSpan(triggerSpan, scriptInfo) };
11711170
}
11721171

11731172
private toSpanGroups(locations: ReadonlyArray<RenameLocation>): ReadonlyArray<protocol.SpanGroup> {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ namespace ts.projectSystem {
456456
function protocolFileLocationFromSubstring(file: File, substring: string): protocol.FileLocationRequestArgs {
457457
return { file: file.path, ...protocolLocationFromSubstring(file.content, substring) };
458458
}
459-
function protocolFileSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions) {
459+
function protocolFileSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): protocol.FileSpan {
460460
return { file: file.path, ...protocolTextSpanFromSubstring(file.content, substring, options) };
461461
}
462462
function documentSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): DocumentSpan {
@@ -8287,7 +8287,8 @@ namespace ts.projectSystem {
82878287
protocolTextSpanFromSubstring(aFile.content, "C"),
82888288
protocolTextSpanFromSubstring(aFile.content, "C", { index: 1 }),
82898289
];
8290-
const cLocs: protocol.TextSpan[] = [protocolTextSpanFromSubstring(cFile.content, "C")];
8290+
const span = protocolTextSpanFromSubstring(cFile.content, "C");
8291+
const cLocs: protocol.TextSpan[] = [span];
82918292
assert.deepEqual<protocol.RenameResponseBody | undefined>(response, {
82928293
info: {
82938294
canRename: true,
@@ -8296,6 +8297,7 @@ namespace ts.projectSystem {
82968297
kind: ScriptElementKind.constElement,
82978298
kindModifiers: ScriptElementKindModifier.exportedModifier,
82988299
localizedErrorMessage: undefined,
8300+
triggerSpan: span,
82998301
},
83008302
locs: [
83018303
{ file: aFc, locs: cLocs },
@@ -10063,6 +10065,7 @@ declare class TestLib {
1006310065
kind: ScriptElementKind.alias,
1006410066
kindModifiers: ScriptElementKindModifier.none,
1006510067
localizedErrorMessage: undefined,
10068+
triggerSpan: protocolTextSpanFromSubstring(userTs.content, "fnA", { index: 1 }),
1006610069
},
1006710070
locs: [renameUserTs(userTs), renameATs(aTs)],
1006810071
});
@@ -10081,6 +10084,7 @@ declare class TestLib {
1008110084
kind: ScriptElementKind.functionElement,
1008210085
kindModifiers: ScriptElementKindModifier.exportedModifier,
1008310086
localizedErrorMessage: undefined,
10087+
triggerSpan: protocolTextSpanFromSubstring(aTs.content, "fnA"),
1008410088
},
1008510089
locs: [renameATs(aTs), renameUserTs(userTs)],
1008610090
});
@@ -10109,6 +10113,7 @@ declare class TestLib {
1010910113
kind: ScriptElementKind.alias,
1011010114
kindModifiers: ScriptElementKindModifier.none,
1011110115
localizedErrorMessage: undefined,
10116+
triggerSpan: protocolTextSpanFromSubstring(userTs.content, "fnB", { index: 1 }),
1011210117
},
1011310118
locs: [
1011410119
{

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6455,6 +6455,8 @@ declare namespace ts.server.protocol {
64556455
* Optional modifiers for the kind (such as 'public').
64566456
*/
64576457
kindModifiers: string;
6458+
/** Span of text to rename. */
6459+
triggerSpan: TextSpan;
64586460
}
64596461
/**
64606462
* A group of text spans, all in 'file'.
@@ -8733,7 +8735,7 @@ declare namespace ts.server {
87338735
private getProjects;
87348736
private getDefaultProject;
87358737
private getRenameLocations;
8736-
private static mapRenameInfo;
8738+
private mapRenameInfo;
87378739
private toSpanGroups;
87388740
private getReferences;
87398741
/**

0 commit comments

Comments
 (0)