True lazy loading, lsp installs, and nvim-compe

Installation scripts for:
+ bashls
+ ccls
+ clangd
+ pylsp
+ pyright
+ sumneko
+ zls

And adjusted a few keymaps
This commit is contained in:
Just Midi 2021-08-26 07:15:27 +00:00
parent 052b4513c2
commit 4ca63a5884
11 changed files with 337 additions and 105 deletions

View file

@ -276,18 +276,20 @@ map('n', '<leader>p', ':lua pm_sync()<CR>', {noremap = true})
-- LSP
local lsp_commands = {
new = {'<', '>','a','d','D','f','h','n','r','s'},
new = {'h','d','D','r','f','n','i','s','S','<','>','a'},
old = {
'diagnostic.goto_prev', -- <
'diagnostic.goto_next', -- >
'buf.code_action', -- a
'buf.hover', -- h
'buf.definition', -- d
'buf.declaration', -- D
'buf.formatting', -- f
'buf.hover', -- h
'buf.rename', -- n
'buf.references', -- r
'buf.document_symbol' -- s
'buf.formatting', -- f
'buf.rename', -- n
'buf.implementation', -- i
'buf.document_symbol', -- s
'buf.signature_help', -- S
'diagnostic.goto_prev', -- <
'diagnostic.goto_next', -- >
'buf.code_action' -- a
}
}
for i = 1, #lsp_commands.new do

View file

