Skip to content
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

bugfix: workaround for missing span in reference to an extension method defined in the companion object #5640

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

kasiaMarek
Copy link
Contributor

Workaround for missing span in:

class MyIntOut(val value: Int)
object MyIntOut:
  extension (i: MyIntOut) def <<uneven>> = i.value % 2 == 1

val a = MyIntOut(1).un@@even

to provide correct:

  1. semantic highlighting,
  2. highlight,
  3. go to definition.

#5630

Copy link
Member

@jkciesluk jkciesluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can also close #5522

The idea looks good, but there is an issue when the method is not simply on ident

case sel: Select
if sel.span.isZeroExtent && sel.symbol.is(Flags.ExtensionMethod) =>
scala.util
.Try(NavigateAST.untypedPath(sel.span)(using compilatonUnitContext))
Copy link
Member

@jkciesluk jkciesluk Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for case mentioned in the comment, because sel.span points to @@MyInt(1).uneven,
so path is Ident :: Apply(MyInt, 1) :: Select :: _.

We can maybe take span from parent and use it? Also, I'm not sure if untyped will be then even needed here

Copy link
Contributor Author

@kasiaMarek kasiaMarek Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which comment? I get it now 😂 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one above this case

class MyIntOut(val value: Int)
object MyIntOut:
  extension (i: MyIntOut) def <<uneven>> = i.value % 2 == 1

val a = MyIntOut(1).un@@even

case (untypedSel: untpd.Select) :: _ =>
Some(
symbolAlternatives(sel.symbol),
pos.withSpan(untypedSel.nameSpan),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for most cases, the span would be the Apply span, from point to end, so we won't have to use untypedPath, but I have to check how it will work for infix methods

Copy link
Member

@jkciesluk jkciesluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a test for hover, besides LGTM

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Does it also fix #5478 ?

@tgodzik
Copy link
Contributor

tgodzik commented Sep 19, 2023

I think for the presentation compiler, we should actually fix the span, so no need to port this to the compiler most likely. (just tests after the span fix is done)

@kasiaMarek
Copy link
Contributor Author

I think for the presentation compiler, we should actually fix the span

scala/scala3#18557 😉

@tgodzik
Copy link
Contributor

tgodzik commented Sep 19, 2023

I think for the presentation compiler, we should actually fix the span

lampepfl/dotty#18557 😉

Och, that's amazing!

@kasiaMarek kasiaMarek merged commit f448ae0 into scalameta:main Sep 22, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants