Metals: Implement textDocument/hover

Created on 20 Dec 2018  路  7Comments  路  Source: scalameta/metals

Most helpful comment

Opened a PR implementing hover #595

All 7 comments

I'm working on this LSP endpoint, and it is roughly working :)
https://github.com/tanishiking/metals/commit/28488bed36616409a47ddf4e454f6ebbfc4737e5


Demo on VSCode (on scalafix)

peek 2019-01-02 14-56

However, I found that there are some TODOs for realizing the practical endpoint for textDocument/hover.

  • [ ] Move PrettyType (and QualifyStrategy and TypeExtractors which are currently used from ExplicitResultTypes) into scalameta/scalameta.

    • My implementation uses PrettyType which is almost copied from scalafix, because PrettyType is quite useful for constructing practical hover information which contains type information of the symbol on the position. If scalameta has a PrettyType and make this endpoint use it instead, we can delete the PrettyType from this implementation.

    • I consider that moving them into scalameta/scalameta (or it's contrib?) is reasonable because they are related only on scalameta (not dependent on scalafix)

  • [ ] (For better hover information)(maybe) fix https://github.com/scalameta/scalameta/issues/1494

    • As we can see from the demo gif above, we cannot retrieve enough information from some of symbols, because they don't have signature and falling back to here in PrettyType#toTree.

    • For retrieving better hover information, we should ensure the most of symbols have a signature.

    • Since I'm not familiar with signature computing, maybe I'm misunderstanding and there are some other workaround...

Thanks for looking into this @tanishiking!

I am afraid that PrettyType is not the best approach to implement this feature. I believe the best way to implement hover is to use the presentation compiler, which will be needed either way if we add completion support. It's difficult to estimate when that will happen, several other things need to be done first.

Before implementing new features, I recommend asking first on the gitter channel or here in the issue tracker to make sure that the approach is sound. Code from the old Metals prototype was removed because it did not meet the level of robustness that I'd like to have for supported features.

Thank you for reviewing on my approach!
It seems better and straightforward to retrieve the hover information from a presentation compiler since it will give us more accurate information about a symbol than PrettyType :+1:

This commit was just a prototype implementation, but I should have asked on gitter or this issue, thank you for your advice :)

Now that #527 is merged, we have the infrastructure to implement this. Current master has a rudimentary implementation of hover with a few basic tests but in order to enable the feature we need a clean reimplementation and to write a lot of tests covering cases like patterns, types, extension methods, annotations, named arguments, packages, apply, for comprehensions and full chain of identifiers in fully qualified names like scala.collection.mutable.ArrayBuffer.

Also, we need a new type printer that pretty-prints modifiers and symbol kinds

// Ok
implicit val global: ExecutionContext
// Not Ok
ExecutionContext

Opened a PR implementing hover #595

How can I use this feature in vim?

It is a command you trigger, there aren't key bindings by default but here you can find the recommended ones: https://scalameta.org/metals/docs/editors/vim.html#recommended-cocnvim-mappings

Was this page helpful?
0 / 5 - 0 ratings