Use LanguageServer.jl on vim 8.1 with vim-lsp plugin

Hi all, right now I succeed to use LanguageServer.jl on vim 8.1 with vim-lsp plugin; I will describe what I did below. I would be happy if it was helpful for others. Many thanks for the maintainers of LanguageServer.jl, this is definitely a great work.

Julia side

I could not get it work with v1.1.0, probably we need v1.0.3 currently. It may be solved for the future version.

  1. Install julia v1.0.3
  2. Open julia v1.0.3 and type ]add LanguageServer SymbolServer
  3. Save the startlanguageserver.jl (see below) as a file in your computer
  • startlanguageserver.jl
import LanguageServer
import Pkg
import SymbolServer

envpath = dirname(Pkg.Types.Context().env.project_file)

const DEPOT_DIR_NAME = ".julia"
depotpath = if Sys.iswindows()
    joinpath(ENV["USERPROFILE"], DEPOT_DIR_NAME)
else
    joinpath(ENV["HOME"], DEPOT_DIR_NAME)
end

server = LanguageServer.LanguageServerInstance(stdin, stdout, false, envpath, depotpath, Dict())
server.runlinter = true
run(server)

Vim side

Install vim-lsp and its requirements.

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'

Cited from the README of vim-lsp, please use your favorite plugin manager. If you want autocompletion, add some requirements.

Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'

Write the lines below into your vimrc. You need to arrange the path to the executable and the script; s:julia_exe and s:julia_lsp_startscript.

  • vimrc
let s:julia_exe = 'path/to/julia-1.0.3-executable'
let s:julia_lsp_startscript = 'path/to/startlanguageserver.jl'
if executable('julia')
  autocmd User lsp_setup call lsp#register_server({
  \ 'name': 'julia',
  \ 'cmd': {server_info->[s:julia_exe, '--startup-file=no', '--history-file=no', s:julia_lsp_startscript]},
  \ 'whitelist': ['julia'],
  \ })
endif

FYI, I’m using windows 10 and vim 8.1.878.

4 Likes

@machakann Thank you for great info!!. I tried it, however it doesn’t work…
When I command “:LspStatus”, It is shown that the julia server is “exited”.

Could you please let me know your versions of LanguageServer.jl and SymbolServer.jl?

Perferps, my OS could be related. I’m using Mac OS.

@AtsushiSakai I’m using LanguageServer.jl v"0.5.1" and SymbolServer.jl v"0.1.2".

I’m not sure why it exited. If you can use vim-lsp, try let g:lsp_log_file = 'lsp.log' and open a julia file. It will emit logs to the file lsp.log. It might help you to check what happened. If you can post or upload the logs, I may be able to help you but the log file may include your texts, paths and something personal. Be careful.

1 Like

@machakann It works!! Thank you. My LangulageServer was old.
Thank you for great info.

1 Like