-
Couldn't load subscription status.
- Fork 106
feat: improve error highlighting to use precise ranges #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Errors are now highlighted using the actual error range (startColumn/endColumn), not the entire line. - Renamed LineMapper to PositionMapper, as it now maps both lines and columns (instrumentation can shift columns too). - Replaced all Int => Int usages with Option[PositionMapper]. - Added tests for column mapping in PositionMapperSpecs (formerly LineMapperSpecs). - Updated the Problem type: now includes severity, line, message, startColumn, and endColumn.
| val clampedStart = (start min (lineLength + 1)) max 1 | ||
| val clampedEnd = (end min (lineLength + 1)) max clampedStart | ||
| (lineInfo.from + clampedStart - 1, lineInfo.from + clampedEnd - 1) | ||
| case (Some(start), _) if start > 0 => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this ever happen? Maybe lets throw here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 😅. I honestly can't remember what the use case for this was. I’m sure I had a reason, but from what I’ve tested now, I couldn’t reproduce this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe lets make it a tuple Option[(Int, Int)] ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Diagnostic requires a Double. Is this the solution you had in mind?
val preciseRangeOpt: Option[(Double, Double)] =
if (problem.line.get > maxLine) {
val endPos = lineInfo.to
Some((endPos, endPos))
} else {
(problem.startColumn, problem.endColumn) match {
case (Some(start), Some(end)) if start > 0 && end >= start =>
val clampedStart = (start min (lineLength + 1)) max 1
val clampedEnd = (end min (lineLength + 1)) max clampedStart
Some((lineInfo.from + clampedStart - 1, lineInfo.from + clampedEnd - 1))
case _ =>
None
}
}
val (startColumn, endColumn) = preciseRangeOpt match {
case Some((start, end)) =>
(start, end)
case None =>
(lineInfo.from, lineInfo.to)
}
Summary
This PR introduces precise error highlighting. Errors are now displayed using their actual range instead of highlighting the entire line.
Key changes
LineMappertoPositionMapper, as instrumentation can shift both lines and columns.PositionMappernow maps both.Int => Int(from the oldLineMapper) withOption[PositionMapper].severity,line,message,startColumn, andendColumn.PositionMapperSpecs(formerlyLineMapperSpecs).SBTandScala-CLIrunners and their tests to use the newPositionMapperand to assert precise error positions.Screenshots / GIFs
Before
After