diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-02-13 02:03:15 +0900 |
---|---|---|
committer | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-02-13 02:03:15 +0900 |
commit | 4e6441f09c86f42a01ccf3b4f3a0a147d9bf9331 (patch) | |
tree | 38de9fea98706a36398a6d0258887ab2e69112b2 | |
parent | 94bda9483d386c592cc2e6a9ff2a87462124bd4a (diff) | |
parent | a2e7bad60ba6509c5e37e0035f7829a6d60ea823 (diff) | |
download | vim-lsp-settings-4e6441f09c86f42a01ccf3b4f3a0a147d9bf9331.tar.gz vim-lsp-settings-4e6441f09c86f42a01ccf3b4f3a0a147d9bf9331.tar.bz2 vim-lsp-settings-4e6441f09c86f42a01ccf3b4f3a0a147d9bf9331.zip |
Merge branch 'master' into add-LspSwitchSourceHeader
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | autoload/lsp_settings.vim | 32 | ||||
-rw-r--r-- | installer/install-julia-language-server.cmd | 28 | ||||
-rwxr-xr-x | installer/install-julia-language-server.sh | 26 | ||||
-rw-r--r-- | settings.json | 14 | ||||
-rw-r--r-- | settings/julia-language-server.vim | 13 | ||||
-rw-r--r-- | test/lsp_settings.vimspec | 4 |
7 files changed, 111 insertions, 7 deletions
@@ -50,6 +50,7 @@ But when rebuild the cache, any merging plugin manager erases old cached files(i You can change the directory to install servers by set `g:lsp_settings_servers_dir` option in full path. ## Usage +While editing a file with a supported filetype: ``` :LspInstallServer diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 3b78c66..476eda3 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -9,6 +9,10 @@ call remove(s:settings, '$schema') let s:ftmap = {} +function! lsp_settings#installer_dir() abort + return s:installer_dir +endfunction + function! lsp_settings#servers_dir() abort let l:path = fnamemodify(get(g:, 'lsp_settings_servers_dir', s:servers_dir), ':p') if has('win32') @@ -176,9 +180,13 @@ function! lsp_settings#autocd(server_info) abort endif endfunction +function! lsp_settings#settings() abort + return s:settings +endfunction + function! lsp_settings#complete_uninstall(arglead, cmdline, cursorpos) abort let l:installers = [] - for l:ft in keys(s:settings) + for l:ft in sort(keys(s:settings)) for l:conf in s:settings[l:ft] if !isdirectory(lsp_settings#servers_dir() . '/' . l:conf.command) continue @@ -272,6 +280,7 @@ function! s:vim_lsp_install_server(ft, command) abort endif let l:server_install_dir = lsp_settings#servers_dir() . '/' . l:entry[0] if isdirectory(l:server_install_dir) + call lsp_settings#utils#msg('Uninstalling ' . l:entry[0]) call delete(l:server_install_dir, 'rf') endif call mkdir(l:server_install_dir, 'p') @@ -293,11 +302,12 @@ function! s:vim_lsp_settings_suggest(ft) abort if empty(l:entry) return endif + + redraw! + echohl Directory + echomsg 'Please do :LspInstallServer to enable Language Server ' . l:entry[0] + echohl None if exists(':LspInstallServer') !=# 2 - redraw! - echohl Directory - echomsg 'Please do :LspInstallServer to enable Language Server ' . l:entry[0] - echohl None command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_install LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>) endif endfunction @@ -324,8 +334,16 @@ function! s:vim_lsp_suggest_plugin() abort endfor endfunction +function! s:vim_lsp_load_or_suggest_delay(ft) abort + call s:vim_lsp_load_or_suggest(a:ft) + "if get(g:, 'vim_lsp_settings_filetype_no_delays', 0) + " return s:vim_lsp_load_or_suggest(a:ft) + "endif + "call timer_start(0, {timer -> [s:vim_lsp_load_or_suggest(a:ft), execute('doautocmd BufReadPost')]}) +endfunction + function! s:vim_lsp_load_or_suggest(ft) abort - if !has_key(s:settings, a:ft) + if (a:ft !=# '_' && &filetype !=# a:ft) || !has_key(s:settings, a:ft) return endif @@ -422,7 +440,7 @@ function! lsp_settings#init() abort endif exe 'augroup' lsp_settings#utils#group_name(l:ft) autocmd! - exe 'autocmd FileType' l:ft printf("call s:vim_lsp_load_or_suggest('%s')", l:ft) + exe 'autocmd FileType' l:ft 'call' printf("s:vim_lsp_load_or_suggest_delay('%s')", l:ft) augroup END endfor augroup vim_lsp_suggest diff --git a/installer/install-julia-language-server.cmd b/installer/install-julia-language-server.cmd new file mode 100644 index 0000000..d9c32af --- /dev/null +++ b/installer/install-julia-language-server.cmd @@ -0,0 +1,28 @@ +@echo off
+
+julia -e "using Pkg; Pkg.add(PackageSpec(name=\"LanguageServer\", rev=\"master\"))"
+julia -e "using Pkg; Pkg.add(PackageSpec(name=\"SymbolServer\", rev=\"master\"))"
+julia -e "using Pkg; Pkg.add(PackageSpec(name=\"CSTParser\", rev=\"master\"))"
+
+echo ^
+import LanguageServer ^
+
+import Pkg ^
+
+import SymbolServer ^
+
+envpath = dirname(Pkg.Types.Context().env.project_file) ^
+
+server = LanguageServer.LanguageServerInstance(stdin, stdout, false, envpath) ^
+
+server.runlinter = true ^
+
+run(server) ^
+
+> languageserver.jl
+
+echo @echo off ^
+
+julia %%~dp0\languageserver.jl %%* ^
+
+> julia-language-server.cmd
diff --git a/installer/install-julia-language-server.sh b/installer/install-julia-language-server.sh new file mode 100755 index 0000000..13559e1 --- /dev/null +++ b/installer/install-julia-language-server.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -e + +julia -e 'using Pkg; Pkg.add(PackageSpec(name="LanguageServer", rev="master"))' +julia -e 'using Pkg; Pkg.add(PackageSpec(name="SymbolServer", rev="master"))' +julia -e 'using Pkg; Pkg.add(PackageSpec(name="CSTParser", rev="master"))' + +cat <<EOF >languageserver.jl +import LanguageServer +import Pkg +import SymbolServer +envpath = dirname(Pkg.Types.Context().env.project_file) +server = LanguageServer.LanguageServerInstance(stdin, stdout, false, envpath) +server.runlinter = true +run(server) +EOF + +cat <<EOF >julia-language-server +#!/usr/bin/env bash + +DIR=\$(cd \$(dirname \$0); pwd) +julia \$DIR/languageserver.jl \$* +EOF + +chmod +x julia-language-server diff --git a/settings.json b/settings.json index 2dc8a9c..c62470e 100644 --- a/settings.json +++ b/settings.json @@ -275,6 +275,20 @@ } } ], + "julia": [ + { + "command": "julia-language-server", + "requires": [ + "julia" + ], + "vim-plugin": { + "extensions": [ + "jl" + ], + "name": "ajpaulson/julia-syntax.vim" + } + } + ], "kotlin": [ { "command": "kotlin-language-server", diff --git a/settings/julia-language-server.vim b/settings/julia-language-server.vim new file mode 100644 index 0000000..ce07288 --- /dev/null +++ b/settings/julia-language-server.vim @@ -0,0 +1,13 @@ +augroup vimlsp_settings_julia_language_server + au! + LspRegisterServer { + \ 'name': 'julia-language-server', + \ 'cmd': {server_info->lsp_settings#get('julia-language-server', 'cmd', [lsp_settings#exec_path('julia-language-server')])}, + \ 'root_uri':{server_info->lsp_settings#get('julia-language-server', 'root_uri', lsp_settings#root_uri(g:lsp_settings_root_markers))}, + \ 'initialization_options': lsp_settings#get('julia-language-server', 'initialization_options', v:null), + \ 'whitelist': lsp_settings#get('julia-language-server', 'whitelist', ['julia']), + \ 'blacklist': lsp_settings#get('julia-language-server', 'blacklist', []), + \ 'config': lsp_settings#get('julia-language-server', 'config', {}), + \ 'workspace_config': lsp_settings#get('julia-language-server', 'workspace_config', {}), + \ } +augroup END diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index 36db445..904610a 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -88,6 +88,7 @@ Describe lsp_settings It should setup commands and autocmds. call lsp_settings#clear() call lsp_settings#init() + let g:vim_lsp_settings_filetype_no_delays = 1 autocmd vim_lsp_suggest_python Assert exists(':LspInstallServer') delcommand LspInstallServer @@ -99,6 +100,7 @@ Describe lsp_settings exe 'augroup! ' . v endfor bw! + unlet g:vim_lsp_settings_filetype_no_delays End It should setup commands and autocmds with python. @@ -106,6 +108,7 @@ Describe lsp_settings call lsp_settings#init() new let g:lsp_settings = {'pyls': {'cmd': ['foo', 'bar']}} + let g:vim_lsp_settings_filetype_no_delays = 1 Throw /E117/ :setfiletype python bw! for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_suggest"') @@ -115,6 +118,7 @@ Describe lsp_settings exe 'augroup! ' . v endfor unlet g:lsp_settings + unlet g:vim_lsp_settings_filetype_no_delays End End End |