aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2020-01-27 13:07:08 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2020-01-27 13:07:08 +0900
commit1a83260ff247e156ec81ee703bc2fba7db50582a (patch)
tree820f0fd3e61c6971cfe8845b0fc9a4fe2b473b64
parentd83e45e1a1f5b16dab688c9e1e1d4789a46b28bb (diff)
downloadvim-lsp-settings-1a83260ff247e156ec81ee703bc2fba7db50582a.tar.gz
vim-lsp-settings-1a83260ff247e156ec81ee703bc2fba7db50582a.tar.bz2
vim-lsp-settings-1a83260ff247e156ec81ee703bc2fba7db50582a.zip
Add sql-language-server
-rw-r--r--autoload/lsp_settings.vim38
-rw-r--r--installer/install-sql-language-server.cmd3
-rw-r--r--installer/install-sql-language-server.sh5
-rw-r--r--plugin/lsp_settings.vim16
-rw-r--r--settings.json6
-rw-r--r--settings/sql-language-server.vim13
6 files changed, 71 insertions, 10 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim
index fbe3210..51ff952 100644
--- a/autoload/lsp_settings.vim
+++ b/autoload/lsp_settings.vim
@@ -1,4 +1,5 @@
let s:servers_dir = expand('<sfile>:h:h').'/servers'
+let s:installer_dir = expand('<sfile>:h:h').'/installer'
function! lsp_settings#get(name, key, default) abort
let l:config = get(g:, 'lsp_settings', {})
@@ -97,3 +98,40 @@ function! lsp_settings#autocd(server_info) abort
exe 'cd' l:path
endif
endfunction
+
+function! lsp_settings#complete_installer(arglead, cmdline, cursorpos) abort
+ let l:settings = json_decode(join(readfile(expand('<sfile>:h:h').'/settings.json'), "\n"))
+ call remove(l:settings, '$schema')
+
+ let l:ft = tolower(get(split(&filetype, '\.'), 0, ''))
+ if !has_key(l:settings, l:ft)
+ return []
+ endif
+ let l:server = l:settings[l:ft]
+ if empty(l:server)
+ return []
+ endif
+ let l:installers = []
+ for l:conf in l:server
+ let l:missing = 0
+ for l:require in l:conf.requires
+ if !executable(l:require)
+ let l:missing = 1
+ break
+ endif
+ endfor
+ if l:missing !=# 0
+ continue
+ endif
+ let l:command = printf('%s/install-%s', s:installer_dir, l:conf.command)
+ if has('win32')
+ let l:command = substitute(l:command, '/', '\', 'g') . '.cmd'
+ else
+ let l:command = l:command . '.sh'
+ endif
+ if executable(l:command)
+ call add(l:installers, l:conf.command)
+ endif
+ endfor
+ return filter(l:installers, 'stridx(v:val, a:arglead) == 0')
+endfunction
diff --git a/installer/install-sql-language-server.cmd b/installer/install-sql-language-server.cmd
new file mode 100644
index 0000000..95d9a78
--- /dev/null
+++ b/installer/install-sql-language-server.cmd
@@ -0,0 +1,3 @@
+@echo off
+
+call "%~dp0\npm_install.cmd" sql-language-server sql-language-server
diff --git a/installer/install-sql-language-server.sh b/installer/install-sql-language-server.sh
new file mode 100644
index 0000000..e4d3586
--- /dev/null
+++ b/installer/install-sql-language-server.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+set -e
+
+"$(dirname $0)/npm_install.sh" sql-language-server sql-language-server
diff --git a/plugin/lsp_settings.vim b/plugin/lsp_settings.vim
index 70aec73..2fade35 100644
--- a/plugin/lsp_settings.vim
+++ b/plugin/lsp_settings.vim
@@ -50,10 +50,6 @@ function! s:vim_lsp_installer(ft, ...) abort
if empty(l:server)
return []
endif
- let l:name = get(a:000, 0, '')
- if !empty(l:name)
- return filter(copy(l:server), 'l:conf.command ==# l:name')
- endif
let l:found = {}
for l:conf in l:server
let l:missing = 0
@@ -71,12 +67,12 @@ function! s:vim_lsp_installer(ft, ...) abort
if empty(l:found)
return []
endif
+ let l:name = get(a:000, 0, '')
for l:conf in l:server
- let l:command = s:vim_lsp_settings_get(l:conf.command, 'cmd', l:conf.command)
- if type(l:command) == type([])
- let l:command = l:command[0]
+ if !empty(l:name) && l:conf.command != l:name
+ continue
endif
- let l:command = printf('%s/install-%s', s:installer_dir, l:command)
+ let l:command = printf('%s/install-%s', s:installer_dir, l:conf.command)
if has('win32')
let l:command = substitute(l:command, '/', '\', 'g') . '.cmd'
else
@@ -141,7 +137,7 @@ function! s:vim_lsp_settings_suggest(ft) abort
echohl Directory
echomsg 'Please do :LspInstallServer to enable Language Server'
echohl None
- command! -nargs=? -buffer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
+ command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_installer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
endif
endfunction
@@ -263,7 +259,7 @@ function! s:vim_lsp_load_or_suggest(ft) abort
else
doautocmd User lsp_setup
if exists(':LspInstallServer') !=# 2
- command! -nargs=? -buffer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
+ command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_installer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
endif
endif
diff --git a/settings.json b/settings.json
index c374e70..c83cdb1 100644
--- a/settings.json
+++ b/settings.json
@@ -385,6 +385,12 @@
],
"sql": [
{
+ "command": "sql-language-server",
+ "requires": [
+ "npm"
+ ]
+ },
+ {
"command": "sqls",
"requires": [
"go"
diff --git a/settings/sql-language-server.vim b/settings/sql-language-server.vim
new file mode 100644
index 0000000..a82f166
--- /dev/null
+++ b/settings/sql-language-server.vim
@@ -0,0 +1,13 @@
+augroup vimlsp_settings_sql_language_server
+ au!
+ LspRegisterServer {
+ \ 'name': 'sql-language-server',
+ \ 'cmd': {server_info->lsp_settings#get('sql-language-server', 'cmd', [lsp_settings#exec_path('sql-language-server'), 'up', '--method', 'stdio'])},
+ \ 'root_uri':{server_info->lsp_settings#get('sql-language-server', 'root_uri', lsp_settings#root_uri(g:lsp_settings_root_markers))},
+ \ 'initialization_options': lsp_settings#get('sql-language-server', 'initialization_options', v:null),
+ \ 'whitelist': lsp_settings#get('sql-language-server', 'whitelist', ['sql']),
+ \ 'blacklist': lsp_settings#get('sql-language-server', 'blacklist', []),
+ \ 'config': lsp_settings#get('sql-language-server', 'config', {}),
+ \ 'workspace_config': lsp_settings#get('sql-language-server', 'workspace_config', {}),
+ \ }
+augroup END