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

Go to definition of synthetic symbols. #3683

Merged
merged 8 commits into from
Mar 7, 2022

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented Mar 5, 2022

Previously, Metals didn't go the definition of symbols that the
presentation compiler defines as synthetic. These symbols include
auto-generated case class apply methods and regular class
constructors. Now, we ignore the isSynthetic bit on the definition
symbol so that "Go to definition" works as expected for cases where it
didn't before.

olafurpg added 2 commits March 5, 2022 15:22
Previously, Metals didn't go the definition of symbols that the
presentation compiler defines as synthetic. These symbols include
auto-generated case class `apply` methods and regular class
constructors. Now, we ignore the `isSynthetic` bit on the definition
symbol so that "Go to definition" works as expected for cases where it
didn't before.
This should be OK since the definition is at the same location as the
call-site.
@olafurpg
Copy link
Member Author

olafurpg commented Mar 5, 2022

I tried fixing the failing Scala 3 tests but I'm not familiar with that part of the codebase. I'd appreciate any help to get the Scala 3 tests green

Copy link
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

Scala2 part looks good 👍
In terms of Scala3, it looks like enclosingSymbols is the root cause, as all the inputs (of failing tests) are swallowed by this match case.
If I remove that case, I got the following test result for eta-2, which is still different from the expected result 🤔

=> Obtained
    """|object Main {
       |  List(1).foldLeft(0)(_ + /*scala/Int#`+`(+4). Int.scala*/_)
       |}
       |""".stripMargin
=> Diff (- obtained, + expected)
 object Main {
-  List(1).foldLeft(0)(_ + /*scala/Int#`+`(+4). Int.scala*/_)
+  List(1).foldLeft(0)(_ + <<>>_)
 }
    at munit.FunSuite.assertNoDiff(FunSuite.scala:11)
    at tests.pc.BasePcDefinitionSuite.check$$anonfun$1(BasePcDefinitionSuite.scala:68)

I guess this is because https://github.com/tanishiking/metals/blob/7871d17c7ea19d9b54c5af6025d242d7e5f5a0e1/mtags/src/main/scala-3/scala/meta/internal/pc/PcDefinitionProvider.scala#L142 ignores the Synthetic symbol, maybe we can fix this by taking care of the Synthetic symbols there.

@tanishiking
Copy link
Member

I partly reviewed the PR, but I don't have time to take a look for a few days. If someone can delve into the problem with Scala3, please go for it :)

@olafurpg
Copy link
Member Author

olafurpg commented Mar 7, 2022

@tanishiking Thank you for the review! I added compat = Map("3" -> ..) assertions to make the Scala 3 tests pass.

@dos65
Copy link
Member

dos65 commented Mar 7, 2022

@olafurpg I made a pr onto your branch with fixes for scala3 - olafurpg#4

@olafurpg
Copy link
Member Author

olafurpg commented Mar 7, 2022

Thank you @dos65 ! I merged your branch and updated this PR

Copy link
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

I checked @dos65 's PR: olafurpg#4 and now it's LGTM!
(except one nitpick comment)

Copy link
Member

@kpodsiad kpodsiad left a comment

Choose a reason for hiding this comment

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

Awesome!

Comment on lines +137 to +139
case (head @ Select(target, name)) :: _
if head.symbol.is(Synthetic) && name == StdNames.nme.apply =>
val sym = target.symbol
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment which case is handled by this match for future us?

Copy link
Member

Choose a reason for hiding this comment

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

it's for synthetic apply method in case-class

Copy link
Member

@dos65 dos65 left a comment

Choose a reason for hiding this comment

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

👍

@dos65 dos65 merged commit 8ad56ce into scalameta:main Mar 7, 2022
@olafurpg olafurpg deleted the definition-broken branch March 7, 2022 10:59
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.

4 participants