From 8b0988543b9217a46fc06b2b35858f6ea6dbfb3a Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 14 Dec 2017 16:40:42 -0800 Subject: [PATCH] Stop assuming code fix test changes are in the originating file Triggering a fix in one file can result in changes in another file. Instead of passing around the originating file, retrieve an appropriate `ScriptInfo` for each `FileTextChanges`. Fixes #19165 --- src/server/session.ts | 8 ++++---- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 17c5777132f..9dcf58734a7 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1230,7 +1230,7 @@ namespace ts.server { return project.getLanguageService().getCompletionEntryDetails(file, position, name, formattingOptions, source); }); return simplifiedResult - ? result.map(details => ({ ...details, codeActions: map(details.codeActions, action => this.mapCodeAction(action, scriptInfo)) })) + ? result.map(details => ({ ...details, codeActions: map(details.codeActions, action => this.mapCodeAction(project, action)) })) : result; } @@ -1560,7 +1560,7 @@ namespace ts.server { return undefined; } if (simplifiedResult) { - return codeActions.map(codeAction => this.mapCodeAction(codeAction, scriptInfo)); + return codeActions.map(codeAction => this.mapCodeAction(project, codeAction)); } else { return codeActions; @@ -1613,8 +1613,8 @@ namespace ts.server { return { startPosition, endPosition }; } - private mapCodeAction({ description, changes: unmappedChanges, commands }: CodeAction, scriptInfo: ScriptInfo): protocol.CodeAction { - const changes = unmappedChanges.map(change => this.mapTextChangesToCodeEditsUsingScriptinfo(change, scriptInfo)); + private mapCodeAction(project: Project, { description, changes: unmappedChanges, commands }: CodeAction): protocol.CodeAction { + const changes = unmappedChanges.map(change => this.mapTextChangesToCodeEditsUsingScriptinfo(change, project.getScriptInfoForNormalizedPath(toNormalizedPath(change.fileName)))); return { description, changes, commands }; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 464e70671f4..a22a2878638 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -7092,7 +7092,7 @@ declare namespace ts.server { private getCombinedCodeFix({scope, fixId}, simplifiedResult); private applyCodeActionCommand(args); private getStartAndEndPosition(args, scriptInfo); - private mapCodeAction({description, changes: unmappedChanges, commands}, scriptInfo); + private mapCodeAction(project, {description, changes: unmappedChanges, commands}); private mapTextChangesToCodeEdits(project, textChanges); private mapTextChangesToCodeEditsUsingScriptinfo(textChanges, scriptInfo); private convertTextChangeToCodeEdit(change, scriptInfo);