-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
LSP: Add support for Go to Definition #575
Conversation
While I think the macro implementation is cool 😎 it can be written with just two methods:
And then used as:
I'm not sure, but it might be refactored in a way, so we wouldn't need to create duplicates and have less memory footprint (maybe @Sija has some ideas? 😄 ) Otherwise I think it's OK 👍 |
I haven't tried just using only Shouldn't be too hard to fall back to using
Doh, it's easy to try and be too fancy with macros 🙈 I'll make this change! What were your opinions on adding additional methods to |
I would keep it separate for now, let's see it a common pattern emerges and then we can add it accordingly. |
I think this is ready for review now 👍 I've made the changes above, as well as a few others:
I've tested it on the recently updated One of the changes is that It now ignores any components that are part of the "core" set, mostly because there is nowhere on disk where vscode etc can find them. To be able to test this. I removed these lines from - module Mint
- class Core
- class_getter ast : Ast = Ast.new
- end
- end Let me know if you would like this back in. I could probably just add a minimal set of components to this for testing rather than all of the core files. |
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've left some minor comments but it looks awesome, great job! 🚀
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
This PR adds support for the LSP feature Go to Definition. Only a few things are actually supported, namely finding the definition of
HtmlAttribute
,HtmlComponent
andHtmlStyle
nodes as demonstrated below:Screencast.from.2023-04-15.16-37-04.webm
I've opened this as a draft, as I'm not sure what I've done is a very good approach or not, and also there are some unfinished bits:
LocationLink
's before returning them (viatextDocument.definition.linkSupport
) and otherwise just return aLocation
's instead (also looks like I should be returning an array of them as per the spec?)The main parts I would like feedback on are below:
Selecting the "name" part of a node
The LSP requires that you return both
targetRange
andtargetSelectionRange
as part of aLocationLink
as described below:Currently I've implemented
targetSelectionRange
by dumping a bunch ofselection
methods onto theDefinition
class. These are used to figure out which part of each node is the "name" (which can be a bit complicated for some nodes)These methods could probably be moved to the actual Ast nodes themselves a bit like we have
.static?
etc?e.g.
Finding other nodes in the "stack"
For figuring out the "definition" of a node, I needed to be able to look at other nodes in the stack as provided by
server.nodes_at_cursor
.As an example, the stack when hovering over a
HtmlStyle
node might look like this:To find the corresponding
Style
node, I also need to know whichComponent
theHtmlStyle
is in.To do this, I added a bunch of methods via macro that allow you to look along the stack (
next_<node_name>
for finding an immediate parent node, andany_<node_name>
for any ancestor node), returningNil
if they can't find anythingIn code this looks something like this:
I'm not sure if this is a very good or efficient approach, and am open to suggestions for a better one!