I broke up with neovim....vim is my best friend now

This commit is contained in:
LinlyBoi
2023-04-30 08:14:07 +03:00
parent 0d185449c5
commit 4a4a6b1e81
5245 changed files with 468325 additions and 25 deletions

View File

@@ -0,0 +1,120 @@
function! s:filter_deny_keys(settings) abort
let l:deny_keys = get(g:, 'lsp_settings_deny_local_keys', ['cmd'])
if empty(l:deny_keys)
return
endif
for l:setting in values(a:settings)
if v:t_dict !=# type(l:setting)
continue
endif
for l:v in values(l:setting)
if v:t_dict !=# type(l:v)
continue
endif
for l:deny in l:deny_keys
if has_key(l:v, l:deny)
call remove(l:v, l:deny)
endif
endfor
endfor
endfor
endfunction
function! lsp_settings#profile#load_local() abort
try
let l:dir = expand('%:p:h')
let l:root = finddir('.vim-lsp-settings', l:dir . ';')
if empty(l:root)
return
endif
if !filereadable(l:root . '/settings.json')
return
endif
let l:settings = json_decode(join(readfile(l:root . '/settings.json'), "\n"))
call s:filter_deny_keys(l:settings)
if has_key(g:, 'lsp_settings')
for [l:k, l:v] in items(l:settings)
if has_key(g:lsp_settings, l:k)
let g:lsp_settings[l:k] = lsp_settings#utils#extend(g:lsp_settings[l:k], l:v)
else
let g:lsp_settings[l:k] = l:v
endif
endfor
else
let g:lsp_settings = l:settings
endif
catch
endtry
endfunction
function! lsp_settings#profile#edit_global() abort
let l:root = lsp_settings#global_settings_dir()
if !isdirectory(l:root)
call mkdir(l:root)
endif
exe 'new' l:root . '/settings.json'
if !filereadable(l:root . '/settings.json')
call setline(1, ['{', "\t", '}'])
call cursor([2, 2])
setlocal nomodified
endif
endfunction
function! lsp_settings#profile#edit_local(...) abort
let l:root = ''
if a:0 >= 1
let l:root = a:1
endif
if l:root ==# ''
let l:root = lsp_settings#root_path(['.vim-lsp-settings'])
endif
if empty(l:root)
let l:root = getcwd()
endif
if !isdirectory(l:root)
return
endif
let l:root .= '/.vim-lsp-settings'
if !isdirectory(l:root)
call mkdir(l:root)
endif
exe 'new' l:root . '/settings.json'
if !filereadable(l:root . '/settings.json')
call setline(1, ['{', "\t", '}'])
call cursor([2, 2])
setlocal nomodified
endif
endfunction
let s:color_map = {
\ 'exited': 'Error',
\ 'starting': 'MoreMsg',
\ 'failed': 'WarningMsg',
\ 'running': 'Keyword',
\ 'not running': 'NonText'
\}
function! lsp_settings#profile#status() abort
let l:settings = lsp_settings#settings()
let l:active_servers = lsp#get_allowed_servers()
let l:servers = []
for l:ft in keys(l:settings)
for l:v in l:settings[l:ft]
if index(l:servers, l:v.command) ==# -1
call add(l:servers, l:v.command)
endif
endfor
endfor
for l:server in uniq(sort(l:servers))
if index(l:active_servers, l:server) != -1
let l:status = lsp#get_server_status(l:server)
echon l:server . ': '
exec 'echohl' s:color_map[l:status]
echon l:status
echohl None
endif
echo ''
endfor
endfunction

View File

