-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Add support for textDocument/hover
(for modules)
#331
Conversation
|
|
|
|
Some.Module| # docs for Some.Module
alias Some.Module
Module| # docs for Some.Module
Some.Module|. # compile error, should still be able to identify Some.Module
Some|.Module # docs for Some
|
Aliases can get pretty tricky, but luckily we have an alias tracker in |
Yep, start off in |
I'm going to mark this PR as ready for review. Currently it is able to resolve modules under the cursor and display module docs. The code (and commits) need to be cleaned up a bit, however. That said, I think it's in a good-enough spot that it's useful to get feedback and make sure I'm not too far astray. |
textDocument/hover
textDocument/hover
(for modules)
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
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.
Wow, what an improvement. I'm really liking the direction here (and I can't wait until we can get Ast.fragment
merged so I can use it in my indexer PR.
I would like to call out the tests though, I think (hope) we can improve them so that each test clearly shows both the module being defined (and its docs, or lack thereof) and the module being hovered over.
apps/remote_control/lib/lexical/remote_control/code_intelligence/docs.ex
Outdated
Show resolved
Hide resolved
apps/server/test/lexical/server/provider/handlers/hover_test.exs
Outdated
Show resolved
Hide resolved
Those aren't embedded in the module docs, but added after the fact. I do think it is worth adding them (Elixir LS does as well), but I'd rather that happen in another PR.
Will look into it! |
apps/server/test/lexical/server/code_intelligence/entity_test.exs
Outdated
Show resolved
Hide resolved
@scohen @scottming I believe everything that's been mentioned so far has been addressed. Please let me know what else y'all would like to see prior to merge! |
* Add `resolve/2` This is a general-purpose API for resolving the code entity at a given position. Currently it only supports resolving modules (and aliased modules). It will have immediate use for accessing docs on hover. * Move `definition/3` Entity resolution and go-to-definition logic are related: the first part of going to a definition is resolving the entity under the cursor so that you know what to go to. While go-to-definition still currently relies on `elixir_sense`, the plan is to eventually remove that dependency, at which point it will share logic with or use `resolve/2`.
This commit adds initial support for `textDocument/hover` LSP requests, showing basic moduledocs when a module or alias is hovered.
This commit swaps out the use of `Sourceror.parse_string/1` with a call to `Sourceror.string_to_quoted/2` that includes the `:static_atoms_encoder` option. This option is used to retain line/column metadata on certain atoms (like the individual segments of an alias) that would otherwise be discarded. An explanatory comment has been added to `Lexical.RemoteControl.CodeMod.Ast/parse/1` for additional context.
This first commit is essentially just scaffolding, including the generated types for
textDocument/hover
and basic request/response handling. It currently replies with static content.There's some additional WIP code for retrieving the docs for the entity being hovered, but I'm not sure how much of it will actually end up in the final feature.
@scohen, some thoughts/questions on the best way to proceed that I'd love your input on.
Project.Docs
fixture for what I'm planning to test with to start. Does this seem reasonable?Code.fetch_docs/1
to retrieve docs. It retrieves docs for an entire module, all functions/types/etc. defined within. As per (Added thoughts about code intelligence and indexing #223), it'll eventually be worth caching this stuff, but for now I'm thinking to just scan the result each time.ElixirSense
to retrieve the definition given a doc/line/character. I'm assuming that I should also use it for now to retrieve the range and module associated with the currently hovered entity?