For which packages does VSCode autocomplete work?

I recently discovered that autocomplete (and more generally IntelliSense) works for some people, and that makes me very frustrated :rofl:
For me it only works with Base and Core, not even standard library stuff like LinearAlgebra. EDIT: see this reply for the real question.

I鈥檓 on macOS Ventura with the latest version of Julia and VSCode. I did wait until IntelliSense finished loading.

Related GitHub issues:

3 Likes

Is LinearAlgebra in your project?

1 Like

You鈥檙e right, I should put it in my project. For LinearAlgebra that does seem to fix it, but I recall more sophisticated setups where this still failed. Will try to cook up an MWE

Let鈥檚 say I鈥檓 developing a package called MyPackage and I have activated its Project.toml. It has one dependency called MyDependency, and one test depency called MyTestDependency.

After some exploration, it seems that IntelliSense鈥

  • works for MyDependency if either one of the following conditions is satisfied
    1. there is a using MyDependency statement at the top of my file
    2. my file is in src/ and included in the module MyPackage (which also contains the using MyDependency statement)
  • never works for MyTestDependency
  • never works for MyPackage

Did I get that right?

3 Likes

You are describing my exact experience.

Also - I tried both methods for test (extras + targets and dedicated test project inside the test directory). IntelliSense doesn鈥檛 work for any of my test-specific dependencies - or for the package I am writing the tests for.

It鈥檚 pretty cumbersome to write tests for functions with multiple parameters (I always need to lookup repeatedly my source code).

P.S. I am somehow surprised that there are not many/more questions/complaints related to this issue. Or maybe not many devs are having the problem, and there are good ways to fix this.

5 Likes

The vscode extension definitely needs some more dedicated dev work as the Is it maintained? shows.

1 Like

The question is, how could better maintenance of the extension be achieved? Is see three options:

  • make it more accessible for new developers
  • get commercial funding
  • perhaps a crowd funding campaign?
3 Likes

I don鈥檛 think it鈥檚 fair to say that the extension is poorly maintained. I have had several interactions with @davidanthoff and @pfitzseb and they all resulted in my problems being fixed.

4 Likes

Well, there are 834 open issues, and a key issue (from my point of view) https://github.com/julia-vscode/julia-vscode/issues/307 is now open since 2017 鈥

I think there is room for improvement, the current team is too small and due to a lack of developer documentation it is very hard to attract new developers鈥

2 Likes

Additional finding: If you use includet <file.jl> because you are using Revise autocomplete fails, but the following workaround works for me:

if isdefined(@__MODULE__,:LanguageServer)
    include("tests.jl")
else
    includet("tests.jl")
end

Yea, that is how things are at the moment.

Regarding

this should work if you are editing source files of MyPackage (i.e. code that are within module MyPackage ... end). For editing test/* files, or any other file in the repo not included in the module, this is LanguageServer.jl#988.

And

I think would be much easier to solve once we have sub projects.

2 Likes

From list of my PRs Pull requests 路 julia-vscode/julia-vscode 路 GitHub . It鈥 s understandable some are design choices. But I don鈥 t get it why simple translation and bugfix are not yet merged.

I think 1.9 is a great release. While the vscode extension experience kind of makes new comers suspicious of the maturity of the language.

3 Likes

If I include("../src/MyPackage.jl") at the top of runtests.jl I get IntelliSense in my test files (I remove the include statement before a test run and undo it right after the test is finished).

This is still less work then constantly switching between test and src files.

The MyTestDependency intelliSense is not solved by this workaround.

1 Like

Did you try:

if isdefined(@__MODULE__,:LanguageServer)
    include(../src/MyPackage.jl)
end
3 Likes

Thanks - this solves the autocompletion for the tested package.

1 Like

Can you explain what this does?

It includes the code of MyPackage.jl when the language server is looking at this file and otherwise, during normal execution or testing it does not include anything.

3 Likes

I鈥檓 reasonably sure you can just write this as

false && include("tests.jl")
includet("tests.jl")

Of course that won鈥檛 work in package code, but you shouldn鈥檛 be using Revise there anyways.

1 Like

The issue I think you鈥檙e running into is that intellisense is broken (well, intentionally disabled because it鈥檚 broken) for the /tests directory in particular.

You can probably work around that by having a complete Manifest inside of /tests that devs the package and explicitly contains test-only dependencies (but you might also need to then rename the dir). If you don鈥檛 have any test-only deps, then including the packages entrypoint should work fine, as pointed out earlier.

Wait so should I include runtests.jl in MyPackage.jl or the other way around?