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
feature: Replace synthetic decorations with inlay hints #5983
Conversation
3ec6048
to
df32716
Compare
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.
Sometimes hover on inlay hints feels broken.
this is line 107 in Scala 3 PcCollector
https://github.com/scalameta/metals/assets/26606662/9e7af9a2-e38d-4fef-9763-9678d2e3112c
Also it doesn't update hover if you move from one inlay hint to another but both of those things may be a VSCode issue.
But in other cases hover info seems to be missing, e.g. on List in Scala 3.
metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala
Outdated
Show resolved
Hide resolved
): Future[InlayHint] = { | ||
scala.util.Try { | ||
val data = inlayHint.getData().asInstanceOf[JsonArray] | ||
getLabelParts(inlayHint).zip(parseData(data)) |
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.
Wouldn't it be a bit cleaner to use create a class for what you're parsing and use CommonMtagsEnrichments#decodeJson
?
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 tried many ways for parsing this, but didn't manage to make anything cleaner work, I had issues with trying to decode optional values or Either
.
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 thought that org.eclipse.lsp4j.jsonrpc.messages.Either
would solve this.
mtags-shared/src/main/scala/scala/meta/internal/mtags/CommonMtagsEnrichments.scala
Outdated
Show resolved
Hide resolved
mtags/src/main/scala-2/scala/meta/internal/pc/PcInlayHintsProvider.scala
Outdated
Show resolved
Hide resolved
mtags/src/main/scala-2/scala/meta/internal/pc/PcInlayHintsProvider.scala
Show resolved
Hide resolved
mtags/src/main/scala-2/scala/meta/internal/pc/MetalsGlobal.scala
Outdated
Show resolved
Hide resolved
mtags/src/main/scala-3/scala/meta/internal/pc/PcInlayHintsProvider.scala
Outdated
Show resolved
Hide resolved
|""".stripMargin, | ||
_ <- server.assertInlayHints( | ||
"MyTests.sc", | ||
s"""|#!/usr/bin/env -S scala-cli shebang --java-opt -Xms256m --java-opt -XX:MaxRAMPercentage=80 |
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.
Do you need to pass the whole file input, won't that be available in buffers
in testing server?
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 most tested methods do it this way.
I've changed the signature so the tests should be more readable.
9ea107d
to
a7de426
Compare
@@ -167,7 +168,7 @@ public abstract CompletableFuture<List<TextEdit>> convertToNamedArguments(Offset | |||
/** | |||
* Returns decorations for missing type adnotations, inferred type parameters, implicit parameters and conversions. | |||
*/ | |||
public CompletableFuture<List<SyntheticDecoration>> syntheticDecorations(SyntheticDecorationsParams params) { |
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.
This will break mima, if we have an older mtags that is no longer release this will throw an exception.
We could do two things:
- have a way to translate older syntheticDecorations to inlay hints (even if worse or not complete) <- this would be the best option
- just deprecate it and have inlay hints return nothing as a default like now (this will make the decorations stop working when using older Scala versions)
Anyway I would not remove the old method
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.
have a way to translate older syntheticDecorations to inlay hints (even if worse or not complete) <- this would be the best option
How should we approach this? In Compilers.inlayHints
, if pc.inlayHints
returns empty results, try to run pc.syntheticDecorations
and transform the result to inlayHints?
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.
Actually, we've added syntheticDecorations
to the Presentation Compiler in the last release, so the only scala versions for which decorations would stop working are these for which we drop support in the next release (assuming in would contain inlayHints
)?
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.
We also have to take into account the compiler itself, which uses the same interface currently. So we should at least not remove the method. But we might not bother with translating decorations to inlay hints then.
@@ -1,12 +0,0 @@ | |||
package scala.meta.pc; |
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.
Let's not remove it, mima should, but I think I haven't updated it previously.
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.
Great work! I left some comments about the interfaces that should be handled properly before merging.
object InlayHints { | ||
def empty: InlayHints = InlayHints(Nil, Set.empty) | ||
|
||
def makeLabelParts( |
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.
Does this method adds the additional [
, ]
parts? Could add a comment and might be better to name it properly.
mtags/src/main/scala-2/scala/meta/internal/pc/PcInlayHintsProvider.scala
Outdated
Show resolved
Hide resolved
| implicit val ttt: Set[Int] = Set(1) | ||
|} | ||
|""".stripMargin, | ||
// TODO: We should show info about renames (`val ttt: S[Int]` instead of `val ttt: Set[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.
That should be shown properly with the recent changes by @kasiaMarek right?
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.
It's not possible to make it work now, because we the tooltip we show, comes from hover
on a ttt
definition. On ttt
definition there is no information about a rename from Set
to S
.
But I think thats not a big issue
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.
Ok sure, we can leave it for now, not super important. I guess we would need to handle the resolve request in the compiler to make that work. And it's maybe not worth it.
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.
Especially that the user will see the rename + what it dealiases to, so maybe that is better.
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.
Yes, and if there are different renames in hint position and symbol definition position, the logic could get quite messy
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 feel like this could be handled if we were passing two positions to hover, one of the symbol we want to hover on, and the other one where the hover info will actually be shown, so the context for the second one could be used for printing. But it may be too optimistic to assume it will just work, and definitely not worth to consider in this PR. I still think we should create an issue considering this, we can give low-priority
and leave it be, but it will be there for sake of documentation.
3a35fbc
to
c9b3015
Compare
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.
Let's rebase and merge @jkciesluk ! I think we should be good to go
c9b3015
to
15d6de1
Compare
Backports changes from Metals: scalameta/metals#5983
Backports changes from Metals: scalameta/metals#5983
Backports changes from Metals: scalameta/metals#5983
Just wanted to say thank you for this PR, appreciate. This will greatly help people working in less mainstream editors like Kakoune, Helix or Zed. Thanks. |
No description provided.