-
Notifications
You must be signed in to change notification settings - Fork 1.1k
bugfix: Make sure that we can query tree.source #24123
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
Conversation
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.
LGTM!
Not sure about this use case, but for linting I used
extension (pos: SrcPos)
def isZeroExtentSynthetic: Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
def isSynthetic: Boolean = pos.span.isSynthetic && pos.span.exists
and for message rendering I wanted to check if it's at EOF, for some reason I got nervous and put the source.length
check after other conditions on the span
// adjust a pos at EOF if preceded by newline
private def adjust(pos: SourcePosition): SourcePosition =
if pos.span.isSynthetic
&& pos.span.isZeroExtent
&& pos.span.exists
&& pos.span.start == pos.source.length
&& pos.source(pos.span.start - 1) == '\n'
then
pos.withSpan(pos.span.shift(-1))
else
pos
I think we should be good here, though it's one of the cases that I am lacking the reproduction, so it's only a guess here. The might have been zero extent, but not sure.
Related to scalameta/metals#7802