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
This commit is contained in:
Andrew Casey 2017-12-14 16:40:42 -08:00
parent 5dab24a2a7
commit 8b0988543b
2 changed files with 5 additions and 5 deletions

View File

@ -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 };
}

View File

@ -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);