@ -19,102 +19,163 @@
-- v = vim.v -- variables
-- env = vim.env -- environment variables
-- dependent on https://github.com/neovim/nvim-lspconfig
local lspconfig = require 'lspconfig'
lspconfig = require 'lspconfig' -- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
--local lspfuzzy = require 'lspfuzzy'
function lsp_init()
-- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
local lsp_filetype = {
['ada'] = {'als'},
['aspnetcorerazor'] = {'tailwindcss'},
['astro'] = {'tailwindcss'},
['astro-markdown'] = {'tailwindcss'},
['beancount'] = {'beancount'},
['bib'] = {'texlab'},
['bicep'] = {'bicep'},
['blade'] = {'tailwindcss'},
['c'] = {'ccls','clangd','sourcekit'},
['clojure'] = {'clojure_lsp'},
['cmake'] = {'cmake'},
-- = {'config'},
['cpp'] = {'ccls','clangd','sourcekit'},
['crystal'] = {'crystalline','scry'},
['css'] = {'cssls','stylelint_lsp','tailwindcss'},
['d'] = {'serve_d'},
['dart'] = {'dartls'},
['dhall'] = {'dhall_lsp_server'},
['django-html'] = {'tailwindcss'},
['Dockerfile'] = {'dockerls'},
['dockerfile'] = {'dockerls'},
['dot'] = {'dotls'},
-- = {'diagnostics'},
['edge'] = {'tailwindcss'},
['edn'] = {'clojure_lsp'},
['eelixir'] = {'elixirls','tailwindcss'},
-- = {'efm'},
['elixir'] = {'elixirls'},
['elm'] = {'elmls'},
['ejs'] = {'tailwindcss'},
['erb'] = {'tailwindcss'},
['erlang'] = {'erlangls'},
['eruby'] = {'tailwindcss'},
['fortran'] = {'fortls'},
['fsharp'] = {'fsautocomplete'},
['gd'] = {'gdscript'},
['gdscript'] = {'gdscript'},
['gdscript3'] = {'gdscript'},
['genie'] = {'vala_ls'},
['go'] = {'gopls'},
['gohtml'] = {'tailwindcss'},
['gomod'] = {'gopls'},
['graphql'] = {'graphql'},
['groovy'] = {'groovyls'},
['haml'] = {'tailwindcss'},
['handlebars'] = {'ember','tailwindcss'},
['haskell'] = {'ghcide','hie','hls'},
['haxe'] = {'haxe_language_server'},
['hbs'] = {'tailwindcss'},
-- = {'health'},
['help'] = {},
['html'] = {'angular','html','tailwindcss'},
['html-eex'] = {'tailwindcss'},
['jade'] = {'tailwindcss'},
['java'] = {'java_language_server','jdtls'},
['javascript'] = {'denols','ember','flow','rome','stylelint_lsp','tsserver','tailwindcss'},
['javascriptreact'] = {'denols','flow','rome','stylelint_lsp','tsserver','tailwindcss'},
['javascript.jsx'] = {'denols','flow','tsserver'},
['json'] = {'jsonls','rome'},
['julia'] = {'julials'},
['kotlin'] = {'kotlin_language_server'},
['leaf'] = {'tailwindcss'},
['lean'] = {'leanls'},
['lean3'] = {'lean3ls'},
['less'] = {'cssls','stylelint_lsp','tailwindcss'},
['lhaskell'] = {'ghcide','hls'},
-- = {'lspinfo'},
['liquid'] = {'tailwindcss'},
['lua'] = {'sumneko_lua'},
['markdown'] = {'zeta_note','tailwindcss'},
['mdx'] = {'tailwindcss'},
['mint'] = {'mint'},
['mustache'] = {'tailwindcss'},
['mysql'] = {'sqlls','sqls'},
['nim'] = {'nimls'},
['nix'] = {'rnix'},
['njk'] = {'tailwindcss'},
['nunjucks'] = {'tailwindcss'},
['objc'] = {'ccls','clangd'},
['objcpp'] = {'ccls','clangd'},
['objective-c'] = {'sourcekit'},
['objective-cpp'] = {'sourcekit'},
['ocaml'] = {'ocamlls','ocamllsp'},
['ocaml.menhir'] = {'ocamllsp'},
['ocaml.interface'] = {'ocamllsp'},
['ocaml.ocamllex'] = {'ocamllsp'},
['perl'] = {'perlls','perlpls'},
['php'] = {'intelephense','phpactor','tailwindcss'},
['prisma'] = {'prismals'},
['ps1'] = {'powershell_es'},
['puppet'] = {'puppet'},
['purescript'] = {'purescriptls'},
['python'] = {'jedi_language_server','pylsp','pyright'},
['ql'] = {'codeqlls'},
['r'] = {'r_language_server'},
['racket'] = {'racket_langserver'},
['razor'] = {'tailwindcss'},
['reason'] = {'ocamlls','ocamllsp','tailwindcss'},
['rescript'] = {'rescript','tailwindcss'},
['rmd'] = {'r_language_server'},
['ruby'] = {'solargraph','sorbet'},
['rust'] = {'rls','rust_analyzer'},
['sass'] = {'tailwindcss'},
['scala'] = {'metals'},
['scheme'] = {'racket_langserver'},
['scss'] = {'cssls','stylelint_lsp','tailwindcss'},
['sh'] = {'bashls'},
['slim'] = {'tailwindcss'},
['stylus'] = {'tailwindcss'},
['sql'] = {'sqlls','sqls'},
['sugarss'] = {'stylelint_lsp','tailwindcss'},
['svelte'] = {'svelte','tailwindcss'},
['swift'] = {'source'},
['systemverilog'] = {'svls'},
['tex'] = {'texlab'},
['terraform'] = {'tflint','teraformls'},
['twig'] = {'tailwindcss'},
['typescript'] = {'angular', 'denols','ember','rome','stylelint_lsp','tsserver','tailwindcss'},
['typescriptreact'] = {'angular', 'denols','rome','stylelint_lsp','tsserver','tailwindcss'},
['typescript.tsx'] = {'angular', 'denols','rome','tsserver'},
-- = {'util'},
['vala'] = {'vala_ls'},
['verilog'] = {'svls'},
['vim'] = {'vimls'},
['vlang'] = {'vls'},
['vue'] = {'stylelint_lsp','vuels','tailwindcss'},
['wxss'] = {'stylelint_lsp'},
['yaml'] = {'ansiblels','yamlls'},
['zig'] = {'zls'},
['zir'] = {'zls'}
}
-- Uncomment conflicting or not preferred lines
-- lazy loading based on filetype
cmd('autocmd BufEnter *.adb,*.ads lua lspconfig.als.setup {}')
cmd('autocmd BufEnter *.ts,*.html lua lspconfig.angularls.setup {}')
cmd('autocmd BufEnter *.yaml lua lspconfig.ansiblels.setup {}')
cmd('autocmd BufEnter *.sh,*.ash,*.bash,*.bsh lua lspconfig.bashls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.beancount.setup {}')
cmd('autocmd BufEnter *.bicep lua lspconfig.bicep.setup {}')
cmd('autocmd BufEnter *.c,*.h,*.cpp,*.hpp,*.m,*.mm,*.M lua lspconfig.ccls.setup {}')
cmd('autocmd BufEnter *.c,*.h,*.cpp,*.hpp,*.m,*.mm,*.M,*.rs,*.f,*.for,*.f90 lua lspconfig.clangd.setup {}')
cmd('autocmd BufEnter *.clj,*.cljs lua lspconfig.clojure_lsp.setup {}')
cmd('autocmd BufEnter Makefile* lua lspconfig.cmake.setup {}')
cmd('autocmd BufEnter *.ql,*.qll lua lspconfig.codeqlls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.configs.setup {}')
cmd('autocmd BufEnter *.cr lua lspconfig.crystalline.setup {}')
cmd('autocmd BufEnter *.css lua lspconfig.cssls.setup {}')
cmd('autocmd BufEnter *.dart lua lspconfig.dartls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.denols.setup {}')
cmd('autocmd BufEnter *.dhall lua lspconfig.dhall_lsp_server.setup {}')
--cmd('autocmd BufEnter lua lspconfig.diagnosticls.setup {}')
cmd('autocmd BufEnter *.dockerfile lua lspconfig.dockerls.setup {}')
cmd('autocmd BufEnter *.dot,*.gv lua lspconfig.dotls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.efm.setup {}')
cmd('autocmd BufEnter *.ex,*.exs lua lspconfig.elixirls.setup {}')
cmd('autocmd BufEnter *.elm lua lspconfig.elmls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.ember.setup {}')
cmd('autocmd BufEnter *.erl,*hrl lua lspconfig.erlangls.setup {}')
cmd('autocmd BufEnter *.js,*.cjs,*.mjs lua lspconfig.flow.setup {}')
cmd('autocmd BufEnter *.f*.for,*.f90 lua lspconfig.fortls.setup {}')
cmd('autocmd BufEnter *.fs,*.fsi,*.fsx,*.fsscript lua lspconfig.fsautocomplete.setup {}')
cmd('autocmd BufEnter *.gd lua lspconfig.gdscript.setup {}')
cmd('autocmd BufEnter *.hs,*.lhs lua lspconfig.ghcide.setup {}')
cmd('autocmd BufEnter *.go lua lspconfig.gopls.setup {}')
cmd('autocmd BufEnter *.graphql lua lspconfig.graphql.setup {}')
cmd('autocmd BufEnter *.groovy,*.gvy,*.gy,*.gsh lua lspconfig.groovyls.setup {}')
cmd('autocmd BufEnter *.hx,*.hxml lua lspconfig.haxe_language_server.setup {}')
--cmd('autocmd BufEnter lua lspconfig.health.setup {}')
cmd('autocmd BufEnter *.hs,lhs lua lspconfig.hie.setup {}')
cmd('autocmd BufEnter *.hs,*.lhs lua lspconfig.hls.setup {}')
cmd('autocmd BufEnter *.html,*.htm lua lspconfig.html.setup {}')
cmd('autocmd BufEnter *.php,*.phar,*.phtml,*.pht,*.phps lua lspconfig.intelephense.setup {}')
cmd('autocmd BufEnter *.java,*.jar,*.class lua lspconfig.java_language_server.setup {}')
cmd('autocmd BufEnter *.java,*.jar,*.class lua lspconfig.jdtls.setup {}')
cmd('autocmd BufEnter *.py,*.pyi,*.pyc,*pyd lua lspconfig.jedi_language_server.setup {}')
cmd('autocmd BufEnter *.json lua lspconfig.jsonls.setup {}')
cmd('autocmd BufEnter *.jl lua lspconfig.julials.setup {}')
cmd('autocmd BufEnter *.kt,*.kts,*.ktm lua lspconfig.kotlin_language_server.setup {}')
cmd('autocmd BufEnter *.lean lua lspconfig.lean3ls.setup {}')
cmd('autocmd BufEnter *.lean lua lspconfig.leanls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.lspinfo.setup {}')
cmd('autocmd BufEnter *.scala,*.sc lua lspconfig.metals.setup {}')
cmd('autocmd BufEnter *.nim,*.nims,*nimble lua lspconfig.nimls.setup {}')
cmd('autocmd BufEnter *.ml,*.mli,*.re,*rei lua lspconfig.ocamlls.setup {}')
cmd('autocmd BufEnter *.ml,*.mli,*.re,*rei lua lspconfig.ocamllsp.setup {}')
cmd('autocmd BufEnter *.cs,*.csx,*.vb,*.vbs,*.vbe,*.wsf,*.wsc lua lspconfig.omnisharp.setup {}')
cmd('autocmd BufEnter *.plx,*.pl,*.pm,*.xs,*.t lua lspconfig.perlls.setup {}')
cmd('autocmd BufEnter *.plx,*.pl,*.pm,*.xs,*.t lua lspconfig.perlpls.setup {}')
cmd('autocmd BufEnter *.php,*.phar,*.phtml,*.pht,*.phps lua lspconfig.phpactor.setup {}')
cmd('autocmd BufEnter *.ps,*.ps1,*.ps1xml,*.psc1,*.psd1,*.psm1,*.pssc,*.psrc,*.cdxml lua lspconfig.powershell_es.setup {}')
--cmd('autocmd BufEnter lua lspconfig.prismals.setup {}')
cmd('autocmd BufEnter *.pp lua lspconfig.puppet.setup {}')
cmd('autocmd BufEnter *.purs lua lspconfig.purescriptls.setup {}')
cmd('autocmd BufEnter *.py,*.pyi,*.pyc,*pyd lua lspconfig.pylsp.setup {}')
cmd('autocmd BufEnter *.py,*.pyi,*.pyc,*pyd lua lspconfig.pyright.setup {}')
cmd('autocmd BufEnter *.r,*.rdata,*.rds,*.rda,*.rmd lua lspconfig.r_language_server.setup {}')
cmd('autocmd BufEnter *.rkt,*.scm,*.ss lua lspconfig.racket_langserver.setup {}')
cmd('autocmd BufEnter *.re,*rei lua lspconfig.rescriptls.setup {}')
cmd('autocmd BufEnter *.rs,*.rlib lua lspconfig.rls.setup {}')
cmd('autocmd BufEnter *.nix lua lspconfig.rnix.setup {}')
cmd('autocmd BufEnter *.js,*.cjs,*.mjs,*.json,*.ts,*.tsx lua lspconfig.rome.setup {}')
cmd('autocmd BufEnter *.rs,*.rlib lua lspconfig.rust_analyzer.setup {}')
cmd('autocmd BufEnter *.cr lua lspconfig.scry.setup {}')
cmd('autocmd BufEnter *.d lua lspconfig.serve_d.setup {}')
cmd('autocmd BufEnter *.rb lua lspconfig.solargraph.setup {}')
cmd('autocmd BufEnter *.rb lua lspconfig.sorbet.setup {}')
cmd('autocmd BufEnter *.swift,*.SWIFT,*.c,*.h,*.cpp,*.hpp,*.m,*.mm,*.M lua lspconfig.sourcekit.setup {}')
cmd('autocmd BufEnter *.sql lua lspconfig.sqlls.setup {}')
cmd('autocmd BufEnter *.sql lua lspconfig.sqls.setup {}')
cmd('autocmd BufEnter *.css,*.less,*.sass,*.scss,*.sss,**.js,*.cjs,*.mjs,*.ts,*.tsx lua lspconfig.stylelint_lsp.setup {}')
cmd('autocmd BufEnter *.lua lua lspconfig.sumneko_lua.setup {}')
cmd('autocmd BufEnter *.svelte lua lspconfig.svelte.setup {}')
cmd('autocmd BufEnter *.v,*.vh,*.sv,*.svh lua lspconfig.svls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.tailwindcss.setup {}') -- uh... what? https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/tailwindcss.lua#L10
cmd('autocmd BufEnter *.hcl lua lspconfig.terraformls.setup {}')
cmd('autocmd BufEnter *.tex,*.latex,*.bib lua lspconfig.texlab.setup {}')
cmd('autocmd BufEnter *.hcl lua lspconfig.tflint.setup {}')
cmd('autocmd BufEnter *.ts,*.tsx lua lspconfig.tsserver.setup {}')
--cmd('autocmd BufEnter lua lspconfig.util.setup {}')
cmd('autocmd BufEnter *.vala,*.vali,*.gs lua lspconfig.vala_ls.setup {}')
cmd('autocmd BufEnter *.vim lua lspconfig.vimls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.vls.setup {}')
--cmd('autocmd BufEnter lua lspconfig.vuels.setup {}')
cmd('autocmd BufEnter *.yaml lua lspconfig.yamlls.setup {}')
cmd('autocmd BufEnter *.md lua lspconfig.zeta_note.setup {}')
cmd('autocmd BufEnter *.zig,*.zir lua lspconfig.zls.setup {}')
for _,server in pairs(lsp_filetype[bo.filetype]) do
lspconfig[server].setup {}
end
end
function lsp_format()
local function format_file()
if bo.filetype == x then
vim.lsp.formatting_sync(nil, 100)
end
end
for _,file in pairs({'javascript', 'python'}) do
format_file(file)
end
end
cmd('autocmd BufRead * lua lsp_init()')
cmd('autocmd BufWritePre * lua lsp_format()')
require 'nvim-compe.lua'

