From e82eaa29b56842691855848e324f9c7e4de532aa Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 17 Sep 2018 14:38:11 -0700 Subject: [PATCH] Include triggerSpan in protocol.RenameInfo --- src/server/protocol.ts | 3 +++ src/server/session.ts | 7 +++---- src/testRunner/unittests/tsserverProjectSystem.ts | 9 +++++++-- tests/baselines/reference/api/tsserverlibrary.d.ts | 4 +++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 2804b27deaf1a..1a4ee8410144f 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -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; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 14ad20d7aaeac..977a0bd186d68 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -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): ReadonlyArray { diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 40d79847baae3..ba3df56b7f20a 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -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 { @@ -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(response, { info: { canRename: true, @@ -8296,6 +8297,7 @@ namespace ts.projectSystem { kind: ScriptElementKind.constElement, kindModifiers: ScriptElementKindModifier.exportedModifier, localizedErrorMessage: undefined, + triggerSpan: span, }, locs: [ { file: aFc, locs: cLocs }, @@ -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)], }); @@ -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)], }); @@ -10109,6 +10113,7 @@ declare class TestLib { kind: ScriptElementKind.alias, kindModifiers: ScriptElementKindModifier.none, localizedErrorMessage: undefined, + triggerSpan: protocolTextSpanFromSubstring(userTs.content, "fnB", { index: 1 }), }, locs: [ { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd590f8e76a35..e9b896e9d1714 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -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'. @@ -8733,7 +8735,7 @@ declare namespace ts.server { private getProjects; private getDefaultProject; private getRenameLocations; - private static mapRenameInfo; + private mapRenameInfo; private toSpanGroups; private getReferences; /**