VSCode's 'Go to definition' to recognise functions from other libraries

I cannot seem to inspect functions or classes defined in external libraries using VSCode’s ‘Go to definition’ (F12) feature. For example, with the following simple example:

using Plots

plot([1, 2, 3], [1, 2, 3])

I get a No definition found for 'plot' message when trying to inspect the plot function from the Plots library. It seems to work fine with some basic functions like +, but not with others like typeof. It seems like it should be possible to get the VSCode Julia extension to recognise functions imported from libraries.

I think typeof doesn’t even have a definition consisting of Julia source that you could go to, because it’s a builtin:

julia> typeof
typeof (built-in function)

julia> +
+ (generic function with 189 methods)

Ah ok fair enough, so that example may not be related to the original question. But it still stands to reason that you should be able to located the definition of a function imported from some other library. Particularly because Julia approach of inclusion with using Package naturally means it’s very difficult to find the source of a function without this sort of code inspection.

I’d frankly be amazed if I was the only person to have encountered this issue.

TBH I never tried the “Go to definition” feature, I always just use @which f(x), so I can’t help you much,

1 Like

Make sure the environment selected in VS Code (check the status bar) actually contains the package (Plots in this case) and is resolved. Also check Output > Julia Language Server for errors in case something about the extension is straight up broken.

Yes the environment selected definitely has Plots installed, as I can activate the same environment in the REPL and run the same lines of code without any issue. However, it seems there are two things going on here, and the issue with the Plots example I gave above may not be related to the problem in the title.

Regarding ‘Go to definition’: after going away and doing some other stuff on my laptop, then coming back deactivating and reactivating the environment a few times (to check on your question of the environment in the status bar), the ‘Go to definition’ feature now seems to be working for most packages and functions where I would expect it to work.

However, it still does not want to recognise the definition of Plots.plot, and I now also get a ‘possible method call error’ warning for the plot function. If however I replace it with a call to plot3D I get no such warning and am also able to use the ‘go to definition’ tool. So I’m not sure what’s going on there, but it seems to be specific to the example I chose to illustrate a point that has now largely resolved itself.

What else is in your environment?