LanguageServer.jl icon indicating copy to clipboard operation
LanguageServer.jl copied to clipboard

Go to position where a symbol entered the namespace

Open lassepe opened this issue 2 years ago • 7 comments

When using the go-to-definition feature, the current behavior jumps to the method definition that potentially resides in another module; potentially even in another package. Instead, what I usually want is to know "where did this symbol enter my namespace"? To answer this question, it would be convenient if "go-to-definition" jumped to the associated using or import statement that brought the symbol into scope.

Example:

using Dictionaries: sortkeys # invoking "go-to-definition" on `sortkeys` here should ideally still jump to the definition in `Dictionaries.jl`

...

function foo()
     ...
     sortkeys(d) # invoking "go-to-definition" on `sortkeys` here would jump to the `using` statement above
end

lassepe avatar Oct 29 '23 21:10 lassepe

Wouldn't the hover action tell you this? Doesn't seem like a job for "go to definition" at least.

fredrikekre avatar Oct 29 '23 21:10 fredrikekre

Yeah, I agree. "Go to references" already handles this case: image

pfitzseb avatar Oct 30 '23 11:10 pfitzseb

I guess my expectation just came from the fact that my python LS had the described behavior.

But I tested in rust and there it seems to behave as in LS.jl. In view of that and the fact that many others are probably already used to the current behavior, I'll close this issue. "Go to references" does the job for me.

lassepe avatar Oct 30 '23 12:10 lassepe

FWIW, the LSP also defines the textDocument/declaration request, which could maybe do this?

pfitzseb avatar Oct 30 '23 12:10 pfitzseb

Yes, at least my python language server jumps to the associated import statement upon "textDocument/declaration". In rust, however, it jumps to the definition in another crate.

lassepe avatar Oct 30 '23 13:10 lassepe

I'm also not sure how e.g. VS Code shows "Go to definition" and "Go to declaration" or how the user would interact with them, FWIW.

pfitzseb avatar Oct 30 '23 13:10 pfitzseb

It seems to be exposed in the right-click menu in vscode and the Go menu in the top bar. The user can also bind a key to it:

image

lassepe avatar Oct 30 '23 13:10 lassepe