Class TextEditUtils

java.lang.Object
org.eclipse.lemminx.commons.TextEditUtils

public class TextEditUtils extends Object
Utilities for TextEdit.
Author:
Angelo ZERR
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    adjustOffsetWithLeftWhitespaces(int leftLimit, int to, CharSequence text)
    Returns the offset of the first whitespace that's found in the given range [leftLimit,to] from the left of the to, and leftLimit otherwise.
    static String
    applyEdits(TextDocument document, List<? extends org.eclipse.lsp4j.TextEdit> edits)
     
    static org.eclipse.lsp4j.TextEdit
    createTextEditIfNeeded(int from, int to, String expectedContent, TextDocument textDocument)
    Returns the TextEdit to insert the given expected content from the given range (from, to) of the given text document and null otherwise.
    static org.eclipse.lsp4j.WorkspaceEdit
    createWorkspaceEdit(List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.TextDocumentEdit,org.eclipse.lsp4j.ResourceOperation>> documentChanges)
     
    static List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.TextEdit,org.eclipse.lsp4j.SnippetTextEdit>>
    toEitherTextEdits(List<org.eclipse.lsp4j.TextEdit> textEdits)
    Converts a list of TextEdit to a list of Eitherinvalid input: '<'TextEdit, SnippetTextEdit>.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toEitherTextEdits

      public static List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.TextEdit,org.eclipse.lsp4j.SnippetTextEdit>> toEitherTextEdits(List<org.eclipse.lsp4j.TextEdit> textEdits)
      Converts a list of TextEdit to a list of Eitherinvalid input: '<'TextEdit, SnippetTextEdit>.

      In LSP4J 1.0.0, TextDocumentEdit requires Either wrappers to support both regular text edits and snippet text edits with placeholders.

      Parameters:
      textEdits - the list of text edits
      Returns:
      the list of Either wrappers containing the text edits
    • createTextEditIfNeeded

      public static org.eclipse.lsp4j.TextEdit createTextEditIfNeeded(int from, int to, String expectedContent, TextDocument textDocument)
      Returns the TextEdit to insert the given expected content from the given range (from, to) of the given text document and null otherwise.
      Parameters:
      from - the range from.
      to - the range to.
      expectedContent - the expected content.
      textDocument - the text document.
      Returns:
      the TextEdit to insert the given expected content from the given range (from, to) of the given text document and null otherwise.
    • applyEdits

      public static String applyEdits(TextDocument document, List<? extends org.eclipse.lsp4j.TextEdit> edits) throws BadLocationException
      Throws:
      BadLocationException
    • adjustOffsetWithLeftWhitespaces

      public static int adjustOffsetWithLeftWhitespaces(int leftLimit, int to, CharSequence text)
      Returns the offset of the first whitespace that's found in the given range [leftLimit,to] from the left of the to, and leftLimit otherwise.
      Parameters:
      leftLimit - the left limit range.
      to - the to range.
      Returns:
      the offset of the first whitespace that's found in the given range [leftLimit,to] from the left of the to, and leftLimit otherwise.
    • createWorkspaceEdit

      public static org.eclipse.lsp4j.WorkspaceEdit createWorkspaceEdit(List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.TextDocumentEdit,org.eclipse.lsp4j.ResourceOperation>> documentChanges)