Julia with neovim

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).

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]

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]

1 Like

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

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

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.

1 Like

Same here.Has anyone made progress?

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

I would point you to my Neovim configuration and in particular the julia_languageserver.jl helper script that is called from my lspconfig file. 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.

1 Like