# Neovim: Getting LSP running for Julia using Coc-Plugin

**URL:** https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654
**Category:** Tooling
**Tags:** vim
**Created:** [September 15, 2020, 6:46pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654 "2020-09-15T18:46:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![pascal-mueller](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pascal-mueller](https://discourse.julialang.org/u/pascal-mueller)
#### Post date: [September 15, 2020, 6:46pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/1 "2020-09-15T18:46:08Z")

</div>

so I’m trying to get LSP working for Julia using the CoC Plugin. It works for python or HTML. So I’m using:

Coc-Plugin: /neoclide/coc.nvim @ github  
CoC-Extension (coc-julia): /neoclide/coc.nvim/wiki/Language-servers#julia @github  
LSP-Server: [https://github.com/julia-vscode/LanguageServer.jl](https://github.com/julia-vscode/LanguageServer.jl) (recommended by the Coc-extension)

I also did:

```
julia> using Pkg
julia> Pkg.add("LanguageServer")
julia> Pkg.add("SymbolServer")
julia> Pkg.add("StaticLint")

```

Doesn’t really work. I don’t get any definitions. If I write “a” I just get a bunch of possible functions starting with a. Also jump to definition doesn’t seem to work. Either the server is just useless or I’m doing something wrong. Chances are way higher on the later.

I then uninstalled the coc extension and added the server config manually to my coc-settings.json - of course I first tried if the arguments in the config worked. They didn’t, might be a bug in the docs in the git of Coc. Anyway, I got this now: which should work according to [https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim](https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim)

```
{
    "python.jediEnabled": false,
    "languageserver": {
        "julia": {
            "command": "/usr/bin/julia",
            "args" : ["--startup-file=no", "--history-file=no", "-e",
           "using LanguageServer; using Pkg; import StaticLint; import SymbolServer; en
            "filetypes": ["julia"]
        }
    }
}

```

but same result. Now I’m having kind of a hard time debugging it since I’m new to Neovim and Coc but `ps aux | grep -i julia` shows that

```
/usr/bin/julia --startup-file=no --history-file=no --depwarn=no --eval using LanguageServer; import StaticLint; import SymbolServer; server = LanguageServer.LanguageServerInstance(stdin, stdout, "/home/<user>/.julia/environments/v1.5"); server.runlinter = true; run(server);

```

is running. (The command also works just fine or at least doesn’t throw an error.) So the server should run. And journalctl -n 40 also doesn’t show anything.

CocOpenLog also shows  
`1 2020-09-15T17:16:14.568 INFO (pid:5526) [services] - registered service "languageserver.julia"`

So I assume that Neovim/Coc has a connection to my server. I’m unsure it’s actually using it though. Again, maybe the server just doesn’t really do much?

Any input is appreciated.

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [September 20, 2020, 12:56pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/2 "2020-09-20T12:56:01Z")

</div>

This didn’t work for me a while back, but I just tried `coc-julia` again a few days ago, and it seems to work now. Popups displaying function definitions and autocompletions do, at least. Not sure about jumping to definitions.

It may take a little while for the LS to start up.

Also, `CocInfo` reports the error `IOError: bind: name too long (ENAMETOOLONG)` from Julia, but I’m not really sure how that error has affected anything, as things are working just as I expect them to.

---

<div class="post-metadata">

### Author: ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)
#### Post date: [October 15, 2020, 9:41am UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/3 "2020-10-15T09:41:58Z")

</div>

Any news? I tried to use it and I don’t get anything at all, like if my .jl file is not even recognized as a Julia file.  
Coc works flawlessly with Rust on the same machine, so I really think its a problem with coc-julia

---

<div class="post-metadata">

### Author: ![pascal-mueller](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pascal-mueller](https://discourse.julialang.org/u/pascal-mueller)
#### Post date: [October 15, 2020, 4:12pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/4 "2020-10-15T16:12:13Z")

</div>

Back then there was a bug in the Julia Language Server. It might have been fixed. I tried fixing it by myself and I think I ws able to but it didn’t really work anyway. Never tried it again.

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 22, 2020, 10:39am UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/5 "2020-10-22T10:39:40Z")

</div>

coc-julia is working very well for me. Do you have julia-vim installed? If **not** , then your vim will probably think your `.jl` files are lisp files (unless you set the ft yourself some other way). That might be why the LS isn’t working for you.

**Edit:** Fixed a typo, in bold.

---

<div class="post-metadata">

### Author: ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)
#### Post date: [October 22, 2020, 12:27pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/6 "2020-10-22T12:27:20Z")

</div>

Yeah I removed julia-vim but I still get nothing, not even syntax highlighting. There’s something I should add to mi init.vim file in order to make coc-julia work?

---

<div class="post-metadata">

### Author: ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)
#### Post date: [October 22, 2020, 12:30pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/7 "2020-10-22T12:30:47Z")

</div>

I forgot to mention: I effortlessly got CoC to work for Rust, simply installing the corresponding module with CocInstall. For Julia, I followed the same steps but it simply does nothing

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 22, 2020, 12:39pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/8 "2020-10-22T12:39:29Z")