View file

@ -0,0 +1,95 @@
-- see `:help` for any questions
-- use `&<var>` to show value of vimscript variable
-- API --
-- o = vim.o -- options
-- go = vim.go -- only-global options
-- bo = vim.bo -- buffer local options
-- wo = vim.wo -- window local options
-- cmd = vim.cmd -- vim commands
-- fn = vim.fn -- vim functions
-- opt = vim.opt -- vim option object
-- g = vim.g -- global variables
-- b = vim.b -- buffer local variables
-- w = vim.w -- window local variables
-- t = vim.t -- tab local variables
-- v = vim.v -- variables
-- env = vim.env -- environment variables
-- dependent on https://github.com/hrsh7th/nvim-compe
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = false;
source = {
path = true;
buffer = true;
calc = true;
vsnip = true;
nvim_lsp = true;
nvim_lua = true;
spell = true;
tags = true;
snippets_nvim = true;
treesitter = true;
};
}
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = fn.col('.') - 1
if col == 0 or fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if fn.pumvisible() == 1 then
return t "<C-n>"
elseif fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return t "<Tab>"
else
return fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if fn.pumvisible() == 1 then
return t "<C-p>"
elseif fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
-- If <S-Tab> is not working in your terminal, change it to <C-h>
return t "<S-Tab>"
end
end
map("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map('i', '<cr>', 'compe#confirm("<cr>")', { expr = true })
map('i', '<c-space>', 'compe#complete()', { expr = true })

View file

@ -0,0 +1,8 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'npm'
if response == 'y' then
npm -i -g bash-language-server
fi

View file

@ -0,0 +1,14 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'CMake'
query_dep 'C++17'
query_dep '
if response == 'y' then
cd builds
git clone --depth=1 --recursive https://github.com/MaskRay/ccls
cd ccls
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/path/to/clang+llvm-xxx
cmake --build Release
fi

View file

@ -0,0 +1,4 @@
#!/bin/sh
printf 'Install from clang-tools or similar '
printf 'with your OS or from releases on LLVM site\n'

View file

@ -0,0 +1,8 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'pip'
if response == 'y' then
pip install python-lsp-server
fi

View file

@ -0,0 +1,8 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'npm'
if response == 'y' then
npm -i -g pyright
fi

View file

@ -0,0 +1,17 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'ninja'
query_dep 'C++17'
if $response == 'y' then
mkdir -p builds
cd builds
git clone https://github.com/sumneko/lua-language-server
cd lua-language-server
git submodule update --init --recursive
cd 3rd/luamake
compile/install.sh
cd ../..
./3rd/luamake/luamake rebuild
fi

View file

@ -0,0 +1,8 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep "xz or xz-utils"
if response == 'y' then
mkdir -p builds/zls && cd builds/zls && curl -L https://github.com/zigtools/zls/releases/download/0.1.0/x86_64-linux.tar.xz | tar -xJ --strip-components=1 -C .
fi

View file

@ -0,0 +1,7 @@
function query_dep(){
printf 'Did you install '
printf $1
printf '?\n (y/N)'
response='n'
read response
}