LSP: add support for finding module fn references #3147
+373
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1541
Using AST traversal to collect references. Extending to other nodes, e.g. local vars, should be simple enough.
This only collects references in the project's modules.
With the references feature, we can reuse the implementation for renaming, as renaming needs to find all references and perform updates on those.
Considerations
Unpreciseness of
definition_location()
Currently, the
definition_location()
method doesn't give the precise location, for example:With the current behaviour, the output of finding references is still reasonable enough, even though it's not pointing to the exact location.
To fix the above, I am proposing a solution: add additional span information for preciseness in the corresponding AST nodes, e.g. add the span of the function name. This would also be very helpful in renaming, as we don't need to use error-prone string matchings (which we need to take care of comments) to perform the correct edits.