julia-vscode / LanguageServer.jl

An implementation of the Microsoft Language Server Protocol for the Julia language.
Other
373 stars 81 forks source link

VSCode unable to find function definitions in multi-module projects #1163

Open MilesCranmer opened 2 years ago

MilesCranmer commented 2 years ago

Right now it seems that VSCode is unable to find function definitions in submodules. For example:

src/A.jl

module A
f(x) = x
end

src/B.jl

module B
import ..A: f
function g(x)
    return f(x)  # VSCode unable to find `f`
end
end

src/C.jl

module C
export g
include("A.jl")
include("B.jl")
import .A: f
import .B: g
end

Project.toml

name = "C"

VSCode cannot seem to locate f from within B.jl, though it is able to locate it from C.jl.

@davidanthoff @ZacLN @pfitzseb do you know why this is not currently possible?

(Maybe related: https://github.com/julia-vscode/julia-vscode/issues/1740, https://github.com/julia-vscode/julia-vscode/issues/2904, https://github.com/julia-vscode/LanguageServer.jl/issues/1173)

Use-case: if you look at the codebase of SymbolicRegression.jl, every single file defines its own module - e.g., the file src/AdaptiveParsimony.jl defines the AdaptiveParsimonyModule which can be imported by other files. This is to make the codebase easier to navigate for potential contributors, since all dependencies are explicit[1]. However, the downside is that Julia VSCode doesn't seem to know where the functions are actually defined.


[1] Aside: I think this should be done by every Julia package, rather than the overpowered namespace mixing include("...") which requires me to search manually for where a function is defined, or to rely on an IDE.


Originally posted in https://github.com/julia-vscode/LanguageServer.jl/issues/1173. Thanks to @pfitzseb for identifying this as a separate issue.

fredrikekre commented 2 years ago

I can not reproduce this.

MilesCranmer commented 2 years ago

Sorry for the confusion, I gave the completely wrong example. The issue I was seeing is actually the one described here: https://github.com/julia-vscode/julia-vscode/issues/2719. Not sure if this is a vscode issue or a LanguageServer.jl issue? Feel free to close this if needed.