# Julia with neovim

**URL:** https://discourse.julialang.org/t/julia-with-neovim/112182
**Category:** Tooling
**Tags:** neovim
**Created:** [March 27, 2024, 2:27pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182 "2024-03-27T14:27:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![krause](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@krause](https://discourse.julialang.org/u/krause)
#### Post date: [March 27, 2024, 2:27pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/1 "2024-03-27T14:27:48Z")

</div>

Hey all,  
i’m using neovim with Julia (julials). I have set up my LSP with “Mason” regarding to the documentation from the github. I include the relevant configs here, but if you want a look at my full neovim config, go to my GitHub: ([GitHub - MichaelBrueggemann/nvim](https://github.com/MichaelBrueggemann/nvim)).

My Issue is, that the LSP is working correctly (i can get Hover documentation etc.) but when i’m in a file that uses Tokens from a local module, neovim doesnt recognize the References. But when i’m in a file deeper nested in my project, this issue is gone.

The module “GEMS” is fully defined in “~/Repositories/gems” and i started my neovim session in this directory via “nvim .”.

Does anyone has had similar experiences? If there are Information missing, please tell me.

As i’m a new user i can’t create multiple embedded files, so i placed all relevant screenshots in a PNGs at the bottom.

[LSP-Config]

```julia
local mason = require('mason')
local mason_lsp = require('mason-lspconfig')

-- setup mason itself
mason.setup({
    ui = {
        icons = {
            package_installed = "✓",
            package_pending = "➜",
            package_uninstalled = "✗"
        }
    }
})

-- Customized on_attach function
-- See `:help vim.diagnostic.*` for documentation on any of the below functions

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
    -- Enable completion triggered by <c-x><c-o>
    vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- See `:help vim.lsp.*` for documentation on any of the below functions
    local opts = { buffer = bufnr }
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
    vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
    vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
    vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
    vim.keymap.set('n', '<leader>rf', vim.lsp.buf.references, opts)
    vim.keymap.set('n', '<leader>f', function()
        print("formatting...")
        vim.lsp.buf.format { async = true }
        print("Formatting done!")
    end, opts)

    print("Language server started: " .. client.name)
end

local lspconfig = require('lspconfig')
local lsp_capabilities = vim.lsp.protocol.make_client_capabilities()

-- define autocompletion capabilitites
local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities(lsp_capabilities)

-- list all lsp servers, that should be installed
local lsp_servers = {
    'lua_ls',
    'julials',
    'jdtls',
}

-- install lsps
mason_lsp.setup({
    ensure_installed = lsp_servers,
    automatic_installation = true,
})

lspconfig.julials.setup({
    on_attach = on_attach,
    capabilities = cmp_capabilities,
})

```

[Screenshots]

 ![Screenshots](https://global.discourse-cdn.com/julialang/original/3X/f/3/f3abc7653ab307311d830858a144de952e407b8d.png)

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [March 27, 2024, 6:13pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/2 "2024-03-27T18:13:43Z")

</div>

Yeah, same. I think this is a problem with LanguageServer.jl (this was happening to me in helix too).

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [March 28, 2024, 4:24pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/3 "2024-03-28T16:24:56Z")

</div>

Same here. What I don’t understand is why VSCode doesn’t have this problem? Or do they?

---

<div class="post-metadata">

### Author: ![krause](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@krause](https://discourse.julialang.org/u/krause)
#### Post date: [March 29, 2024, 9:22pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/4 "2024-03-29T21:22:47Z")

</div>

One thing to add, i think it has to do something with my custom package and the startup of the LSP. I could think of, that it could be necessary to run like "julia -e ‘using Pkg; Pkg.instantiate()’ in the directory where my Project.toml is on startup of the LSP. But i dont know how to change this in the LSP settings and i also don’t think that this should be done by a user in the first place.

---

<div class="post-metadata">

### Author: ![SoerenNagel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soerennagel/32/213699_2.png) [@SoerenNagel](https://discourse.julialang.org/u/SoerenNagel)
#### Post date: [November 25, 2024, 10:39pm UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/5 "2024-11-25T22:39:36Z")

</div>

Same here.Has anyone made progress?

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [November 26, 2024, 1:08am UTC](https://discourse.julialang.org/t/julia-with-neovim/112182/6 "2024-11-26T01:08:53Z")

</div>

You still have to instantiate the environment that the LSP should connect to.

I would point you to [my Neovim configuration](https://github.com/goerz/neovimrc) and in particular the [julia\_languageserver.jl](https://github.com/goerz/neovimrc/blob/master/helpers/julia_languageserver.jl) helper script that is [called from my lspconfig file](https://github.com/goerz/neovimrc/blob/94c12b0a4bc93872cdac6fb816b04f020c7a8c64/lua/plugins/lspconfig.lua#L131). That script doesn’t instantiate the environment (because I always have my environments instantiated from running the tests), but it could. The sky is the limit to what you can set up for your workflow.
