Immediately respond to applyCodeActionCommand requests (#20448)

This commit is contained in:
Andy 2017-12-05 13:19:01 -08:00 committed by GitHub
parent 7bb5fc22c2
commit 3a3bb8e3f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View file

@ -1571,15 +1571,15 @@ namespace ts.server {
}
}
private applyCodeActionCommand(commandName: string, requestSeq: number, args: protocol.ApplyCodeActionCommandRequestArgs): void {
private applyCodeActionCommand(args: protocol.ApplyCodeActionCommandRequestArgs): {} {
const commands = args.command as CodeActionCommand | CodeActionCommand[]; // They should be sending back the command we sent them.
for (const command of toArray(commands)) {
const { project } = this.getFileAndProject(command);
const output = (success: boolean, message: string) => this.doOutput({}, commandName, requestSeq, success, message);
project.getLanguageService().applyCodeActionCommand(command).then(
result => { output(/*success*/ true, result.successMessage); },
error => { output(/*success*/ false, error); });
_result => { /* TODO: GH#20447 report success message? */ },
_error => { /* TODO: GH#20447 report errors */ });
}
return {};
}
private getStartAndEndPosition(args: protocol.FileRangeRequestArgs, scriptInfo: ScriptInfo) {
@ -1705,17 +1705,17 @@ namespace ts.server {
private handlers = createMapFromTemplate<(request: protocol.Request) => HandlerResponse>({
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
this.projectService.openExternalProject(request.arguments, /*suppressRefreshOfInferredProjects*/ false);
// TODO: report errors
// TODO: GH#20447 report errors
return this.requiredResponse(/*response*/ true);
},
[CommandNames.OpenExternalProjects]: (request: protocol.OpenExternalProjectsRequest) => {
this.projectService.openExternalProjects(request.arguments.projects);
// TODO: report errors
// TODO: GH#20447 report errors
return this.requiredResponse(/*response*/ true);
},
[CommandNames.CloseExternalProject]: (request: protocol.CloseExternalProjectRequest) => {
this.projectService.closeExternalProject(request.arguments.projectFileName);
// TODO: report errors
// TODO: GH#20447 report errors
return this.requiredResponse(/*response*/ true);
},
[CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => {
@ -1957,8 +1957,7 @@ namespace ts.server {
return this.requiredResponse(this.getCodeFixes(request.arguments, /*simplifiedResult*/ false));
},
[CommandNames.ApplyCodeActionCommand]: (request: protocol.ApplyCodeActionCommandRequest) => {
this.applyCodeActionCommand(request.command, request.seq, request.arguments);
return this.notRequired(); // Response will come asynchronously.
return this.requiredResponse(this.applyCodeActionCommand(request.arguments));
},
[CommandNames.GetSupportedCodeFixes]: () => {
return this.requiredResponse(this.getSupportedCodeFixes());

View file

@ -7072,7 +7072,7 @@ declare namespace ts.server {
private getApplicableRefactors(args);
private getEditsForRefactor(args, simplifiedResult);
private getCodeFixes(args, simplifiedResult);
private applyCodeActionCommand(commandName, requestSeq, args);
private applyCodeActionCommand(args);
private getStartAndEndPosition(args, scriptInfo);
private mapCodeAction({description, changes: unmappedChanges, commands}, scriptInfo);
private mapTextChangesToCodeEdits(project, textChanges);