Class Positions

java.lang.Object
org.clafer.lsp.Positions

public final class Positions extends Object
Converts between the frontend's positions and LSP's, on the text of a document.

The frontend's lines and columns start at 1, and its columns are the compiler's: a tab moves to the column after the next multiple of 8, and every other character, a carriage return included, is one column. LSP's lines and characters start at 0, and a character is a UTF-16 code unit, as a Java char is.

  • Constructor Details

    • Positions

      public Positions(String text)
      Parameters:
      text - the text of the document
  • Method Details

    • line

      public String line(int line)
      Parameters:
      line - a line, from 0
      Returns:
      its text without the newline, or empty if there is no such line
    • lineCount

      public int lineCount()
      Returns:
      the number of lines, the last one after the last newline included
    • toLsp

      public org.eclipse.lsp4j.Position toLsp(int line, int column)
      Parameters:
      line - a line of the frontend, from 1
      column - a column of the frontend, from 1
      Returns:
      the LSP position: past the end of its line if the column is, and at the end of the document if the line is past it
    • fromLsp

      public int[] fromLsp(org.eclipse.lsp4j.Position position)
      Parameters:
      position - an LSP position
      Returns:
      the frontend's line and column there, as {line, column}
    • toLsp

      public org.eclipse.lsp4j.Range toLsp(SourceSpan span)
      Parameters:
      span - a span of the frontend
      Returns:
      its LSP range
    • toVisibleLsp

      public org.eclipse.lsp4j.Range toVisibleLsp(SourceSpan span)
      Parameters:
      span - a span of the frontend
      Returns:
      its LSP range, widened to the character at its start if it is empty and there is one, so that every editor shows it
    • text

      public String text(org.eclipse.lsp4j.Range range)
      Parameters:
      range - a range in this document
      Returns:
      its text