@@ -2201,36 +2201,68 @@ namespace ts.server {
22012201 } ) ;
22022202 }
22032203
2204- private toggleLineComment ( args : protocol . FileRangeRequestArgs ) : TextChange [ ] {
2204+ private toggleLineComment ( args : protocol . FileRangeRequestArgs , simplifiedResult : boolean ) : TextChange [ ] | protocol . CodeEdit [ ] {
22052205 const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
22062206 const scriptInfo = this . projectService . getScriptInfo ( file ) ! ;
22072207 const textRange = this . getRange ( args , scriptInfo ) ;
22082208
2209- return languageService . toggleLineComment ( file , textRange ) ;
2209+ const textChanges = languageService . toggleLineComment ( file , textRange ) ;
2210+
2211+ if ( simplifiedResult ) {
2212+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
2213+
2214+ return textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) ;
2215+ }
2216+
2217+ return textChanges ;
22102218 }
22112219
2212- private toggleMultilineComment ( args : protocol . FileRangeRequestArgs ) : TextChange [ ] {
2220+ private toggleMultilineComment ( args : protocol . FileRangeRequestArgs , simplifiedResult : boolean ) : TextChange [ ] | protocol . CodeEdit [ ] {
22132221 const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
22142222 const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
22152223 const textRange = this . getRange ( args , scriptInfo ) ;
22162224
2217- return languageService . toggleMultilineComment ( file , textRange ) ;
2225+ const textChanges = languageService . toggleMultilineComment ( file , textRange ) ;
2226+
2227+ if ( simplifiedResult ) {
2228+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
2229+
2230+ return textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) ;
2231+ }
2232+
2233+ return textChanges ;
22182234 }
22192235
2220- private commentSelection ( args : protocol . FileRangeRequestArgs ) : TextChange [ ] {
2236+ private commentSelection ( args : protocol . FileRangeRequestArgs , simplifiedResult : boolean ) : TextChange [ ] | protocol . CodeEdit [ ] {
22212237 const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
22222238 const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
22232239 const textRange = this . getRange ( args , scriptInfo ) ;
22242240
2225- return languageService . commentSelection ( file , textRange ) ;
2241+ const textChanges = languageService . commentSelection ( file , textRange ) ;
2242+
2243+ if ( simplifiedResult ) {
2244+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
2245+
2246+ return textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) ;
2247+ }
2248+
2249+ return textChanges ;
22262250 }
22272251
2228- private uncommentSelection ( args : protocol . FileRangeRequestArgs ) : TextChange [ ] {
2252+ private uncommentSelection ( args : protocol . FileRangeRequestArgs , simplifiedResult : boolean ) : TextChange [ ] | protocol . CodeEdit [ ] {
22292253 const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
22302254 const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
22312255 const textRange = this . getRange ( args , scriptInfo ) ;
22322256
2233- return languageService . uncommentSelection ( file , textRange ) ;
2257+ const textChanges = languageService . uncommentSelection ( file , textRange ) ;
2258+
2259+ if ( simplifiedResult ) {
2260+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
2261+
2262+ return textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) ;
2263+ }
2264+
2265+ return textChanges ;
22342266 }
22352267
22362268 private mapSelectionRange ( selectionRange : SelectionRange , scriptInfo : ScriptInfo ) : protocol . SelectionRange {
@@ -2678,17 +2710,29 @@ namespace ts.server {
26782710 [ CommandNames . ProvideCallHierarchyOutgoingCalls ] : ( request : protocol . ProvideCallHierarchyOutgoingCallsRequest ) => {
26792711 return this . requiredResponse ( this . provideCallHierarchyOutgoingCalls ( request . arguments ) ) ;
26802712 } ,
2681- [ CommandNames . ToggleLineCommentFull ] : ( request : protocol . CommentSelectionRequest ) => {
2682- return this . requiredResponse ( this . toggleLineComment ( request . arguments ) ) ;
2713+ [ CommandNames . ToggleLineComment ] : ( request : protocol . ToggleLineCommentRequest ) => {
2714+ return this . requiredResponse ( this . toggleLineComment ( request . arguments , /*simplifiedResult*/ true ) ) ;
2715+ } ,
2716+ [ CommandNames . ToggleLineCommentFull ] : ( request : protocol . ToggleLineCommentRequest ) => {
2717+ return this . requiredResponse ( this . toggleLineComment ( request . arguments , /*simplifiedResult*/ false ) ) ;
26832718 } ,
2684- [ CommandNames . ToggleMultilineCommentFull ] : ( request : protocol . CommentSelectionRequest ) => {
2685- return this . requiredResponse ( this . toggleMultilineComment ( request . arguments ) ) ;
2719+ [ CommandNames . ToggleMultilineComment ] : ( request : protocol . ToggleMultilineCommentRequest ) => {
2720+ return this . requiredResponse ( this . toggleMultilineComment ( request . arguments , /*simplifiedResult*/ true ) ) ;
2721+ } ,
2722+ [ CommandNames . ToggleMultilineCommentFull ] : ( request : protocol . ToggleMultilineCommentRequest ) => {
2723+ return this . requiredResponse ( this . toggleMultilineComment ( request . arguments , /*simplifiedResult*/ false ) ) ;
2724+ } ,
2725+ [ CommandNames . CommentSelection ] : ( request : protocol . CommentSelectionRequest ) => {
2726+ return this . requiredResponse ( this . commentSelection ( request . arguments , /*simplifiedResult*/ true ) ) ;
26862727 } ,
26872728 [ CommandNames . CommentSelectionFull ] : ( request : protocol . CommentSelectionRequest ) => {
2688- return this . requiredResponse ( this . commentSelection ( request . arguments ) ) ;
2729+ return this . requiredResponse ( this . commentSelection ( request . arguments , /*simplifiedResult*/ false ) ) ;
2730+ } ,
2731+ [ CommandNames . UncommentSelection ] : ( request : protocol . UncommentSelectionRequest ) => {
2732+ return this . requiredResponse ( this . uncommentSelection ( request . arguments , /*simplifiedResult*/ true ) ) ;
26892733 } ,
2690- [ CommandNames . UncommentSelectionFull ] : ( request : protocol . CommentSelectionRequest ) => {
2691- return this . requiredResponse ( this . uncommentSelection ( request . arguments ) ) ;
2734+ [ CommandNames . UncommentSelectionFull ] : ( request : protocol . UncommentSelectionRequest ) => {
2735+ return this . requiredResponse ( this . uncommentSelection ( request . arguments , /*simplifiedResult*/ false ) ) ;
26922736 } ,
26932737 } ) ;
26942738
0 commit comments