From 937e3e88e122e3ffb62d686a2c0f34d42cbfb769 Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Tue, 25 Feb 2020 14:34:31 -0800 Subject: [PATCH] Added simplified result to ToggleComment --- src/server/session.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 386c737e49a..d94f0df7f5a 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -2196,20 +2196,32 @@ namespace ts.server { }); } - private toggleLineComment(args: protocol.ToggleLineCommentRequestArgs, simplifiedResult: boolean) { + private toggleLineComment(args: protocol.ToggleLineCommentRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] { const { file, project } = this.getFileAndProject(args); - const result = project.getLanguageService().toggleLineComment(file, args.textRanges); + const textChanges = project.getLanguageService().toggleLineComment(file, args.textRanges); - return simplifiedResult ? [] : result; + if (simplifiedResult) { + const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; + + return textChanges.map(textChange => this.convertTextChangeToCodeEdit(textChange, scriptInfo)); + } + + return textChanges; } - private toggleMultilineComment(args: protocol.ToggleMultilineCommentRequestArgs, simplifiedResult: boolean) { + private toggleMultilineComment(args: protocol.ToggleMultilineCommentRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] { const { file, project } = this.getFileAndProject(args); - const result = project.getLanguageService().toggleMultilineComment(file, args.textRanges); + const textChanges = project.getLanguageService().toggleMultilineComment(file, args.textRanges); - return simplifiedResult ? [] : result; + if (simplifiedResult) { + const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; + + return textChanges.map(textChange => this.convertTextChangeToCodeEdit(textChange, scriptInfo)); + } + + return textChanges; } private mapSelectionRange(selectionRange: SelectionRange, scriptInfo: ScriptInfo): protocol.SelectionRange {