lexical-lsp / lexical

Lexical is a next-generation elixir language server
779 stars 77 forks source link

Indexed delegated functions #729

Closed scohen closed 1 month ago

scohen commented 1 month ago

Functions created with defdelegate weren't being indexed, so they weren't showing up in find references, document symbols, or go to definition.

This change emits two entries when it encounters a defdelegate call, one for the local function definition in the calling module, and a function reference to the delegated module. One possibly strange thing is that the function that's being created by defdelegate shows up as def in document symbols. This is technically correct, you're defining a public function, but it might be confusing in the UI.

Fixes #724

crbelaus commented 1 month ago

I am testing this and can confirm that delegated functions are now included in the document symbols.

Here is a screenshot that shows this. Notice how the translate/3 function is included along with the rest, even though it is a defdelegate instead of a def or defp.

image

This second screenshot is showing the "peek references" functionality of VSCode in the delegated module, which shows the defdelegate macro that points to it. So I believe this is working good as well.

image


I agree with you that it may be a little bit confusing to show the defdelegate as def in the document symbols. May be enough to include a note somewhere (maybe in the README?) about this as the reasoning is sound and you are, in fact, defining a public function.

scohen commented 1 month ago

Note: #734 will allow us to mark delegates as delegates easily.

scohen commented 1 month ago

@crbelaus we now show defdelegate in document symbols

scohen commented 1 month ago

I'm going to merge this, @scottming, you've had ample time to review this, two weeks for a small PR is too much.