mirror of
https://github.com/mattn/vim-lsp-settings.git
synced 2025-12-12 20:35:54 +01:00
Add sql-language-server
This commit is contained in:
@@ -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
|
||||
|
||||
3
installer/install-sql-language-server.cmd
Normal file
3
installer/install-sql-language-server.cmd
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
|
||||
call "%~dp0\npm_install.cmd" sql-language-server sql-language-server
|
||||
5
installer/install-sql-language-server.sh
Normal file
5
installer/install-sql-language-server.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
"$(dirname $0)/npm_install.sh" sql-language-server sql-language-server
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -384,6 +384,12 @@
|
||||
}
|
||||
],
|
||||
"sql": [
|
||||
{
|
||||
"command": "sql-language-server",
|
||||
"requires": [
|
||||
"npm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"command": "sqls",
|
||||
"requires": [
|
||||
|
||||
13
settings/sql-language-server.vim
Normal file
13
settings/sql-language-server.vim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user