Skip to content

Commit 55a1b50

Browse files
author
Armando Aguirre
committed
Revert "Removed public commands"
This reverts commit 40751ba.
1 parent 0985afd commit 55a1b50

File tree

4 files changed

+99
-19
lines changed

4 files changed

+99
-19
lines changed

src/server/protocol.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ namespace ts.server.protocol {
136136
SelectionRange = "selectionRange",
137137
/* @internal */
138138
SelectionRangeFull = "selectionRange-full",
139+
ToggleLineComment = "toggleLineComment",
139140
/* @internal */
140141
ToggleLineCommentFull = "toggleLineComment-full",
142+
ToggleMultilineComment = "toggleMultilineComment",
141143
/* @internal */
142144
ToggleMultilineCommentFull = "toggleMultilineComment-full",
145+
CommentSelection = "commentSelection",
143146
/* @internal */
144147
CommentSelectionFull = "commentSelection-full",
148+
UncommentSelection = "uncommentSelection",
145149
/* @internal */
146150
UncommentSelectionFull = "uncommentSelection-full",
147151
PrepareCallHierarchy = "prepareCallHierarchy",
@@ -1540,8 +1544,23 @@ namespace ts.server.protocol {
15401544
parent?: SelectionRange;
15411545
}
15421546

1547+
export interface ToggleLineCommentRequest extends FileRequest {
1548+
command: CommandTypes.ToggleLineComment;
1549+
arguments: FileRangeRequestArgs;
1550+
}
1551+
1552+
export interface ToggleMultilineCommentRequest extends FileRequest {
1553+
command: CommandTypes.ToggleMultilineComment;
1554+
arguments: FileRangeRequestArgs;
1555+
}
1556+
15431557
export interface CommentSelectionRequest extends FileRequest {
1558+
command: CommandTypes.CommentSelection;
1559+
arguments: FileRangeRequestArgs;
1560+
}
15441561

1562+
export interface UncommentSelectionRequest extends FileRequest {
1563+
command: CommandTypes.UncommentSelection;
15451564
arguments: FileRangeRequestArgs;
15461565
}
15471566

src/server/session.ts

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/testRunner/unittests/tsserver/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ namespace ts.server {
272272
CommandNames.PrepareCallHierarchy,
273273
CommandNames.ProvideCallHierarchyIncomingCalls,
274274
CommandNames.ProvideCallHierarchyOutgoingCalls,
275-
CommandNames.ToggleLineCommentFull,
276-
CommandNames.ToggleMultilineCommentFull,
277-
CommandNames.CommentSelectionFull,
278-
CommandNames.UncommentSelectionFull,
275+
CommandNames.ToggleLineComment,
276+
CommandNames.ToggleMultilineComment,
277+
CommandNames.CommentSelection,
278+
CommandNames.UncommentSelection,
279279
];
280280

281281
it("should not throw when commands are executed with invalid arguments", () => {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6304,6 +6304,10 @@ declare namespace ts.server.protocol {
63046304
GetEditsForFileRename = "getEditsForFileRename",
63056305
ConfigurePlugin = "configurePlugin",
63066306
SelectionRange = "selectionRange",
6307+
ToggleLineComment = "toggleLineComment",
6308+
ToggleMultilineComment = "toggleMultilineComment",
6309+
CommentSelection = "commentSelection",
6310+
UncommentSelection = "uncommentSelection",
63076311
PrepareCallHierarchy = "prepareCallHierarchy",
63086312
ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls",
63096313
ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls"
@@ -7328,7 +7332,20 @@ declare namespace ts.server.protocol {
73287332
textSpan: TextSpan;
73297333
parent?: SelectionRange;
73307334
}
7335+
interface ToggleLineCommentRequest extends FileRequest {
7336+
command: CommandTypes.ToggleLineComment;
7337+
arguments: FileRangeRequestArgs;
7338+
}
7339+
interface ToggleMultilineCommentRequest extends FileRequest {
7340+
command: CommandTypes.ToggleMultilineComment;
7341+
arguments: FileRangeRequestArgs;
7342+
}
73317343
interface CommentSelectionRequest extends FileRequest {
7344+
command: CommandTypes.CommentSelection;
7345+
arguments: FileRangeRequestArgs;
7346+
}
7347+
interface UncommentSelectionRequest extends FileRequest {
7348+
command: CommandTypes.UncommentSelection;
73327349
arguments: FileRangeRequestArgs;
73337350
}
73347351
/**

0 commit comments

Comments
 (0)