-
Notifications
You must be signed in to change notification settings - Fork 60
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
Support textDocument/prepareRename & textDocument/documentHighlight, improve accuracy of reference finding #732
base: main
Are you sure you want to change the base?
Support textDocument/prepareRename & textDocument/documentHighlight, improve accuracy of reference finding #732
Conversation
…ight, improve reference results Zed requires servers to support textDocument/prepareRename in order for symbol renaming to work. Zed also doesn't do any highlighting without textDocument/documentHighlight, and this request is also used to create a visual effect, highlighting everything that will get renamed when you start the symbol renaming action. This commit adds support for both these capabilities. It also resolves a previous issue regarding variable shadowing and module imports when searching for symbols, and makes assigning fields in tables work with references (before, `bar` wouldn't be recognized as a reference in `foo.bar = baz`, at least with the old solver, provided the type of `foo` contains `bar`).
Apologies, but if it's not too difficult could you split out these different features + bug fixes into separate PRs? It makes it a bit easier on me to review, but it's alright if not. Could you also add changelog entries for each of them too? I hope to review within the next week |
I don't think there's a good way to separate these into different PRs, because the two main bug fixes are both related to AST traversal structures that depend on lsp::DocumentHighlightKind. I could put prepareRename in a different one, but it's a very small part of this. |
Fair enough Could you also write some test cases for the bugs you fixed and the 2 new features you added? |
I just added some test cases that capture the things I've added and fixed. |
So sorry for the delay, will try to take a look this weekend |
Zed requires that language servers support textDocument/prepareRename for symbol renaming to work. Zed also requires textDocument/documentHighlighting for highlighting to work, and this request is also used to mark everything that is about to get renamed when you enter symbol renaming mode. This PR adds support for both these capabilities.
Before, with the current type solver, finding property references didn't recognize assigning to properties, meaning
foo
intbl.foo = bar
wouldn't be recognized as a reference to thefoo
property inside oftbl
. This PR changes the logic behind finding property references to instead go through the AST, which also makes it possible to properly determine if symbols should be marked as Read or Write for the documentHighlight request.Previously, finding references of imported modules in types also didn't work with scopes or shadowing. This PR alters the algorithm so that it stops processing a statement block when the symbol is shadowed by a module import, and when the scope in which the symbol is declared ends, which also is an optimization.
The old findAllReferences function would also allow finding references of properties of globals, which makes an assertment fail in debug builds. With these changes, it returns early instead.
Resolves 4teapo/zed-luau#2.