-
Notifications
You must be signed in to change notification settings - Fork 337
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
Type annotation on code selection #3060
Conversation
3f72351
to
c0d2f7c
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.
So this is really rad @KacperFKorban, I will use this a ton!
Using nvim-metals
, this seems to just work as expected out of the box.
Screen.Recording.2021-08-22.at.15.56.00.mov
With that in mind and looking at the code fully recognising I may have missed something, it seems that the biggest thing we are still looking for is the offset coming off of the end of the range. In my video above, that's all that is being sent in, the position at the end of the visual selection. Do we actually need the full range? Won't the type at the end point always be what we are after? If that's possible, then we don't actually need to break away from the LSP spec for hover
by using our own class instead of the TextDocumentPositionParams
.
metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
Outdated
Show resolved
Hide resolved
Hmmm, can it be the case that nvim sends different position? In vscode triggering the hover on the end of an expression doesn't work. Range on a term name seems to include the position before, but not the position after. Like here: Technically |
Gotcha. I think it's partly because when nvim sends in the position from the selection range, it's still just a single point that often isn't actually after the symbol, since unlike VS Code, you can't really extend past the text like in your image. Either way, great work on this 👍🏼 I'll for sure play around with this a bit more to see if anything will even need to be added for this to work the same way in nvim-metals as it does in VS Code. |
@ckipp01 I thought of an example that won't work with just the end offset- method calls in infix notation. List("1", "2", "3").filter(<<_ contains "2">>) the result will be Boolean. List("1", "2", "3").filter(_ contains "2@@") the result will be String. |
Really cool feature ! What needs to be done for none VS code clients, say Sublime Text ? :) |
You would need to send a range instead of position, similar to scalameta/metals-vscode#652 - this was actually discussed in the LSP github repo, but not sure if anything will change on that front. This is already being done for Rust and I think Haskell. |
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.
Thanks for the great work! I have a few comments, overall it would be awesome to limit the changes to only the code selection if possible.
metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
Outdated
Show resolved
Hide resolved
mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala
Outdated
Show resolved
Hide resolved
mtags/src/main/scala/scala/meta/internal/metals/CompilerOffsetParams.scala
Outdated
Show resolved
Hide resolved
4f530cd
to
4d956c8
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.
LGTM! Just one small typo, I will push the change and rebase on master
This reverts commit c457790.
2bb35a9
to
b3fb8d0
Compare
This is a follow-up to the work done in scalameta#3060, but since positions is now optional, we need to ensure to use `getPosition` instead of position like we did here. This was causing the following exception to be throw: ``` Caused by: java.lang.IllegalArgumentException: Property must not be null: position at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29) at org.eclipse.lsp4j.TextDocumentPositionParams.<init>(TextDocumentPositionParams.java:49) at scala.meta.internal.metals.Compilers.withPCAndAdjustLsp(Compilers.scala:594) at scala.meta.internal.metals.Compilers.hover(Compilers.scala:365) at scala.meta.internal.metals.MetalsLanguageServer.$anonfun$hover$1(MetalsLanguageServer.scala:1359) at scala.meta.internal.metals.CancelTokens$.future(CancelTokens.scala:38) at scala.meta.internal.metals.MetalsLanguageServer.hover(MetalsLanguageServer.scala:1357) ... 17 more ``` I'm surprised the test didn't catch this, because this shouldn't work at all without this change, but by quickly looking at the tests, it's wasn't clear to me right away why that was the case. I'll need to look further to understand the tests, but figured I'd send up this quick fix right away because now it won't work at all without it.
@tgodzik Do you mind posting the link so I get the context ? |
The discussion is happening here: microsoft/language-server-protocol#377 |
This is needed to handle scalameta/metals#3060 It should be handle by LSP package once microsoft/language-server-protocol#377 is resolved
Sorry for necrobumping, but a question for @ckipp01, did you manage to make it work properly in nvim-metals? |
closes #3059
We are limited by frontend capabilities, so to display the information properly we have to use the type annotation as hover.
Things that may be controversial:
key binding herevscode plugin changes: scalameta/metals-vscode#652