Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ namespace ts.server.protocol {
* Optional modifiers for the kind (such as 'public').
*/
kindModifiers: string;

/** Span of text to rename. */
triggerSpan: TextSpan;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,13 +1161,12 @@ namespace ts.server {
if (!simplifiedResult) return locations;

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

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

private toSpanGroups(locations: ReadonlyArray<RenameLocation>): ReadonlyArray<protocol.SpanGroup> {
Expand Down
9 changes: 7 additions & 2 deletions src/testRunner/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ namespace ts.projectSystem {
function protocolFileLocationFromSubstring(file: File, substring: string): protocol.FileLocationRequestArgs {
return { file: file.path, ...protocolLocationFromSubstring(file.content, substring) };
}
function protocolFileSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions) {
function protocolFileSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): protocol.FileSpan {
return { file: file.path, ...protocolTextSpanFromSubstring(file.content, substring, options) };
}
function documentSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): DocumentSpan {
Expand Down Expand Up @@ -8287,7 +8287,8 @@ namespace ts.projectSystem {
protocolTextSpanFromSubstring(aFile.content, "C"),
protocolTextSpanFromSubstring(aFile.content, "C", { index: 1 }),
];
const cLocs: protocol.TextSpan[] = [protocolTextSpanFromSubstring(cFile.content, "C")];
const span = protocolTextSpanFromSubstring(cFile.content, "C");
const cLocs: protocol.TextSpan[] = [span];
assert.deepEqual<protocol.RenameResponseBody | undefined>(response, {
info: {
canRename: true,
Expand All @@ -8296,6 +8297,7 @@ namespace ts.projectSystem {
kind: ScriptElementKind.constElement,
kindModifiers: ScriptElementKindModifier.exportedModifier,
localizedErrorMessage: undefined,
triggerSpan: span,
},
locs: [
{ file: aFc, locs: cLocs },
Expand Down Expand Up @@ -10063,6 +10065,7 @@ declare class TestLib {
kind: ScriptElementKind.alias,
kindModifiers: ScriptElementKindModifier.none,
localizedErrorMessage: undefined,
triggerSpan: protocolTextSpanFromSubstring(userTs.content, "fnA", { index: 1 }),
},
locs: [renameUserTs(userTs), renameATs(aTs)],
});
Expand All @@ -10081,6 +10084,7 @@ declare class TestLib {
kind: ScriptElementKind.functionElement,
kindModifiers: ScriptElementKindModifier.exportedModifier,
localizedErrorMessage: undefined,
triggerSpan: protocolTextSpanFromSubstring(aTs.content, "fnA"),
},
locs: [renameATs(aTs), renameUserTs(userTs)],
});
Expand Down Expand Up @@ -10109,6 +10113,7 @@ declare class TestLib {
kind: ScriptElementKind.alias,
kindModifiers: ScriptElementKindModifier.none,
localizedErrorMessage: undefined,
triggerSpan: protocolTextSpanFromSubstring(userTs.content, "fnB", { index: 1 }),
},
locs: [
{
Expand Down
4 changes: 3 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6455,6 +6455,8 @@ declare namespace ts.server.protocol {
* Optional modifiers for the kind (such as 'public').
*/
kindModifiers: string;
/** Span of text to rename. */
triggerSpan: TextSpan;
}
/**
* A group of text spans, all in 'file'.
Expand Down Expand Up @@ -8733,7 +8735,7 @@ declare namespace ts.server {
private getProjects;
private getDefaultProject;
private getRenameLocations;
private static mapRenameInfo;
private mapRenameInfo;
private toSpanGroups;
private getReferences;
/**
Expand Down