-
Notifications
You must be signed in to change notification settings - Fork 205
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
Re-use document symbols functionality for workspace symbols #683
Conversation
The tests pass locally for me on the failed job (elixir 1.13 and otp 24.1), but i can't test the otp 22 failure because i am on mac (I think only 23+ works on mac now a days). I think it might have been a dialyzer timeout or something, but I can't restart the failed jobs myself it seems. |
I will be testing this in the VSCode extension soon. I think that the neovim lsp client might be forgiving in whether it sees a DocumentSymbol or a SymbolInformation, whereas there is a chance that VSCode might be more strict. |
All builds green now 😄 |
symbols = | ||
for file <- paths, into: %{} do | ||
file = Path.absname(file) | ||
uri = "file://#{file}" |
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.
use path to URI convert function from SourceFile
end | ||
symbols = | ||
for uri <- uris, into: state.symbols do | ||
file = URI.parse(uri).path |
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.
us URI to path conversion from SourceFile
Nice work @mhanberg but I'm not completely convinced we should go this road. Let me state my reasons.
Anyway, I plan to play around with it and see how it works in practice |
@lukaszsamson thank you for taking the time to look over this patch, I really appreciate it.
This is something I was thinking about when writing this patch. I am trying to think of the utility of navigating to functions that don't exist in the source code. I figure you'd rather go to the actual source code (the macro that generates the code) than the module where it gets injected. Small example, but I'm not certain the value i'd get from the Is there a useful example that you use regularly?
That seems cool to me. 👍
I think configuration is a valid point (while, not applicable with this patch, as it can't pull in functions/modules/types that are used in the project but not present in the source code). One of the things I noticed which instigated me writing this patch was that the symbols didn't seem to show up at all, except for some (to me, random) OTP functions. You can observe this in the screen recording I shared. Do you know why that is?
I think this is on oversight in the patch. I think this could possibly be remedied. Thank you for pointing it out 👍. Thanks again for reviewing this patch. I appreciate all the comments and for the consideration. I have been using this branch for the last week at work and have been enjoying it, let me know what you think after using it. |
cd06c18
to
c429111
Compare
c429111
to
ba4371a
Compare
I'm going to try and port the workspace symbols to compiler tracers in the next week or so. |
I already have a PoC branch with DocumentSymbols using a database built by compile tracers. It looks promising but requires more work and integration with current AST based approach. Currently compile tracers can only get high quality info only about modules and defs and some limited info about attributes. Anything more than that requires loading the module and doing the usual introspection that WorkspaceSymbols currently do. |
Gotcha, thanks for the update 🚀 |
ba4371a
to
a37ab53
Compare
Previously, the workspace symbols feature used the `:code.all_loaded` functionality of the OTP standard library to "discover" all modules, and then was able to parse out the different type of symbols from that. In doing so, this loaded _tons_ of symbols that are completely unrelated to your workspace. As a prior user of the document symbols feature, this really threw me off. As I understand it, the workspace symbols support is for quick navigation of functions, modules, types in your own codebase, so if the source code is not available in your own repository, you really wouldn't be navigating to it. The workspace symbols feature was also implemented differently than the document symbols feature. This commit works to align the two features to make them work similarly. In addition, this also allows you to pass an empty query to LSP request in order to retrieve a full list of all of the symbols. This aligns the Elixir implementation with the spec, and makes it useful for those who use a fuzzy searching plugin in their editor to do the querying. _Notes_ - I believe this is technically a breaking change, as the results returned in the request are slightly different than they were before. I believe them to be _more_ accurate now, but they are technically different. - With the previous implementation, I found that in some codebases (like https://github.com/mhanberg/temple), no symbols were being returned for the project. I suspect it had something to do with the library not having an `Application`, so no code is loaded at first. - I have tested this on the Wallaby codebase (https://github.com/elixir-wallaby/wallaby) and it seems to return instantly, so I don't think there should be any kind of performance regression, but it would be worth checking against larger codebases. I plan on trying this branch on my work projects on my next working day.
This was meant to be a normal `<-`.
a37ab53
to
b66d65c
Compare
#1050 should improve workspace symbols experience for now. In the future I plan to build a common database/index layer. If that happens parts of this PR may be yet reused |
Previously, the workspace symbols feature used the
:code.all_loaded
functionality of the OTP standard library to "discover" all modules, and then was able to parse out the different type of symbols from that.In doing so, this loaded tons of symbols that are completely unrelated to your workspace. As a prior user of the document symbols feature, this really threw me off. As I understand it, the workspace symbols support is for quick navigation of functions, modules, types in your own codebase, so if the source code is not available in your own repository, you really wouldn't be navigating to it.
The workspace symbols feature was also implemented differently than the document symbols feature. This commit works to align the two features to make them work similarly.
In addition, this also allows you to pass an empty query to LSP request in order to retrieve a full list of all of the symbols. This aligns the Elixir implementation with the spec, and makes it useful for those who use a fuzzy searching plugin in their editor to do the querying.
Here are two videos demonstrating the differences between the current and (potentially) new behavior. I uploaded the to YouTube as the vides were over 10MB.
Current Behavior: https://youtu.be/PUkykG7IK8I
New Behavior: https://youtu.be/7CmKaGyTfqk
Notes
Application
, so no code is loaded at first. The videos uploaded demonstrate it with the Wallaby codebase, which does use anApplication
however, so I'm not entirely sure why.PS
I understand this is a significant and unsolicited change, so thank you in advance for reviewing this patch and considering it for merging.