Go to definition almost never works

I know there have been several threads on this topic already. Examples include going to definitions in packages or included definitions. Most of these threads just seem to be dangling with no resolution.

In my experience, “go to definition” almost never works.

Screenshot 2023-03-01 at 11.03.24

Perhaps I’m doing something wrong or my expectations are unrealistic but pycharm has no such problems.

8 Likes

When I have a package open for development, VSC does not recognize its methods, and jumping to definition does not work. I already asked about this, and I don’t think I got a definitive answer.

1 Like

It does for me but I think one must have the entire directory (normally the src dir) loaded in the EXPLORER such that it can sniff in all files that may have the type/function definition.

What happens if you open a new file and try the example above?

This seems to be coming up more often (i.e. Go To Definition (F12) does not work for functions in an included file). I had a workflow that used to work okay (required a few Julia language server restarts every so often) but recently it doesn’t work and I can’t access intellisense (and hence go to definition) in most of my own files.

General advice that may or may not help:

  • Open the project as a folder in VS code, instead of individual files.
  • Create an environment for your project and activate that in VS code
  • If you are using modules, adopt a standard package structure - e.g. using PkgTemplates.jl.

Not immediately, and if fact I’m not exactly sure what made it work but I think it was the fact that I include("testa.jl") in the module and in the VSC repl I did a using *package*

I’ll give those things a try (I already do the first one). But it seems, that is at best temperamental and unreliable.

Interestingly, in my case if the change the type from an abstract type to a struct, it suddenly works.

I think I will raise an issue.

Unfortunately, this has been a longstanding issue for me. I reported this issue in 2021.

2 Likes

I think the main, underlying issue is the lack of documentation of the StaticLint, see: Request for a more specific example or documentation on StaticLint · Issue #310 · julia-vscode/StaticLint.jl · GitHub

If StaticLint would be better documented and could be used and tested stand-alone more people would test it and contribute, and these issues would get fixed faster …

1 Like

Another very simple example - unable to find the module in the module project. It’s also unable to find the definition of greet.

1 Like

Possible solution…

2 Likes

Thanks - that did fix that particular issue. It’s not an obvious workaround (at least to me) and doesn’t address the bigger issue that navigation is unreliable.

I certainly agree. I use Sublime Text with its search facilities based on indexing. That works rather well.