sbt / zinc

Scala incremental compiler library, used by sbt and other build tools
Apache License 2.0
333 stars 118 forks source link

Parse column/position information from javac error messages #1372

Closed vasilmkd closed 2 months ago

vasilmkd commented 2 months ago

IntelliJ IDEA expects compiler error messages to be reported with a (line, column) pair. xsbti.Position instances produced for error messages coming from javac do not contain a value for pointer.

https://youtrack.jetbrains.com/issue/SCL-22799/Missing-Line-and-Column-Info-in-Compilation-Error-Message-for-Java-SBT-project

Technically, there is enough information to calculate this, by combining the line and offset information. But this requires reading the source file from disk, which I'm trying to avoid.

At the moment, both sbt.internal.inc.javac.DiagnosticsReporter.PositionImpl and sbt.internal.inc.javac.JavaPosition implement def pointer: Optional[Integer] = o2jo(None).

It should be possible to parse this information and include it in the Position instances.

vasilmkd commented 2 months ago

Furthermore, the information returned by offset in JavaPosition is actually the column information, not the offset from the beginning of the file.

https://github.com/sbt/zinc/blob/4eacff2a9bf5c8750bfc5096955065ce67f4e68a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala#L185-L196 https://github.com/sbt/zinc/blob/4eacff2a9bf5c8750bfc5096955065ce67f4e68a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala#L295-L296

getOffset is called on the contents of the error message, not the contents of the file.