Diagnostics enhancement request

Arthur McGibbon arthur.mcgibbon at gmail.com
Wed Jul 17 10:50:00 UTC 2024


Currently compiler diagnostics are sent back with some positional
information.  See
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/tools/Diagnostic.html

The Diagnostic class contains range info...
  getStartPosition - file offset (no line or column number)
  getEndPosition - file offset (no line or column number)

And it contains more specific position info...
  getLineNumber - line number in file.
  getColumnNumber - column number in file.
  getPosition - file offset.

For LSP (Language Server Protocol) the requirements for a diagnostic
location are startLine, startColumn, endLine, endColumn.

Because of this, taking a javac diagnostic and transforming it into LSP
diagnostic requires parsing the source file and transforming
`getStartPosition`, `getEndPosition` and sometimes `getPosition` into
line/column numbers.

`getColumnNumber` can't be used (without source file parsing) because it
returns a position based on the assumption that a tab is 8 spaces which
isn't true in most code from what I've seen and tabs are treated as a
single character in LSP.

So ideally I'd like methods `getStartLine`, `getEndLine`,
`getStartColNumber`, `getEndColNumber` added to the Diagnostic class.
Where the `colNumber` methods treat a tab as a single character.

Is this possible?  I imagine the data is already available at the time the
diagnostics are created.

regards
Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20240717/d8a4f3d8/attachment.htm>


More information about the compiler-dev mailing list