Neovim + LanguageServer.jl

I’ve just tried to get this working, and I can successfully run the language server (from the log "[ Info: Received new data from Julia Symbol Server.\n"), but when using autocomplete inside of nvim it constantly says Missing Reference: ... next to the cursor when I’m typing and I don’t see any lsp suggestions in the autocomplete dropdown.

I’m running NVIM v0.5.0-584-gf137307dc. I tried my previous config, using the basic nvim config @kdheepak provided in the post above, and the aforementioned config with the additional packages deoplete and deoplete-lsp. I made sure to clear old plugins and cache files before trying this.

I also notice high CPU usage from the Julia process that runs when a .jl file is opened (note that this is after the first run where the packages are indexed), is that expected?

Does anyone have any suggestions to get this working?

Edit: It seems to show some lsp autocomplete suggestions when I’m editing a new file, but when editing an existing .jl file with a good bit of code in it I get the Missing Reference: ....

If you are getting “Missing Reference: …” then LSP is working for you. Diagnostics may show missing references if LanguageServer.jl is not able to find those references. This may happen for a number of reasons. For example LanguageServer.jl will only find references in the src folder of a package, and will not find references in the tests folder. This may also be affected by whether or not you have a Manifest.toml file in the folder. See @ExpandingMan’s LSPNeovim.jl package for more information on this.

If you want to decrease the verbosity of the diagnostic messages, you can use something like diagnostic-nvim. See @ExpandingMan’s dotfiles for an example of configuring neovim using nvim-lsp, diagnostic-nvim and deoplete and deoplete-lsp. Make sure you are using the latest versions of deoplete and deoplete-lsp.

I’m not sure why autocomplete isn’t working for you properly. If you are not wedded to deoplete, you can also try completion-nvim. You can see my dotfiles at this commit for an example on how to configure neovim, nvim-lsp, diagnostic-nvim, and completion-nvim.

Here’s the relevant pieces:

  1. Install the plugins
Plug 'nvim-lua/diagnostic-nvim'                                    | " better neovim built in lsp diagnostics
Plug 'nvim-lua/completion-nvim'                                    | " better neovim built in lsp completion
  1. Initialize
autocmd BufEnter * lua require'completion'.on_attach()

lua << EOF
    local nvim_lsp = require'nvim_lsp'
    local on_attach_vim = function()
        require'diagnostic'.on_attach()
    end
    nvim_lsp.julials.setup({on_attach=on_attach_vim})
EOF
  1. Configure
let g:diagnostic_auto_popup_while_jump = 0
let g:diagnostic_enable_virtual_text = 0
let g:diagnostic_enable_underline = 0
let g:completion_timer_cycle = 200 "default value is 80
1 Like

really hate how lsp eco system is fragmented so thanks for having pointers here. Since I write more julia than python now I decided to abandon the deoplete and jump to your band wagon:

still several questions (I use vim as a tool so not really know about the internals):

  1. your dotfile doesn’t have start language server parts such as Vim and Neovim · julia-vscode/LanguageServer.jl Wiki · GitHub ?

  2. when I ‘fix’ 1, I still don’t get completion prompt, and when I manually :call LanguageClient_textDocument_hover() I get a send to disconnected channel

I’m not using LanguageClient-neovim, I’m using the built-in LSP. It seems like currently there are four approaches: You can use LanguageClient-neovim, SpaceVim, deoplete or completion-nvim.

1 Like

Thanks for the explanation, @kdheepak! I was able to get Julia lsp autocomplete to work using the completion-nvim plugin you mentioned.

does your completion work for exported functions from modules?

i.e does calling :lua vim.lsp.buf.hover() on plot produce anything if you have using Plots?

edit: worked after I nuked ~/.julia

Yes, that works for me.

1 Like

Thanks for the tips! Are the indices supposed to be cached somewhere? If I open a Julia file that is not associated with a particular Project, the LS re-indexes every single package in my global Project.toml and it’s taking a lot of CPU each time.

Hi thanks for the thread. I’ve followed the instructions and ended up setting everything up.

However, I have a personal package that I use, which are just collections of functions at some home directory. I don’t have an actual project.toml files or anything like that. Stuff like src set up etc. since I am not familiar with how to properly develop packages.

However, I think that is leading to having missing reference error show up when I import that package.

For example, if I just have some package called A and have “using A”, that A shows up as missing reference.

Is there any way to tell Julia to get rid of this error message? I am already using diagonstic-nvim but that didn’t seem to help, unless I messed something up.

Secondly, suppose I have some named tuple called B that consists of a and b. If I type B. in the .jl file and press tab, nothing shows up. B is defined in the REPL (and ofc works in REPL). I do not have other external autocompletion plugin. Is there any way to get tab completion working for named tuples without an additional plugin like deoplete? I prefer not to use other external plugins at the moment because I use a lot of greek letters which uses tabs.

Thanks in advance.

1 Like

:LspInstall is not working anymore. How am I supposed to install julials?

For now, yes. Run the following:

julia -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'

I’ll plan to submit a PR to nvim-lspconfig to that it can be installed by the default install instructions.

For future reference, this is the location of the julia configuration.

https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/julials.lua

3 Likes

Hey, I have LanguageServer installed both globally and in my Project. nvim-lsp is working, but it cannot find the packages installed in the Project. Neovim working dir is the root of the project

Any advice?

Spot it, it’s because Startify moves my tab pwd but not the whole neovim pwd. I think the only solution is to make Startify move the whole pwd.

However, LanguageServer cannot recognize Flux and Random modules. Anyone with similar issue?

I’m also running this setup but for me whenever I try to start the server when I open a julia file my log shows an error.

[ START ] 2021-06-29T10:43:46+0200 ] LSP logging initiated
[ ERROR ] 2021-06-29T10:43:47+0200 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]    "rpc"   "julia" "stderr"        "ERROR: "
[ ERROR ] 2021-06-29T10:43:47+0200 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]    "rpc"   "julia" "stderr"        "StackOverflowError:"
[ ERROR ] 2021-06-29T10:43:47+0200 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]    "rpc"   "julia" "stderr"        "\n"

I’ve pulled the latest language server and neovim as well as installed the LanguageServer and SymbolServer. How did you get your setup to work? @sapo

Hello, can you try to read the log? :JuliaFormatterLog does the trick.

Also, with the latest version, :JuliaFormatterEchoCmd on the first call shows the command used for launching the server. Just copy it and launch in a different terminal. If it fails, feel free to put here the error output…

With the latest version of JuliaFormatter.vim you can use :JuliaFormatterEchoCmd to get the command that is being executed. There’s also :JuliaFormatterLog that shows you the log from the server that can help for debugging purposes. This of course is not related to LSP.

@sapo you and I are racing to post the same thing :slight_smile:

1 Like

Yep, I have just corrected my message above :slight_smile:
Thank you a lot, it’s one of the most useful plugin when working in Julia

Thanks for the tip with JuliaFormatterLog. Very useful. The juliaformatter actually works. It’s my neovim native lsp via nvim-lspconfig that doesn’t work. But I have no idea why. I just get a stackoverflow error from my ~/.cach/nvim/lsp.log file. Weird because when I run the same commands in julia on my own it works. Maybe I’ll just post it on neovim to see if those guys knows what’s going on. I’m sure I’m doing something stupid. :slight_smile:

you forgot to include server_path in your config. you can read more in https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
look for julials