</div>

Sorry, there was a typo in my last post. You want to keep julia-vim installed. (Or, otherwise, `set ft=julia` for `.jl` files by an `autocmd`.)

I’m not sure if LanguageServer.jl supports syntax highlighting yet. But, other than that, coc-julia worked for me without having to do anything other than installing it. What exactly isn’t working with coc-julia for you? Other than syntax highlighting, because I don’t think that’s available (or, at least, hasn’t worked for me yet either).

Can you add `coc#status()` to your statusline (or you could call it manually too I guess) to see what coc does when you open a `.jl` file? You can also try `:CocInfo` and `:CocOpenLog` to see if coc starts the Julia language server.

---

<div class="post-metadata">

### Author: ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)
#### Post date: [October 22, 2020, 2:02pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/9 "2020-10-22T14:02:49Z")

</div>

If I take julia-vim installed together with coc-julia I get errors, so I think the two of them goes in conflict. I could stand (for now) to be without the syntax highlighting provided from julia-vim, I would really like to get coc-julia to work with autocompletion. At the actual state, I only get completion for reserved words and words that I already used in the same file, but no autocompletion for modules or their imported methods and functions

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 22, 2020, 2:21pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/10 "2020-10-22T14:21:58Z")

</div>

coc-julia and julia-vim work fine for me, so perhaps there is something else wrong with your configuration.

The way coc-julia works (but I think this might be how it is implemented in LanguageServer.jl, I’m not sure) is that it checks your cwd for a Manifest.toml file so that it can index the modules you’re importing from elsewhere. If you generate that file in your working directory, then coc-julia will do what you want.

---

<div class="post-metadata">

### Author: ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)
#### Post date: [October 26, 2020, 2:39pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/11 "2020-10-26T14:39:14Z")

</div>

I tried to use the sample init.vim file present on the github page of COC. I tried without it (“blank” init.vim file with only COC and Julia module installed) but it still doesn’t work and I get the same error message:

[coc.nvim]: Some plugin change completeopt on insert mode: Last set from ~/.config/nvim/plugged/julia-vim/autoload/LaT  
eXtoUnicode.vim line 404!

Ho did you configured julia-vim and COC in your init.vim file? Did you just installed both and it simply worked out of the box? Which version of neovim or vim are you using?

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 26, 2020, 5:57pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/12 "2020-10-26T17:57:00Z")

</div>

