My Julia setup for vim with YCM on Linux

Installation

$ pip install jill --user -U
$ jill install 1.3

lsp

Plug 'ycm-core/YouCompleteMe'
Plug 'ycm-core/lsp-examples'
Plug 'JuliaEditorSupport/julia-vim', {'for': 'julia'}

let g:ycm_language_server = [
			\   { 
			\     'name': 'julia',
			\     'filetypes': [ 'julia' ],
			\     'project_root_files': [ 'Project.toml' ],
			\	'cmdline': ['julia', '--startup-file=no', '--history-file=no', '-e', '
			\       using LanguageServer;
			\       using Pkg;
			\       import StaticLint;
			\       import SymbolServer;
			\       env_path = dirname(Pkg.Types.Context().env.project_file);
			\       
			\       server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, "");
			\       server.runlinter = true;
			\       run(server);
			\   ']
			\  },
			\ ]
$ cd $HOME/.vim/plugged/lsp-examples
$ ./install.py --enable-julia

Ctags and Gtags

# ~/.ctags.d/julia.ctags
--langdef=julia
--langmap=julia:.jl
--regex-julia=/^[ \t]*(([^ \t.({[]+\.)*@[^ \t({[]+[ \t]+)*(function|macro|abstract type|primitive type|struct|mutable struct|module)[ \t]+([^ \t({[]+).*$/\4/f,function/
--regex-julia=/^[ \t]*(([^ \t.({[]+\.)*@[^ \t({[]+[ \t]+)*(([^@#$ \t({[]+)|\(([^@#$ \t({[]+)\))[ \t]*[ \t]*\([^#]*\)([ \t]+where[ \t]+\{.*\})?[ \t]*=([^=].*)?$/\4\5/f,function/
--regex-julia=/^(([^ \t.({[]+\.)*@[^ \t({[]+[ \t]+)*(const[ \t]+)?(([^ \t.({[]+\.)*@[^ \t({[]+[ \t]+)*([^@#$ \t({[]+)[ \t]*=([^=].*)?$/\6/v,variable/

$ ctags -R  --totals=yes --exclude=`.*` --exclude=.git --languages=julia 
$ gtags

jupyter

Plug 'jupyter-vim/jupyter-vim', {'for': ['python', 'julia']}
8 Likes

YouCompleteMe Hover:

GNU global for ref:

Thanks for sharing, @junix

I am trying to get YouCompleteMe in NeoVim to play nice with LanguageServer.jl, but it does not work for me. My log files say that the Julia language server crashes. I tried with Julia 1.7 and (after reading this issue) with 1.6, but to no avail. Different errors pop up, but all involve the JSONRPC package. Could you share the Manifest of your Julia environment that runs language server? I would like to try with the exact same versions.

I just try it and it still works using ycm for julia 1.6 if you follow https://github.com/ycm-core/lsp-examples but it is horribly slow and consumes lots of CPU when starting(I wait for 1min).

Actually, I find I actually don’t need julia lsp to write julialang.

Gutentags and tag completion are nice for a project.

OhMyREPL and vim-slime(lots of similar plugins) are nice for REPL.

ftplugin/julia.vim

noremap <buffer> <localleader>d :call slime#send("@doc " . expand("<cword>") . "\r")<CR>

xmap <silent><buffer> <CR> <Plug>SlimeRegionSend
nmap <silent><buffer> <space><space> <Plug>SlimeParagraphSend

Btw localleader is for ftplugin and I think it may be silly to set localleader the same as leader.

Also, you can use quickui

nnoremap <localleader>] :call quickui#tools#preview_tag('')<cr>

to preview tags in a popup window

vim ~/.ctags

add https://gist.github.com/Evizero/e1595c35611c15ebf8f9.

vim ~/.ctags.d/exclusion.ctags

add exclusion.

cd $HOME/packages/julias/julia-1.7/share/julia/stdlib/v1.7/LinearAlgebra/
ctags -R --languages=julia --fields=+nl

DONOT forget --fields=+l

Add

let g:ycm_collect_identifiers_from_tags_files           = 1
let g:ycm_min_num_of_chars_for_completion               = 4

into your vimrc.

vim ~/.vim/ftplugin/julia.vim

add

setlocal tags+=$HOME/packages/julias/julia-1.7/share/julia/stdlib/v1.7/LinearAlgebra/tags
vim ~/.dotfiles/vim/.vim/after/syntax/julia.vim

add

hi link juliaFunctionCall juliaFunction

syntax keyword juliaFunction println zero zeros summary
syntax keyword juliaFunction eigvecs eigen eigvals

such like that.

Add

let g:ycm_seed_identifiers_with_syntax                  = 1

in your vimrc

I think I tried to follow your steps ( except for installing julia 1.7) but this is not working for me somehow.


as you can see, the juliacompleter server is dead. Can you give me some clue about what to check?

Show your config for julia.
eg:

let s:julia_cmdline = ['julia', '--startup-file=no', '--history-file=no', expand('~/.vim/lsp-julia/run.jl')]
let g:ycm_language_server += [
			\   { 'name': 'julia',
			\     'filetypes': [ 'julia' ],
			\     'project_root_files': [ 'Project.toml' ],
			\     'cmdline': s:julia_cmdline
			\   },
			\ ]

In lsp-julia/run.jl

using LanguageServer;
using Pkg;
import StaticLint;
import SymbolServer;
server = LanguageServer.LanguageServerInstance(stdin, stdout, "", "");
server.runlinter = false;
run(server);

Don’t forget to exec ./install.py --enable-julia in lsp-examples

And show your ycm log in /tmp

I am using NeoVim v0.6.1 and Julia v1.7.2. and I installed the plugins you mentioned.

Plug 'ycm-core/YouCompleteMe'
Plug 'ycm-core/lsp-examples'
Plug 'JuliaEditorSupport/julia-vim', {'for': 'julia'}

then I first tried with the config you posted. It did not work. then I tried to follow some other guides and ran ./install.py --enable-julia in lsp-examples, which suggested to source ~/.local/share/nvim/plugged/lsp-examples/vimrc.generated. which has the following config

     let g:ycm_lsp_dir = '/home/$USER/.local/share/nvim/plugged/lsp-examples'
     let g:ycm_language_server = []
  let s:julia_cmdline = ['julia', '--startup-file=no', '--history-file=no', '-e', '
\       using LanguageServer;
\       using Pkg;
\       import StaticLint;
\       import SymbolServer;
\       env_path = dirname(Pkg.Types.Context().env.project_file);
\       debug = false;
\
\       server = LanguageServer.LanguageServerInstance(stdin, stdout, debug, env_path, "", Dict());
\       server.runlinter = true;
\       run(server);
\   ']

let g:ycm_language_server += [
  \   { 'name': 'julia',
  \     'filetypes': [ 'julia' ],
  \     'project_root_files': [ 'Project.toml' ],
  \     'cmdline': s:julia_cmdline
  \   },
  \ ]

I have then tried using Plug 'autozimu/LanguageClient-neovim' but that did not work either. So I am assuming I am missing a very basic step, which I cannot figure out on my own.

logs at /tmp are

% cat ycm_1lp7j2jp.log 
2022-04-12 14:58:50,287 - ERROR - <urlopen error [Errno 111] Connection refused>
2022-04-12 14:58:50,390 - ERROR - <urlopen error [Errno 111] Connection refused>
2022-04-12 14:58:50,493 - ERROR - <urlopen error [Errno 111] Connection refused>
% cat ycmd_54423_stderr_e1g9hzuu.log 
2022-04-12 14:58:50,561 - INFO - Completion config: 50, detailing -1 candiates
2022-04-12 14:58:50,562 - INFO - Completion config: 50, detailing -1 candiates
2022-04-12 14:58:50,562 - INFO - Completion config: 50, detailing -1 candiates
2022-04-12 14:58:50,563 - INFO - Completion config: 50, detailing -1 candiates
127.0.0.1 - - [12/Apr/2022 14:58:50] "GET /ready HTTP/1.1" 200 4
127.0.0.1 - - [12/Apr/2022 14:58:50] "GET /signature_help_available?subserver=vim HTTP/1.1" 200 18
2022-04-12 14:58:50,612 - ERROR - Semantic completion not available for ['vim']
Traceback (most recent call last):
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 106, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 91, in GetFiletypeCompleter
    raise ValueError(
ValueError: No semantic completer exists for filetypes: ['vim']
127.0.0.1 - - [12/Apr/2022 14:58:50] "POST /event_notification HTTP/1.1" 200 2
2022-04-12 14:58:50,620 - INFO - Adding buffer identifiers for file: ~/.config/nvim/init.vim
2022-04-12 14:58:50,623 - ERROR - Semantic completion not available for ['vim']
Traceback (most recent call last):
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 106, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 91, in GetFiletypeCompleter
    raise ValueError(
ValueError: No semantic completer exists for filetypes: ['vim']
127.0.0.1 - - [12/Apr/2022 14:58:50] "POST /event_notification HTTP/1.1" 200 2
127.0.0.1 - - [12/Apr/2022 14:58:50] "POST /receive_messages HTTP/1.1" 200 5
2022-04-12 14:58:50,728 - ERROR - Semantic completion not available for ['vim']
Traceback (most recent call last):
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 106, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "~/.local/share/nvim/plugged/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 91, in GetFiletypeCompleter
    raise ValueError(
ValueError: No semantic completer exists for filetypes: ['vim']
127.0.0.1 - - [12/Apr/2022 14:58:50] "POST /semantic_completion_available HTTP/1.1" 200 5
% cat ycmd_54423_stdout_557d38wt.log 
serving on http://localhost:54423

% cat ycm_ik9n26h_.log 
2022-04-12 04:59:18,561 - ERROR - The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). Unexpected exit code 0. Type ':YcmToggleLogs ycmd_38959_stderr_r1z7u8c7.log' to check the logs.

1st, I’m using Julia v1.7.2 and vim8.2. I’m not sure whether it’s suitable for neovim. But I guess it should work.

2nd, don’t use the config you posted.
If you @doc LanguageServer.LanguageServerInstance, you will find how to use LanguageServerInstance. Or if the doc is not right, then you should check the source code of LanguageServer, which is not hard if you use ctags. It may be not the ycm team’s fault, LanguageServer’s API may have often been changed.

And I suggest you split your julia config as I do because it’s convenient to modify. Note: without the -e.

3rd, the log
ValueError: No semantic completer exists for filetypes: ['vim']
confuses me.
Does lsp-examples work for other languages?

Or you should try neovim built-in lsp. It sounds great. though I’m satisfied with my current workflow

I have not tried lsp with other languages.

I don’t understand what you mean by @doc LanguageServer.LanguageServerInstance I tried running this in julia but that did not show me anything.

using LanguageServer