# How to make vscode aware of user modules

**URL:** <https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948>\
**Category:** VS Code\
**Tags:** question\
**Created:** [April 9, 2019, 6:02am UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948 "2019-04-09T06:02:10Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![marty0801](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marty0801/32/12715_2.png) [@marty0801](https://discourse.julialang.org/u/marty0801)\
**Post date:** [February 15, 2021, 2:01pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/21 "2021-02-15T14:01:46Z")

</div>

May I ask some follow-on questions? I’m having similar problems moving to VSCode from Juno.

1. Do you keep your package source code in ~/.julia/dev? (Correct me if I’m wrong, but this seems to be the default location for PkgTemplates, and is required for introspection by the VSCode language server.)
2. If not, how do you synchronize your package source code with .julia/dev? (I’ve read most of the Pkg documentation, but must have missed this part.)
3. More generally, would you mind sketching out your package development workflow?

Let me know if I ought to be starting a different topic. Thank you very much.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 15, 2021, 5:00pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/22 "2021-02-15T17:00:36Z")

</div>

> [@marty0801](#):
>
> Do you keep your package source code in ~/.julia/dev?

No.

> [@marty0801](#):
>
> If not, how do you synchronize your package source code with .julia/dev? (I’ve read most of the Pkg documentation, but must have missed this part.)

I don’t.

> [@marty0801](#):
>
> would you mind sketching out your package development workflow?

I keep code at an arbitrary location (`~/code/julia/Foo` for `Foo.jl`), and activate it if I am working on it.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [February 15, 2021, 5:02pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/23 "2021-02-15T17:02:33Z")

</div>

> [@marty0801](#):
>
> and is required for introspection by the VSCode language server

This also isn’t true. You just need to point VSCode to the correct environment via the env selector in the lower left (modulo some bugs in our env handling that should be fixed in the next minor release).

---

<div class="post-metadata">

**Author:** ![marty0801](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marty0801/32/12715_2.png) [@marty0801](https://discourse.julialang.org/u/marty0801)\
**Post date:** [February 15, 2021, 10:14pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/24 "2021-02-15T22:14:30Z")

</div>

I’m unable to get autocompletion to work in VSCode for user-defined modules except for those present in .julia/dev as packages. Is this user-error, or one of the bugs to which you alluded?

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [March 3, 2021, 3:03pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/25 "2021-03-03T15:03:47Z")

</div>

Can someone post a step-by-step guide to creating a project where autocomplete works across different files in that project?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 3, 2021, 8:42pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/26 "2021-03-03T20:42:01Z")

</div>

Well, for me it works if I have one file in which I define a module, lets call it Utils.jl

```julia
module Utils
export my_test

function my_test()
    println("my_test")
end

end

```

and a main program that includes this module in the same directory:

```julia
include("./Utils.jl")
using .Utils

my_test()

```

If I now right click on my\_test() I can select “Go to Definition” and it works.

The main program and the module(s) that you include do not have to be in the same directory,  
but if they are not you have to adapt the relative path in the include statement.

Typing: `my<TAB>` should result in auto completion to `my_test`.

Does that work for you?

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [March 3, 2021, 8:55pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/27 "2021-03-03T20:55:55Z")

</div>

This works for me, thank you!

In contrast,

```julia
push!(LOAD_PATH, @ __DIR__ )
using Utils

my_test()

```

, which is what I was using before, runs but does not autocomplete.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 3, 2021, 8:58pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/28 "2021-03-03T20:58:09Z")

</div>

> [@Satvik](#):
>
> which is what I was using before, runs but does not autocomplete.

That is a known issue which might or might not be fixed at some point in time:

> <https://github.com/julia-vscode/julia-vscode/issues/307>
>
> The linter seems to think things are undefined even if they are there:
> 
> Define…d here:
> !\[image\](https://user-images.githubusercontent.com/734386/31589568-fef6ba42-b1d1-11e7-8872-3abd9dad3682.png)
> 
> used here:
> !\[image\](https://user-images.githubusercontent.com/734386/31589582-1fcfe8f6-b1d2-11e7-9c97-21f240263238.png)
> 
> output in the linter pane:
> !\[image\](https://user-images.githubusercontent.com/734386/31589586-31a6868e-b1d2-11e7-9a8d-64bb1218a921.png)
> 
> I think this might have to do with the fact that the \`SampledSignals\` package isn't located in the normal \`.julia/v0.6\` package directory, but is in a different directory that I add to my \`LOAD\_PATH\` in \`.juliarc.jl\`.
> 
> It also might be more useful in this case to display the warning on the \`import\` line with something like "Could not find package SampledSignals" rather than later on when you try to use the identifier.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 3, 2021, 9:04pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/29 "2021-03-03T21:04:39Z")

</div>

Yeah, honestly, I’d recommend setting up a local environment instead of any `LOAD_PATH` shenanigans.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 3, 2021, 9:07pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/30 "2021-03-03T21:07:38Z")

</div>

> [@pfitzseb](#):
>
> I’d recommend setting up a local environment

But that does not solve this issue. It is not even a work around.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 3, 2021, 9:25pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/31 "2021-03-03T21:25:25Z")

</div>

Why not? If you’re using `LOAD_PATH`, it’s because you want to load a package somewhere. Instead just put that relationship into a Manifest and you’re good to go, no?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/2/c27d28b96883a235716457dc45c90865f8f64e06.png)

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [March 3, 2021, 9:29pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/32 "2021-03-03T21:29:08Z")

</div>

Could you say more about this workflow or post a link that explains it? I have a Project.toml and Manifest.toml that contain external libraries, which were auto-generated via `Pkg.add`, how do I add my own files to it?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 3, 2021, 9:40pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/33 "2021-03-03T21:40:29Z")

</div>

> If you’re using `LOAD_PATH` , it’s because you want to load a package somewhere.

I was using LOAD\_PATH in the past not to load a package, but a module, usually in a file in the same directory.

A local environment does only help if you are a package developer. But many people just write projects, not packages. In that case my work around helps.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 3, 2021, 9:49pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/34 "2021-03-03T21:49:39Z")

</div>

Sure, but you weren’t doing anything with `LOAD_PATH` 🙂 That’s a perfectly fine solution for referencing local files.

> [@Satvik](#):
>
> Could you say more about this workflow or post a link that explains it? I have a Project.toml and Manifest.toml that contain external libraries, which were auto-generated via `Pkg.add` , how do I add my own files to it?

Take a look at the [Pkg docs](https://docs.julialang.org/en/v1/stdlib/Pkg/). What I did to generate the above example was basically

```julia
$ mkdir VSCode-Test
$ cd VSCode-Test
$ mkdir Foo
$ echo 'name = "Foo"\nuuid = "a33f4f40-c364-4a1b-9be3-145a5eb10e1c"' > ./Foo/Project.toml
$ mkdir Foo/src
$ echo 'module Foo\nf(x)=x\nend' > ./src/Foo.jl
$ code .
$ julia --project=.
(VSCode-Test) pkg>dev ./Foo

```

and then right click on the Project.toml in VSCode and select `Activate This Environment`.

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [April 30, 2021, 7:45pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/35 "2021-04-30T19:45:11Z")

</div>

I created a package, which I named `Experiments` and I dump all my scripts in `src`. I also set up a `startup.jl` file inside `.doc/config/` with something like

```
cd("path/to/experiments/") # set up path to package
import Pkg
Pkg.activate(".")

```

This is an all-purpose environment. I don’t have to have a `push` command or similar. This seems okay for short scripts and quick debugging of loops. Once in a while I delete everything below the `# This file is machine-generated - editing it directly is not advised` header in the `Manifest.toml` file and re-install packages as I need them.

Anything seriously wrong with this approach?

---

<div class="post-metadata">

**Author:** ![Dustin\_Hess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dustin_hess/32/11957_2.png) [@Dustin\_Hess](https://discourse.julialang.org/u/Dustin_Hess)\
**Post date:** [May 4, 2021, 2:47am UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/36 "2021-05-04T02:47:17Z")

</div>

Sorry to dig this up again but I cannot get user defined modules to work with code completion. Reading through these post it seems if you have generated a package and added it to dev it should work.

```julia
[dustin@Odin-pc ~]$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.6.1 (2021-04-23)
 _/ |\ __'_|_|_|\__'_| |  
|__/ |

(@v1.6) pkg> status
      Status `~/.julia/environments/v1.6/Project.toml`
  [023a3684] GenieVue v0.1.0 `~/Git/Projects/genieplayground/GenieVue`
  [6696d0b5] RPGCombat v0.1.0 `~/Git/Projects/Katas/RPGCombat`

(@v1.6) pkg>

```

My Project.toml file looks like

```julia
name = "RPGCombat"
uuid = "6696d0b5-b9c1-4907-9ab0-32591776c20d"
authors = "Dustin"
version = "0.1.0"

[deps]
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

```

My env: is RPGcombat in VScode  
I am setting something up incorrectly?

---

<div class="post-metadata">

**Author:** ![apg](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@apg](https://discourse.julialang.org/u/apg)\
**Post date:** [December 29, 2021, 6:04am UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/37 "2021-12-29T06:04:49Z")

</div>

I have custom modules I want to use, so I set julia.environmentPath in vscode, but this flag does not seem to be doing anything at all. I have also tried:  
using Pkg and Pkg.activate(/path/to/whatever) in the julia file but this is an aweful solution polluting the julia file. On top of that, it does not seem to be loading modules from the environment of my choosing and seems to load modules from ~/.julia even when environment is selected differently.

using somePackage  
pathof(somePackage)

This always returns ~/.julia/path/to/some/package

The only way I have found it working was when I export JULIA\_DEPOT\_PATH and JULIA\_PROJECT and run julia from the terminal.

I can’t seem to set the custom julia environment (without polluting julia sorce file) and get packages from that environment correctly in vscode. I’d appreciate it if anyone could share how to get these two environment variables to work in vscode so that the julia environment is consistent with packages defined in that environment.

I have tried adding these environment variables in launch.json file, but vscode does not seem to care

Thanks!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [December 29, 2021, 10:40am UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/38 "2021-12-29T10:40:46Z")

</div>

I am not using the work around I suggested earlier in this thread any longer, because it makes pre-compilation impossible.

It is pretty clear that the current vscode for Julia team will not fix [https://github.com/julia-vscode/julia-vscode/issues/307](https://github.com/julia-vscode/julia-vscode/issues/307) . So the only way to go forward is to create a fork, implement a good linter and fix this issue. A first step could be to define the requirements and interface of a language server/ linter, that finds modules in the load path.

---

<div class="post-metadata">

**Author:** ![Kirby\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirby_zhang/32/36204_2.png) [@Kirby\_Zhang](https://discourse.julialang.org/u/Kirby_Zhang)\
**Post date:** [July 3, 2022, 6:46pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/39 "2022-07-03T18:46:05Z")

</div>

I have followed Julia community for 2 months. There are so many people smart at compilers, but making unbelievable common sense decisions. I notice you said the code was very hard to read. what would it take to just read JULIA\_LOAD\_PATH one time on startup?

---

<div class="post-metadata">

**Author:** ![alequa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alequa/32/12338_2.png) [@alequa](https://discourse.julialang.org/u/alequa)\
**Post date:** [January 20, 2023, 12:48pm UTC](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948/40 "2023-01-20T12:48:23Z")

</div>

This solved it for me. Now VScode can `Go to Definition` of the symbols in my user-defined packages.

For clarity.  
I am `using DrWatson`. I create a new environment by using: `DrWatson.initialize_project("Foo")`

Once in the new environment (which looks pretty much like a package!) I move in the `src` folder and create a new package with `]generate myFooPackage`.

At this point I activate the environment (with shell in: `/projects/Foo/`).

```julia
]activate .
]dev ./src/myFooPackage

```

Now to have the symbols in `myFooPackage` available I have to go to Code options (Maiusc-Command-P) and click on `Julia: Change Current Environment`. There I select `Foo` and it works.

[Previous page](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948.md?page=1)

[Next page](https://discourse.julialang.org/t/how-to-make-vscode-aware-of-user-modules/22948.md?page=3)