Do you mean the configuration found in [this section](https://github.com/neoclide/coc.nvim#example-vim-configuration)?

It should work out of the box, but coc does like to complain when another plugin does automatic completion in your buffer. The error you see should appear whenever you try to use julia-vim’s LaTeX-to-Unicode substitution (e.g. when you type `\mu`, it converts it automatically to `µ`, perhaps after pressing `<Tab>`). However, as far as I can tell, the error doesn’t really have any impact other than being annoying.

To avoid the error, I’ve turned off julia-vim’s LaTeX-to-Unicode substitution by putting this in my `init.vim` / `.vimrc`:

```nohighlight
let g:latex_to_unicode_file_types = '$^'
let g:latex_to_unicode_file_types_blacklist = '.*'

```

One probably really only needs the first line, but I haven’t gotten around to testing it fully. The language server can also do the same substitutions, so I haven’t noticed any loss in functionality from disabling the julia-vim-L2U plugin. (See `:help julia-vim-L2U`, `:help g:latex_to_unicode_file_types`, etc.)

julia-vim-L2U also allows you to customise the behaviour of its substitutions. If you want to keep using it, but don’t like the error coc gives you, you can try reading `:help julia-vim-L2U-keymap`. I’ve found that turning this on and turning off tab/automatic completion avoids the error from coc. (However, you should not include the `init.vim` config I’ve shown you above to use it.)

Note that the configuration above will deactivate LaTeX-to-Unicode substitutions for all filetypes, so you’ll want to modify it appropriately if you want to use it for some non-Julia filetypes.

I am using Neovim built from the master branch. That is, `NVIM v0.5.0-a22fe09`, so I might be a few commits behind the current master branch.

---

<div class="post-metadata">

### Author: ![nacnudus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nacnudus/32/15762_2.png) [@nacnudus](https://discourse.julialang.org/u/nacnudus)
#### Post date: [October 29, 2020, 9:38pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/13 "2020-10-29T21:38:06Z")

</div>

I have been struggling too. Here is a minimal `init.vim` for neovim with only coc and julia-vim. I have also installed coc-julia. Latex-to-unicode substitution then happens like this:

1. I type the characters `\mu`
2. I type the tab key
3. I type the backspace key
4. I type the tab key again, and this time the substitution is made. The 404 error message may or may not appear. If I keep alternating tab and backspace, no further substitution is made, but sometimes the 404 message appears.

```nohighlight
call plug#begin('/home/nacnudus/.config/nvim/plugged')  
Plug 'neoclide/coc.nvim', {'branch': 'release'}"
Plug 'JuliaEditorSupport/julia-vim'
call plug#end()
filetype plugin indent on

```

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 29, 2020, 10:52pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/14 "2020-10-29T22:52:10Z")

</div>

> [@chisquared](#):
>
> It should work out of the box, but coc does like to complain when another plugin does automatic completion in your buffer. The error you see should appear whenever you try to use julia-vim’s LaTeX-to-Unicode substitution (e.g. when you type `\mu` , it converts it automatically to `µ` , perhaps after pressing `<Tab>` ). However, as far as I can tell, the error doesn’t really have any impact other than being annoying.
> 
> To avoid the error, I’ve turned off julia-vim’s LaTeX-to-Unicode substitution by putting this in my `init.vim` / `.vimrc` :
> 
> ```julia
> let g:latex_to_unicode_file_types = '$^'
> let g:latex_to_unicode_file_types_blacklist = '.*'
> 
> ```
> 
> One probably really only needs the first line, but I haven’t gotten around to testing it fully.

Hi @nacnudus, did you get the chance to read this part of my previous post?

---

<div class="post-metadata">

### Author: ![nacnudus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nacnudus/32/15762_2.png) [@nacnudus](https://discourse.julialang.org/u/nacnudus)
#### Post date: [October 29, 2020, 11:13pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/15 "2020-10-29T23:13:37Z")

</div>

Hi @chisquared, thank you for replying. Yes I did read your full post. Using those two lines disables LaTeX-to-Unicode substitution altogether for me, and I would like to retain it. Without using those two lines, the substitution is only made at the second attempt, and I would prefer it to be made at the first attempt, which is what julia-vim does on its own (when coc.vim and coc-julia aren’t installed).

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 29, 2020, 11:56pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/16 "2020-10-29T23:56:25Z")

</div>