@@ -0,0 +1,107 @@
function! s:install_or_update() abort
let l:line = getline('.')
let l:token = matchlist(getline('.'), '\[.\] \(\S\+\)\s\+(\([^)]\+\))')
let l:command = l:token[1]
let l:languages = split(l:token[2], ',\s*')
if empty(l:command)
return
endif
if confirm('Install ' . l:command . ' ?', "&OK\n&Cancel") ==# 2
return
endif
bw!
call lsp_settings#install_server(l:languages[0], l:command)
endfunction
function! s:open() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command)
return
endif
let l:settings = lsp_settings#settings()
for l:ft in sort(keys(l:settings))
for l:conf in l:settings[l:ft]
if l:conf.command ==# l:command
let l:cmd = ''
if !lsp_settings#utils#open_url(l:conf.url)
return
endif
break
endif
endfor
endfor
endfunction
function! s:help() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command)
return
endif
let l:settings = lsp_settings#settings()
for l:ft in sort(keys(l:settings))
for l:conf in l:settings[l:ft]
if l:conf.command ==# l:command
echomsg l:conf.url
echomsg l:conf.description
return
endif
endfor
endfor
endfunction
function! s:uninstall() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command)
return
endif
if confirm('Uninstall ' . l:command . ' ?', "&OK\n&Cancel") ==# 2
return
endif
bw!
exe 'LspUninstallServer' l:command
endfunction
function! lsp_settings#ui#open() abort
silent new __LSP_SETTINGS__
only!
setlocal buftype=nofile bufhidden=wipe noswapfile cursorline
silent! %d _
let l:names = []
let l:types = {}
let l:installer_dir = lsp_settings#installer_dir()
let l:settings = lsp_settings#settings()
for l:ft in sort(keys(l:settings))
for l:conf in l:settings[l:ft]
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
call add(l:names, l:conf.command)
if !has_key(l:types, l:conf.command)
let l:types[l:conf.command] = [l:ft]
else
call add(l:types[l:conf.command], l:ft)
endif
endfor
endfor
let l:names = uniq(sort(l:names))
call map(l:names, {_, v -> printf('%s %s (%s)', lsp_settings#executable(v) ? '[*]' : '[ ]', v, join(l:types[v], ', '))})
cal setline(1, l:names)
setlocal nomodifiable nomodified
nnoremap <buffer> i :call <SID>install_or_update()<cr>
nnoremap <buffer> x :call <SID>uninstall()<cr>
nnoremap <buffer> b :call <SID>open()<cr>
nnoremap <buffer> ? :call <SID>help()<cr>
nnoremap <buffer> q :bw<cr>
redraw
echomsg 'Type i to install, or x to uninstall, b to open browser, ? to show description'
endfunction

View File

@@ -0,0 +1,187 @@
function! lsp_settings#utils#msg(msg, ...) abort
redraw
echohl Comment
echo a:msg
echohl None
return a:0 > 0 ? a:000[0] : v:null
endfunction
function! lsp_settings#utils#warning(msg, ...) abort
redraw
echohl WarningMsg
echomsg a:msg
echohl None
return a:0 > 0 ? a:000[0] : v:null
endfunction
function! lsp_settings#utils#error(msg, ...) abort
redraw
echohl Error
echomsg a:msg
echohl None
return a:0 > 0 ? a:000[0] : v:null
endfunction
function! lsp_settings#utils#valid_name(command) abort
return a:command =~# '^[a-zA-Z0-9_-]\+$'
endfunction
function! lsp_settings#utils#group_name(ft) abort
return printf('vim_lsp_suggest_%s', a:ft)
endfunction
function! lsp_settings#utils#first_one(lines) abort
if empty(a:lines)
return ''
endif
let l:path = fnamemodify(split(a:lines, "\n")[0], ':p')
if has('win32')
let l:path = substitute(l:path, '/', '\', 'g')
endif
return l:path
endfunction
function! lsp_settings#utils#dotmerge(d) abort
let l:ret = {}
let l:keys = keys(a:d)
for l:k in sort(keys(a:d))
let l:new = {}
let l:cur = l:new
let l:arr = split(l:k, '\.')
for l:i in range(len(l:arr))
let l:kk = l:arr[l:i]
if type(l:cur) == v:t_dict && !has_key(l:cur, l:kk)
if l:i == len(l:arr) - 1
let l:cur[l:kk] = a:d[l:k]
break
else
let l:cur[l:kk] = {}
endif
endif
let l:cur = l:cur[l:kk]
endfor
let l:ret = extend(l:ret, l:new)
endfor
return l:ret
endfunction
let s:catalog_path = expand('<sfile>:h:h:h') . '/data/catalog.json'
function! lsp_settings#utils#load_schemas(name) abort
let l:schemas = json_decode(join(readfile(s:catalog_path), "\n"))['schemas']
return extend(l:schemas, lsp_settings#get(a:name, 'schemas', []))
endfunction
function! lsp_settings#utils#load_schemas_map(name) abort
let l:schemas = json_decode(join(readfile(s:catalog_path), "\n"))['schemas']
let l:result = {}
for l:v in extend(l:schemas, lsp_settings#get(a:name, 'schemas', []))
if has_key(l:v, 'fileMatch')
let l:result[l:v['url']] = l:v['fileMatch']
endif
endfor
return l:result
endfunction
function! lsp_settings#utils#term_start(cmd, options) abort
let l:options = {}
if has_key(a:options, 'cwd')
let l:options['cwd'] = a:options['cwd']
endif
if has('nvim')
split new
call termopen(a:cmd, l:options)
else
call term_start(a:cmd, l:options)
endif
endfunction
function! s:add(lhs, rhs) abort
for l:V in a:rhs
if index(a:lhs, l:V) == -1
call add(a:lhs, l:V)
endif
endfor
return a:rhs
endfunction
function! s:extend(lhs, rhs) abort
let [l:lhs, l:rhs] = [a:lhs, a:rhs]
if type(l:lhs) ==# 3
if type(l:rhs) ==# 3
" [1,2,3]+[4,5,6]=[1,2,3,4,5,6]
call s:add(l:lhs, l:rhs)
elseif type(l:rhs) ==# 4
" [1,2,3]+{'a':1,'b':2}= [1,2,3,{'a':1},{'b':2}]
call s:add(l:lhs, map(keys(l:rhs), '{v:val : l:rhs[v:val]}'))
endif
elseif type(l:lhs) ==# 4
if type(l:rhs) ==# 3
" {'a':1,'b':2}+[{'c':3},{'d':4},5]= {'a':1,'b':2,'c':3,'d':4}
for l:V in l:rhs
if type(l:V) != 4
continue
endif
for l:k in keys(l:V)
let l:lhs[l:k] = l:V[l:k]
endfor
endfor
elseif type(l:rhs) ==# 4
" {'a':1,'b':2}+{'c':3,'d':4}= {'a':1,'b':2,'c':3,'d':4}
for l:key in keys(l:rhs)
if type(l:rhs[l:key]) ==# 3
" {'a':1,'b':2}+{'c':[1]}={'a':1,'b':2,'c':[1]}
if !has_key(l:lhs, l:key)
let l:lhs[l:key] = []
endif
if type(l:lhs[l:key]) == 3
" {'a':[1],'b':2}+{'a':[2]}={'a':[1,2],'b':2}
call s:add(l:lhs[l:key], l:rhs[l:key])
elseif type(l:lhs[l:key]) == 4
" {'a':{'aa':1},'b':2}+{'a':[2]}={'a':[2],'b':2}
for l:k in keys(l:rhs[l:key])
let l:lhs[l:key][l:k] = l:rhs[l:key][l:k]
endfor
endif
elseif type(l:rhs[l:key]) ==# 4
" {'a':{'aa':1},'b':2}+{'a':{'ab':2]}={'a':{'aa':1,'ab':2},'b':2}
if has_key(l:lhs, l:key)
call s:extend(l:lhs[l:key], l:rhs[l:key])
else
let l:lhs[l:key] = l:rhs[l:key]
endif
else
" {'a':{'aa':1},'b':2}+{'a':1}={'a':1,'b':2}
let l:lhs[l:key] = l:rhs[l:key]
endif
endfor
endif
endif
return l:lhs
endfunction
function! lsp_settings#utils#extend(lhs, rhs) abort
return s:extend(a:lhs, a:rhs)
endfunction
function! lsp_settings#utils#shellescape(path) abort
let l:quote = &shellxquote ==# '"' ? "'" : '"'
return l:quote . a:path . l:quote
endfunction
function! lsp_settings#utils#open_url(url) abort
if exists('g:loaded_openbrowser') && g:loaded_openbrowser
call openbrowser#open(a:url)
elseif has('win32') || has('win64')
silent! exec printf('!start rundll32 url.dll,FileProtocolHandler %s', a:url)
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
call system(printf('open "%s"', a:url))
elseif executable('xdg-open')
call system(printf('xdg-open "%s"', a:url))
elseif executable('firefox')
call system(printf('firefox "%s"', a:url))
else
return v:false
endif
return v:true
endfunction