Package org.eclipse.lemminx.commons
Class CodeActionFactory
java.lang.Object
org.eclipse.lemminx.commons.CodeActionFactory
Factory for simple
CodeAction-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.lsp4j.CodeActioncreateCommand(String title, String commandId, List<Object> commandParams, org.eclipse.lsp4j.Diagnostic diagnostic) Makes a CodeAction to call a command from the available server commands.static org.eclipse.lsp4j.CodeActioncreateFile(String title, String fileURI, String fileContent, org.eclipse.lsp4j.Diagnostic diagnostic) Makes a CodeAction to create a file and add content to the file.static org.eclipse.lsp4j.WorkspaceEditcreateFileEdit(String fileURI, String fileContent) Returns the file edit to create the file with the givenfileURIand the givenfileContent.static StringescapeSnippetText(String text) Escapes special snippet characters (\,$, }) so that the given text is treated as literal content inside a snippet.static org.eclipse.lsp4j.WorkspaceEditgetReplaceWorkspaceEdit(String replaceText, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document) Returns the workspace edit of a given replacement text and range.static org.eclipse.lsp4j.WorkspaceEditgetReplaceWorkspaceEdit(String replaceText, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document, boolean snippetSupport) Returns the workspace edit that replaces the given range with the given text.static org.eclipse.lsp4j.CodeActioninsert(String title, org.eclipse.lsp4j.Position position, String insertText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) Create a CodeAction to insert a new content at the end of the given range.static org.eclipse.lsp4j.CodeActioninsert(String title, org.eclipse.lsp4j.Position position, String insertText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, boolean snippetSupport) Creates aCodeActionthat inserts the given text at the given position.static org.eclipse.lsp4j.TextEditinsertEdit(String insertText, org.eclipse.lsp4j.Position position) static org.eclipse.lsp4j.TextDocumentEditinsertEdit(String insertText, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.TextDocumentItem document) Returns the text edit to insert a new content at the end of the given range.static org.eclipse.lsp4j.TextDocumentEditinsertEdit(String insertText, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.TextDocumentItem document, boolean snippetSupport) static org.eclipse.lsp4j.TextDocumentEditinsertEdits(org.eclipse.lsp4j.TextDocumentItem document, List<org.eclipse.lsp4j.TextEdit> edits) static org.eclipse.lsp4j.TextDocumentEditinsertEdits(org.eclipse.lsp4j.TextDocumentItem document, List<org.eclipse.lsp4j.TextEdit> edits, boolean snippetSupport) static org.eclipse.lsp4j.CodeActionremove(String title, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) Create a CodeAction to remove the content from the given range.static org.eclipse.lsp4j.CodeActionreplace(String title, List<org.eclipse.lsp4j.TextEdit> replace, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) static org.eclipse.lsp4j.CodeActionreplace(String title, org.eclipse.lsp4j.Range range, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) static org.eclipse.lsp4j.CodeActionreplace(String title, org.eclipse.lsp4j.Range range, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, boolean snippetSupport) Creates aCodeActionthat replaces the given range with the given text.static org.eclipse.lsp4j.CodeActionreplaceAt(String title, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, Collection<org.eclipse.lsp4j.Range> ranges) static org.eclipse.lsp4j.CodeActionreplaceAt(String title, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, Collection<org.eclipse.lsp4j.Range> ranges, boolean snippetSupport)
-
Constructor Details
-
CodeActionFactory
public CodeActionFactory()
-
-
Method Details
-
remove
public static org.eclipse.lsp4j.CodeAction remove(String title, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) Create a CodeAction to remove the content from the given range.- Parameters:
title-range-document-diagnostic-- Returns:
-
insert
public static org.eclipse.lsp4j.CodeAction insert(String title, org.eclipse.lsp4j.Position position, String insertText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic) Create a CodeAction to insert a new content at the end of the given range.- Parameters:
title-insertText-document-diagnostic-range-- Returns:
- the CodeAction to insert a new content at the end of the given range.
-
insert
public static org.eclipse.lsp4j.CodeAction insert(String title, org.eclipse.lsp4j.Position position, String insertText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, boolean snippetSupport) Creates aCodeActionthat inserts the given text at the given position. WhensnippetSupportis true, the text is treated as a LSP 3.18 snippet (with tabstops$1,$0) and wrapped in aSnippetTextEdit; otherwise a plainTextEditis used.- Parameters:
title- the code action title.position- the position to insert at.insertText- the text to insert (plain or snippet syntax).document- the text document.diagnostic- the diagnostic this code action fixes.snippetSupport- true if the client supportsworkspace.workspaceEdit.snippetEditSupport.- Returns:
- the code action.
-
insertEdit
public static org.eclipse.lsp4j.TextDocumentEdit insertEdit(String insertText, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.TextDocumentItem document) Returns the text edit to insert a new content at the end of the given range.- Parameters:
insertText- text to insert.position- the position.document- the text document.- Returns:
- the text edit to insert a new content at the end of the given range.
-
insertEdit
public static org.eclipse.lsp4j.TextDocumentEdit insertEdit(String insertText, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.TextDocumentItem document, boolean snippetSupport) -
insertEdit
public static org.eclipse.lsp4j.TextEdit insertEdit(String insertText, org.eclipse.lsp4j.Position position) -
insertEdits
public static org.eclipse.lsp4j.TextDocumentEdit insertEdits(org.eclipse.lsp4j.TextDocumentItem document, List<org.eclipse.lsp4j.TextEdit> edits) -
insertEdits
public static org.eclipse.lsp4j.TextDocumentEdit insertEdits(org.eclipse.lsp4j.TextDocumentItem document, List<org.eclipse.lsp4j.TextEdit> edits, boolean snippetSupport) -
replace
-
replace
-
getReplaceWorkspaceEdit
public static org.eclipse.lsp4j.WorkspaceEdit getReplaceWorkspaceEdit(String replaceText, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document) Returns the workspace edit of a given replacement text and range.- Parameters:
replaceText- the text to replace.range- the range to replace the text over.document- the text document.- Returns:
- the workspace edit of a given replacement text and range.
-
replace
public static org.eclipse.lsp4j.CodeAction replace(String title, org.eclipse.lsp4j.Range range, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, boolean snippetSupport) Creates aCodeActionthat replaces the given range with the given text. WhensnippetSupportis true, the text is treated as a LSP 3.18 snippet (with tabstops$1,$0) and wrapped in aSnippetTextEdit; otherwise a plainTextEditis used.- Parameters:
title- the code action title.range- the range to replace.replaceText- the replacement text (plain or snippet syntax).document- the text document.diagnostic- the diagnostic this code action fixes.snippetSupport- true if the client supportsworkspace.workspaceEdit.snippetEditSupport.- Returns:
- the code action.
-
getReplaceWorkspaceEdit
public static org.eclipse.lsp4j.WorkspaceEdit getReplaceWorkspaceEdit(String replaceText, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.TextDocumentItem document, boolean snippetSupport) Returns the workspace edit that replaces the given range with the given text. WhensnippetSupportis true, the text is wrapped in aSnippetTextEdit; otherwise a plainTextEditis used.- Parameters:
replaceText- the replacement text (plain or snippet syntax).range- the range to replace.document- the text document.snippetSupport- true if the client supportsworkspace.workspaceEdit.snippetEditSupport.- Returns:
- the workspace edit.
-
replaceAt
public static org.eclipse.lsp4j.CodeAction replaceAt(String title, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, Collection<org.eclipse.lsp4j.Range> ranges) -
replaceAt
public static org.eclipse.lsp4j.CodeAction replaceAt(String title, String replaceText, org.eclipse.lsp4j.TextDocumentItem document, org.eclipse.lsp4j.Diagnostic diagnostic, Collection<org.eclipse.lsp4j.Range> ranges, boolean snippetSupport) -
escapeSnippetText
Escapes special snippet characters (\,$, }) so that the given text is treated as literal content inside a snippet. Call this on any grammar-provided value before concatenating it with snippet tabstops like$0.- Parameters:
text- the plain text to escape.- Returns:
- the escaped text safe for use in a snippet.
-
createFile
public static org.eclipse.lsp4j.CodeAction createFile(String title, String fileURI, String fileContent, org.eclipse.lsp4j.Diagnostic diagnostic) Makes a CodeAction to create a file and add content to the file.- Parameters:
title- The displayed name of the CodeActionfileURI- The file to createfileContent- The text to put into the newly created document.diagnostic- The diagnostic that this CodeAction will fix
-
createFileEdit
Returns the file edit to create the file with the givenfileURIand the givenfileContent.- Parameters:
fileURI- the file URI to create.fileContent- the file content.- Returns:
- the file edit to create the file with the given
fileURIand the givenfileContent.
-
createCommand
public static org.eclipse.lsp4j.CodeAction createCommand(String title, String commandId, List<Object> commandParams, org.eclipse.lsp4j.Diagnostic diagnostic) Makes a CodeAction to call a command from the available server commands.- Parameters:
title- The displayed name of the CodeActioncommandId- The id of the given command to add as CodeActioncommandParams- The document URI of the document the command is called ondiagnostic- The diagnostic that this CodeAction will fix
-