The language server should be able to do L2U-substitution, though I’m not quite sure what you mean by first and second attempt. ( **Edit:** Ok, now I understand. See further edit below.) L2U-substitution using julia-vim vs using the language server are practically indistinguishable for me, aside from julia-vim being perhaps a split second faster while the language server is still starting up.

One way to keep using coc for completion while also using julia-vim without errors is described in the second part of my previous post, though I don’t find the experience ideal. (It’s hard to describe. You can try it out for yourself to see.)

I guess your other alternative is to turn off coc completion for `.jl` files and just rely on julia-vim, but that’ll be much more limited.

Finally, I suppose you could also try the other language server plugins available for vim:

> **[Neovim + LanguageServer.jl](https://blog.kdheepak.com/neovim-languageserver-julia.html)**
>
> Showcasing Neovim and LanguageServer.jl

[https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim](https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim)

**Edit:** Ok, I think I now understand what you mean. That’s because your `init.vim` contains no keybindings for coc completion. I don’t think it should even work at all the second time, but perhaps I am missing something.

If you want to use tab-completion with coc, you’ll need to use some of the configuration given [here](https://github.com/neoclide/coc.nvim#example-vim-configuration) (along with deactivating julia-vim-L2U). For example:

```nohighlight
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1] =~# '\s'
endfunction

```

I should mention that I’ve found this piece of the config a little finicky when it comes to working with other plugins (e.g. UltiSnips), but you may wish to try it.

I’m not using this particular suggested configuration. Instead, I patterned mine off the coc keybindings I found here:

[https://github.com/lervag/dotvim](https://github.com/lervag/dotvim)

---

<div class="post-metadata">

### Author: ![nacnudus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nacnudus/32/15762_2.png) [@nacnudus](https://discourse.julialang.org/u/nacnudus)
#### Post date: [October 30, 2020, 10:08am UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/17 "2020-10-30T10:08:48Z")

</div>

Thanks again, I have now tried that chunk of tab completion configuration, and also the relevant parts of lervag/dotvim. The L2U substitution by the language server still doesn’t work either way. This is in a completely clean init.vim, and the only coc extension installed is coc-julia. It seems the only option now is to try other language server plugins, unless there is an example init.vim somewhere that has been confirmed to work.

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [October 30, 2020, 11:37am UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/18 "2020-10-30T11:37:10Z")

</div>

That is very strange. Sorry it hasn’t worked for you.

I think you’ll want to try the built-in LS plugin described in the blogpost I shared (it’s also in the second half of the wiki page on vim at the LanguageServer.jl repo); I believe the way that completion is implemented there is a bit friendlier to how julia-vim does L2U-substitution.

If you’d like to keep trying with coc, send me a PM and I can send my `init.vim`.

---

<div class="post-metadata">

### Author: ![nacnudus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nacnudus/32/15762_2.png) [@nacnudus](https://discourse.julialang.org/u/nacnudus)
#### Post date: [October 31, 2020, 11:50pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/19 "2020-10-31T23:50:38Z")

</div>

With help from @chisquared I have got LatTeX-to-unicode substitution working from the language server instead of the vim-julia package. However, it only replaces the backslash, not the rest of the text already written, so the result is `muμ` instead of `μ`.

There is a setting to control whether the existing text is replaced, `suggest.fixInsertedWord`, which defaults to `true`. I have also tried manually setting that in the coc config, to no avail.

---

<div class="post-metadata">

### Author: ![chisquared](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chisquared](https://discourse.julialang.org/u/chisquared)
#### Post date: [November 1, 2020, 10:01pm UTC](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654/20 "2020-11-01T22:01:56Z")

</div>

> [@nacnudus](#):
>
> However, it only replaces the backslash, not the rest of the text already written, so the result is `muμ` instead of `μ` .

Huh, this happens to me now too. This isn’t how coc used to work, and I think is a bug either in coc.nvim or coc-julia.

[Next page](https://discourse.julialang.org/t/neovim-getting-lsp-running-for-julia-using-coc-plugin/46654.md?page=2)
