Revert "Removed public commands"

This reverts commit 40751ba89b.
This commit is contained in:
Armando Aguirre
2020-07-09 15:55:51 -07:00
parent 0985afd51a
commit 55a1b50e7a
4 changed files with 100 additions and 20 deletions
+20 -1
View File
@@ -136,12 +136,16 @@ namespace ts.server.protocol {
SelectionRange = "selectionRange",
/* @internal */
SelectionRangeFull = "selectionRange-full",
ToggleLineComment = "toggleLineComment",
/* @internal */
ToggleLineCommentFull = "toggleLineComment-full",
ToggleMultilineComment = "toggleMultilineComment",
/* @internal */
ToggleMultilineCommentFull = "toggleMultilineComment-full",
CommentSelection = "commentSelection",
/* @internal */
CommentSelectionFull = "commentSelection-full",
UncommentSelection = "uncommentSelection",
/* @internal */
UncommentSelectionFull = "uncommentSelection-full",
PrepareCallHierarchy = "prepareCallHierarchy",
@@ -1540,8 +1544,23 @@ namespace ts.server.protocol {
parent?: SelectionRange;
}
export interface CommentSelectionRequest extends FileRequest {
export interface ToggleLineCommentRequest extends FileRequest {
command: CommandTypes.ToggleLineComment;
arguments: FileRangeRequestArgs;
}
export interface ToggleMultilineCommentRequest extends FileRequest {
command: CommandTypes.ToggleMultilineComment;
arguments: FileRangeRequestArgs;
}
export interface CommentSelectionRequest extends FileRequest {
command: CommandTypes.CommentSelection;
arguments: FileRangeRequestArgs;
}
export interface UncommentSelectionRequest extends FileRequest {
command: CommandTypes.UncommentSelection;
arguments: FileRangeRequestArgs;
}
+59 -15
View File
@@ -2201,36 +2201,68 @@ namespace ts.server {
});
}
private toggleLineComment(args: protocol.FileRangeRequestArgs): TextChange[] {
private toggleLineComment(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const scriptInfo = this.projectService.getScriptInfo(file)!;
const textRange = this.getRange(args, scriptInfo);
return languageService.toggleLineComment(file, textRange);
const textChanges = languageService.toggleLineComment(file, textRange);
if (simplifiedResult) {
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
return textChanges.map(textChange => this.convertTextChangeToCodeEdit(textChange, scriptInfo));
}
return textChanges;
}
private toggleMultilineComment(args: protocol.FileRangeRequestArgs): TextChange[] {
private toggleMultilineComment(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const textRange = this.getRange(args, scriptInfo);
return languageService.toggleMultilineComment(file, textRange);
const textChanges = languageService.toggleMultilineComment(file, textRange);
if (simplifiedResult) {
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
return textChanges.map(textChange => this.convertTextChangeToCodeEdit(textChange, scriptInfo));
}
return textChanges;
}
private commentSelection(args: protocol.FileRangeRequestArgs): TextChange[] {
private commentSelection(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const textRange = this.getRange(args, scriptInfo);
return languageService.commentSelection(file, textRange);
const textChanges = languageService.commentSelection(file, textRange);
if (simplifiedResult) {
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
return textChanges.map(textChange => this.convertTextChangeToCodeEdit(textChange, scriptInfo));
}
return textChanges;
}
private uncommentSelection(args: protocol.FileRangeRequestArgs): TextChange[] {
private uncommentSelection(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const textRange = this.getRange(args, scriptInfo);
return languageService.uncommentSelection(file, textRange);
const textChanges = languageService.uncommentSelection(file, textRange);
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 {
@@ -2678,17 +2710,29 @@ namespace ts.server {
[CommandNames.ProvideCallHierarchyOutgoingCalls]: (request: protocol.ProvideCallHierarchyOutgoingCallsRequest) => {
return this.requiredResponse(this.provideCallHierarchyOutgoingCalls(request.arguments));
},
[CommandNames.ToggleLineCommentFull]: (request: protocol.CommentSelectionRequest) => {
return this.requiredResponse(this.toggleLineComment(request.arguments));
[CommandNames.ToggleLineComment]: (request: protocol.ToggleLineCommentRequest) => {
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/ true));
},
[CommandNames.ToggleMultilineCommentFull]: (request: protocol.CommentSelectionRequest) => {
return this.requiredResponse(this.toggleMultilineComment(request.arguments));
[CommandNames.ToggleLineCommentFull]: (request: protocol.ToggleLineCommentRequest) => {
return this.requiredResponse(this.toggleLineComment(request.arguments, /*simplifiedResult*/ false));
},
[CommandNames.ToggleMultilineComment]: (request: protocol.ToggleMultilineCommentRequest) => {
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/ true));
},
[CommandNames.ToggleMultilineCommentFull]: (request: protocol.ToggleMultilineCommentRequest) => {
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/ false));
},
[CommandNames.CommentSelection]: (request: protocol.CommentSelectionRequest) => {
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/ true));
},
[CommandNames.CommentSelectionFull]: (request: protocol.CommentSelectionRequest) => {
return this.requiredResponse(this.commentSelection(request.arguments));
return this.requiredResponse(this.commentSelection(request.arguments, /*simplifiedResult*/ false));
},
[CommandNames.UncommentSelectionFull]: (request: protocol.CommentSelectionRequest) => {
return this.requiredResponse(this.uncommentSelection(request.arguments));
[CommandNames.UncommentSelection]: (request: protocol.UncommentSelectionRequest) => {
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ true));
},
[CommandNames.UncommentSelectionFull]: (request: protocol.UncommentSelectionRequest) => {
return this.requiredResponse(this.uncommentSelection(request.arguments, /*simplifiedResult*/ false));
},
});
+4 -4
View File
@@ -272,10 +272,10 @@ namespace ts.server {
CommandNames.PrepareCallHierarchy,
CommandNames.ProvideCallHierarchyIncomingCalls,
CommandNames.ProvideCallHierarchyOutgoingCalls,
CommandNames.ToggleLineCommentFull,
CommandNames.ToggleMultilineCommentFull,
CommandNames.CommentSelectionFull,
CommandNames.UncommentSelectionFull,
CommandNames.ToggleLineComment,
CommandNames.ToggleMultilineComment,
CommandNames.CommentSelection,
CommandNames.UncommentSelection,
];
it("should not throw when commands are executed with invalid arguments", () => {
+17
View File
@@ -6304,6 +6304,10 @@ declare namespace ts.server.protocol {
GetEditsForFileRename = "getEditsForFileRename",
ConfigurePlugin = "configurePlugin",
SelectionRange = "selectionRange",
ToggleLineComment = "toggleLineComment",
ToggleMultilineComment = "toggleMultilineComment",
CommentSelection = "commentSelection",
UncommentSelection = "uncommentSelection",
PrepareCallHierarchy = "prepareCallHierarchy",
ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls",
ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls"
@@ -7328,7 +7332,20 @@ declare namespace ts.server.protocol {
textSpan: TextSpan;
parent?: SelectionRange;
}
interface ToggleLineCommentRequest extends FileRequest {
command: CommandTypes.ToggleLineComment;
arguments: FileRangeRequestArgs;
}
interface ToggleMultilineCommentRequest extends FileRequest {
command: CommandTypes.ToggleMultilineComment;
arguments: FileRangeRequestArgs;
}
interface CommentSelectionRequest extends FileRequest {
command: CommandTypes.CommentSelection;
arguments: FileRangeRequestArgs;
}
interface UncommentSelectionRequest extends FileRequest {
command: CommandTypes.UncommentSelection;
arguments: FileRangeRequestArgs;
}
/**