From 052b4513c25a1e4f28841e3e22ac01c8a820e711 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Wed, 11 Aug 2021 20:52:37 +0000 Subject: [PATCH 1/7] Base LSP + loads LSP server based on file type + imports native-lsp (our's) and lspconfig (foreign) + key mappings for lsp --- init.lua | 3 +- lua/keymap/init.lua | 41 +++++++------- lua/native-lsp/init.lua | 120 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 lua/native-lsp/init.lua diff --git a/init.lua b/init.lua index e74f054..a968659 100755 --- a/init.lua +++ b/init.lua @@ -22,7 +22,8 @@ env = vim.env -- environment variables local modules = { 'general', 'keymap', - 'ui' + 'ui', + 'native-lsp' } local async diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index d40a57b..55e86af 100755 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -275,27 +275,26 @@ end map('n', 'p', ':lua pm_sync()', {noremap = true}) -- LSP -function lsp_shortcuts() - local lsp_commands = { - new = {'d','r','f','t','x','a','c','C','h','s','m'}, - old = { - '#textDocument_definition', -- d - '#textDocument_rename', -- r - '#textDocument_formatting', -- f - '#textDocument_typeDefinition', -- t - '#textDocument_references', -- x - '_workspace_applyEdit', -- a - '#textDocument_completion', -- c - '#textDocument_codeAction', -- C - '#textDocument_hover', -- h - '_textDocument_documentSymbol', -- s - '_contextMenu' -- m - } +local lsp_commands = { + new = {'<', '>','a','d','D','f','h','n','r','s'}, + old = { + 'diagnostic.goto_prev', -- < + 'diagnostic.goto_next', -- > + 'buf.code_action', -- a + 'buf.definition', -- d + 'buf.declaration', -- D + 'buf.formatting', -- f + 'buf.hover', -- h + 'buf.rename', -- n + 'buf.references', -- r + 'buf.document_symbol' -- s } - for i = 1, #lspcommands.new do - for _,f in pairs(modes_map({'n'})) do - f('l'..key_pair.new[i], - ':call LanguageClient'..key_pair.old[i]..'()', {noremap = true}) - end +} +for i = 1, #lsp_commands.new do + for _,f in pairs(modes_map({'n'})) do + f('l'..lsp_commands.new[i], + 'lua vim.lsp.'..lsp_commands.old[i]..'()', + {noremap = true} + ) end end diff --git a/lua/native-lsp/init.lua b/lua/native-lsp/init.lua new file mode 100644 index 0000000..0166d6c --- /dev/null +++ b/lua/native-lsp/init.lua @@ -0,0 +1,120 @@ +-- see `:help` for any questions +-- use `&` 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 + + +lspconfig = require 'lspconfig' -- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md +--local lspfuzzy = require 'lspfuzzy' + +-- 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 {}') From 4ca63a5884daa0b61cb7c8aa37247a7501be10d6 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Thu, 26 Aug 2021 07:15:27 +0000 Subject: [PATCH 2/7] True lazy loading, lsp installs, and nvim-compe Installation scripts for: + bashls + ccls + clangd + pylsp + pyright + sumneko + zls And adjusted a few keymaps --- lua/keymap/init.lua | 18 ++- lua/native-lsp/init.lua | 255 ++++++++++++++++++------------ lua/native-lsp/nvim-compe.lua | 95 +++++++++++ scripts/install_bashls_server.sh | 8 + scripts/install_ccls_server.sh | 14 ++ scripts/install_clangd_server.sh | 4 + scripts/install_pylsp_server.sh | 8 + scripts/install_pyright_server.sh | 8 + scripts/install_sumneko_lua.sh | 17 ++ scripts/install_zls_server.sh | 8 + scripts/query_dependency.sh | 7 + 11 files changed, 337 insertions(+), 105 deletions(-) create mode 100644 lua/native-lsp/nvim-compe.lua create mode 100644 scripts/install_bashls_server.sh create mode 100644 scripts/install_ccls_server.sh create mode 100644 scripts/install_clangd_server.sh create mode 100644 scripts/install_pylsp_server.sh create mode 100644 scripts/install_pyright_server.sh create mode 100644 scripts/install_sumneko_lua.sh create mode 100644 scripts/install_zls_server.sh create mode 100644 scripts/query_dependency.sh diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index 55e86af..568b57d 100755 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -276,18 +276,20 @@ map('n', 'p', ':lua pm_sync()', {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 diff --git a/lua/native-lsp/init.lua b/lua/native-lsp/init.lua index 0166d6c..71912b3 100644 --- a/lua/native-lsp/init.lua +++ b/lua/native-lsp/init.lua @@ -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' diff --git a/lua/native-lsp/nvim-compe.lua b/lua/native-lsp/nvim-compe.lua new file mode 100644 index 0000000..72b5926 --- /dev/null +++ b/lua/native-lsp/nvim-compe.lua @@ -0,0 +1,95 @@ +-- see `:help` for any questions +-- use `&` 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 "" + elseif fn.call("vsnip#available", {1}) == 1 then + return t "(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "" + else + return fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if fn.pumvisible() == 1 then + return t "" + elseif fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + -- If is not working in your terminal, change it to + return t "" + end +end + +map("i", "", "v:lua.tab_complete()", {expr = true}) +map("s", "", "v:lua.tab_complete()", {expr = true}) +map("i", "", "v:lua.s_tab_complete()", {expr = true}) +map("s", "", "v:lua.s_tab_complete()", {expr = true}) + +map('i', '', 'compe#confirm("")', { expr = true }) +map('i', '', 'compe#complete()', { expr = true }) diff --git a/scripts/install_bashls_server.sh b/scripts/install_bashls_server.sh new file mode 100644 index 0000000..fab818a --- /dev/null +++ b/scripts/install_bashls_server.sh @@ -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 diff --git a/scripts/install_ccls_server.sh b/scripts/install_ccls_server.sh new file mode 100644 index 0000000..5f0056b --- /dev/null +++ b/scripts/install_ccls_server.sh @@ -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 diff --git a/scripts/install_clangd_server.sh b/scripts/install_clangd_server.sh new file mode 100644 index 0000000..0e5e707 --- /dev/null +++ b/scripts/install_clangd_server.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +printf 'Install from clang-tools or similar ' +printf 'with your OS or from releases on LLVM site\n' diff --git a/scripts/install_pylsp_server.sh b/scripts/install_pylsp_server.sh new file mode 100644 index 0000000..9f2ada2 --- /dev/null +++ b/scripts/install_pylsp_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'pip' + +if response == 'y' then + pip install python-lsp-server +fi diff --git a/scripts/install_pyright_server.sh b/scripts/install_pyright_server.sh new file mode 100644 index 0000000..383039b --- /dev/null +++ b/scripts/install_pyright_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'npm' + +if response == 'y' then + npm -i -g pyright +fi diff --git a/scripts/install_sumneko_lua.sh b/scripts/install_sumneko_lua.sh new file mode 100644 index 0000000..cd5b854 --- /dev/null +++ b/scripts/install_sumneko_lua.sh @@ -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 diff --git a/scripts/install_zls_server.sh b/scripts/install_zls_server.sh new file mode 100644 index 0000000..f39bb7e --- /dev/null +++ b/scripts/install_zls_server.sh @@ -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 diff --git a/scripts/query_dependency.sh b/scripts/query_dependency.sh new file mode 100644 index 0000000..1cef7d5 --- /dev/null +++ b/scripts/query_dependency.sh @@ -0,0 +1,7 @@ +function query_dep(){ + printf 'Did you install ' + printf $1 + printf '?\n (y/N)' + response='n' + read response +} From 6179a86a754f143e71a895b82f74c62ad4d29964 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Fri, 27 Aug 2021 06:18:00 +0000 Subject: [PATCH 3/7] Removed && in zls install removed && in favor of scripts on separate lines --- scripts/install_zls_server.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install_zls_server.sh b/scripts/install_zls_server.sh index f39bb7e..f8fbd3d 100644 --- a/scripts/install_zls_server.sh +++ b/scripts/install_zls_server.sh @@ -4,5 +4,7 @@ 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 . + 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 From 2f1202a6691e244524d682c52b293c47a82ad947 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Fri, 27 Aug 2021 06:21:53 +0000 Subject: [PATCH 4/7] Squashed commit of the following: commit 6179a86a754f143e71a895b82f74c62ad4d29964 Author: Just Midi Date: Fri Aug 27 06:18:00 2021 +0000 Removed && in zls install removed && in favor of scripts on separate lines commit 4ca63a5884daa0b61cb7c8aa37247a7501be10d6 Author: Just Midi Date: Thu Aug 26 07:15:27 2021 +0000 True lazy loading, lsp installs, and nvim-compe Installation scripts for: + bashls + ccls + clangd + pylsp + pyright + sumneko + zls And adjusted a few keymaps commit 052b4513c25a1e4f28841e3e22ac01c8a820e711 Author: Just Midi Date: Wed Aug 11 20:52:37 2021 +0000 Base LSP + loads LSP server based on file type + imports native-lsp (our's) and lspconfig (foreign) + key mappings for lsp --- init.lua | 3 +- lua/keymap/init.lua | 43 +++---- lua/native-lsp/init.lua | 181 ++++++++++++++++++++++++++++++ lua/native-lsp/nvim-compe.lua | 95 ++++++++++++++++ scripts/install_bashls_server.sh | 8 ++ scripts/install_ccls_server.sh | 14 +++ scripts/install_clangd_server.sh | 4 + scripts/install_pylsp_server.sh | 8 ++ scripts/install_pyright_server.sh | 8 ++ scripts/install_sumneko_lua.sh | 17 +++ scripts/install_zls_server.sh | 10 ++ scripts/query_dependency.sh | 7 ++ 12 files changed, 376 insertions(+), 22 deletions(-) create mode 100644 lua/native-lsp/init.lua create mode 100644 lua/native-lsp/nvim-compe.lua create mode 100644 scripts/install_bashls_server.sh create mode 100644 scripts/install_ccls_server.sh create mode 100644 scripts/install_clangd_server.sh create mode 100644 scripts/install_pylsp_server.sh create mode 100644 scripts/install_pyright_server.sh create mode 100644 scripts/install_sumneko_lua.sh create mode 100644 scripts/install_zls_server.sh create mode 100644 scripts/query_dependency.sh diff --git a/init.lua b/init.lua index e74f054..a968659 100755 --- a/init.lua +++ b/init.lua @@ -22,7 +22,8 @@ env = vim.env -- environment variables local modules = { 'general', 'keymap', - 'ui' + 'ui', + 'native-lsp' } local async diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index d40a57b..568b57d 100755 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -275,27 +275,28 @@ end map('n', 'p', ':lua pm_sync()', {noremap = true}) -- LSP -function lsp_shortcuts() - local lsp_commands = { - new = {'d','r','f','t','x','a','c','C','h','s','m'}, - old = { - '#textDocument_definition', -- d - '#textDocument_rename', -- r - '#textDocument_formatting', -- f - '#textDocument_typeDefinition', -- t - '#textDocument_references', -- x - '_workspace_applyEdit', -- a - '#textDocument_completion', -- c - '#textDocument_codeAction', -- C - '#textDocument_hover', -- h - '_textDocument_documentSymbol', -- s - '_contextMenu' -- m - } +local lsp_commands = { + new = {'h','d','D','r','f','n','i','s','S','<','>','a'}, + old = { + 'buf.hover', -- h + 'buf.definition', -- d + 'buf.declaration', -- D + 'buf.references', -- r + '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, #lspcommands.new do - for _,f in pairs(modes_map({'n'})) do - f('l'..key_pair.new[i], - ':call LanguageClient'..key_pair.old[i]..'()', {noremap = true}) - end +} +for i = 1, #lsp_commands.new do + for _,f in pairs(modes_map({'n'})) do + f('l'..lsp_commands.new[i], + 'lua vim.lsp.'..lsp_commands.old[i]..'()', + {noremap = true} + ) end end diff --git a/lua/native-lsp/init.lua b/lua/native-lsp/init.lua new file mode 100644 index 0000000..71912b3 --- /dev/null +++ b/lua/native-lsp/init.lua @@ -0,0 +1,181 @@ +-- see `:help` for any questions +-- use `&` 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/neovim/nvim-lspconfig +local lspconfig = require 'lspconfig' + +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'} + } + + 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' diff --git a/lua/native-lsp/nvim-compe.lua b/lua/native-lsp/nvim-compe.lua new file mode 100644 index 0000000..72b5926 --- /dev/null +++ b/lua/native-lsp/nvim-compe.lua @@ -0,0 +1,95 @@ +-- see `:help` for any questions +-- use `&` 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 "" + elseif fn.call("vsnip#available", {1}) == 1 then + return t "(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "" + else + return fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if fn.pumvisible() == 1 then + return t "" + elseif fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + -- If is not working in your terminal, change it to + return t "" + end +end + +map("i", "", "v:lua.tab_complete()", {expr = true}) +map("s", "", "v:lua.tab_complete()", {expr = true}) +map("i", "", "v:lua.s_tab_complete()", {expr = true}) +map("s", "", "v:lua.s_tab_complete()", {expr = true}) + +map('i', '', 'compe#confirm("")', { expr = true }) +map('i', '', 'compe#complete()', { expr = true }) diff --git a/scripts/install_bashls_server.sh b/scripts/install_bashls_server.sh new file mode 100644 index 0000000..fab818a --- /dev/null +++ b/scripts/install_bashls_server.sh @@ -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 diff --git a/scripts/install_ccls_server.sh b/scripts/install_ccls_server.sh new file mode 100644 index 0000000..5f0056b --- /dev/null +++ b/scripts/install_ccls_server.sh @@ -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 diff --git a/scripts/install_clangd_server.sh b/scripts/install_clangd_server.sh new file mode 100644 index 0000000..0e5e707 --- /dev/null +++ b/scripts/install_clangd_server.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +printf 'Install from clang-tools or similar ' +printf 'with your OS or from releases on LLVM site\n' diff --git a/scripts/install_pylsp_server.sh b/scripts/install_pylsp_server.sh new file mode 100644 index 0000000..9f2ada2 --- /dev/null +++ b/scripts/install_pylsp_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'pip' + +if response == 'y' then + pip install python-lsp-server +fi diff --git a/scripts/install_pyright_server.sh b/scripts/install_pyright_server.sh new file mode 100644 index 0000000..383039b --- /dev/null +++ b/scripts/install_pyright_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'npm' + +if response == 'y' then + npm -i -g pyright +fi diff --git a/scripts/install_sumneko_lua.sh b/scripts/install_sumneko_lua.sh new file mode 100644 index 0000000..cd5b854 --- /dev/null +++ b/scripts/install_sumneko_lua.sh @@ -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 diff --git a/scripts/install_zls_server.sh b/scripts/install_zls_server.sh new file mode 100644 index 0000000..f8fbd3d --- /dev/null +++ b/scripts/install_zls_server.sh @@ -0,0 +1,10 @@ +#!/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 diff --git a/scripts/query_dependency.sh b/scripts/query_dependency.sh new file mode 100644 index 0000000..1cef7d5 --- /dev/null +++ b/scripts/query_dependency.sh @@ -0,0 +1,7 @@ +function query_dep(){ + printf 'Did you install ' + printf $1 + printf '?\n (y/N)' + response='n' + read response +} From ce9bd490eecdfd74fa6933faf26fc51b518f15d6 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Fri, 27 Aug 2021 06:21:53 +0000 Subject: [PATCH 5/7] Squash and merged lsp branch Squashed commit of the following: commit 6179a86a754f143e71a895b82f74c62ad4d29964 Author: Just Midi Date: Fri Aug 27 06:18:00 2021 +0000 Removed && in zls install removed && in favor of scripts on separate lines commit 4ca63a5884daa0b61cb7c8aa37247a7501be10d6 Author: Just Midi Date: Thu Aug 26 07:15:27 2021 +0000 True lazy loading, lsp installs, and nvim-compe Installation scripts for: + bashls + ccls + clangd + pylsp + pyright + sumneko + zls And adjusted a few keymaps commit 052b4513c25a1e4f28841e3e22ac01c8a820e711 Author: Just Midi Date: Wed Aug 11 20:52:37 2021 +0000 Base LSP + loads LSP server based on file type + imports native-lsp (our's) and lspconfig (foreign) + key mappings for lsp --- init.lua | 3 +- lua/keymap/init.lua | 43 +++---- lua/native-lsp/init.lua | 181 ++++++++++++++++++++++++++++++ lua/native-lsp/nvim-compe.lua | 95 ++++++++++++++++ scripts/install_bashls_server.sh | 8 ++ scripts/install_ccls_server.sh | 14 +++ scripts/install_clangd_server.sh | 4 + scripts/install_pylsp_server.sh | 8 ++ scripts/install_pyright_server.sh | 8 ++ scripts/install_sumneko_lua.sh | 17 +++ scripts/install_zls_server.sh | 10 ++ scripts/query_dependency.sh | 7 ++ 12 files changed, 376 insertions(+), 22 deletions(-) create mode 100644 lua/native-lsp/init.lua create mode 100644 lua/native-lsp/nvim-compe.lua create mode 100644 scripts/install_bashls_server.sh create mode 100644 scripts/install_ccls_server.sh create mode 100644 scripts/install_clangd_server.sh create mode 100644 scripts/install_pylsp_server.sh create mode 100644 scripts/install_pyright_server.sh create mode 100644 scripts/install_sumneko_lua.sh create mode 100644 scripts/install_zls_server.sh create mode 100644 scripts/query_dependency.sh diff --git a/init.lua b/init.lua index e74f054..a968659 100755 --- a/init.lua +++ b/init.lua @@ -22,7 +22,8 @@ env = vim.env -- environment variables local modules = { 'general', 'keymap', - 'ui' + 'ui', + 'native-lsp' } local async diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index d40a57b..568b57d 100755 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -275,27 +275,28 @@ end map('n', 'p', ':lua pm_sync()', {noremap = true}) -- LSP -function lsp_shortcuts() - local lsp_commands = { - new = {'d','r','f','t','x','a','c','C','h','s','m'}, - old = { - '#textDocument_definition', -- d - '#textDocument_rename', -- r - '#textDocument_formatting', -- f - '#textDocument_typeDefinition', -- t - '#textDocument_references', -- x - '_workspace_applyEdit', -- a - '#textDocument_completion', -- c - '#textDocument_codeAction', -- C - '#textDocument_hover', -- h - '_textDocument_documentSymbol', -- s - '_contextMenu' -- m - } +local lsp_commands = { + new = {'h','d','D','r','f','n','i','s','S','<','>','a'}, + old = { + 'buf.hover', -- h + 'buf.definition', -- d + 'buf.declaration', -- D + 'buf.references', -- r + '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, #lspcommands.new do - for _,f in pairs(modes_map({'n'})) do - f('l'..key_pair.new[i], - ':call LanguageClient'..key_pair.old[i]..'()', {noremap = true}) - end +} +for i = 1, #lsp_commands.new do + for _,f in pairs(modes_map({'n'})) do + f('l'..lsp_commands.new[i], + 'lua vim.lsp.'..lsp_commands.old[i]..'()', + {noremap = true} + ) end end diff --git a/lua/native-lsp/init.lua b/lua/native-lsp/init.lua new file mode 100644 index 0000000..71912b3 --- /dev/null +++ b/lua/native-lsp/init.lua @@ -0,0 +1,181 @@ +-- see `:help` for any questions +-- use `&` 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/neovim/nvim-lspconfig +local lspconfig = require 'lspconfig' + +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'} + } + + 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' diff --git a/lua/native-lsp/nvim-compe.lua b/lua/native-lsp/nvim-compe.lua new file mode 100644 index 0000000..72b5926 --- /dev/null +++ b/lua/native-lsp/nvim-compe.lua @@ -0,0 +1,95 @@ +-- see `:help` for any questions +-- use `&` 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 "" + elseif fn.call("vsnip#available", {1}) == 1 then + return t "(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "" + else + return fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if fn.pumvisible() == 1 then + return t "" + elseif fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + -- If is not working in your terminal, change it to + return t "" + end +end + +map("i", "", "v:lua.tab_complete()", {expr = true}) +map("s", "", "v:lua.tab_complete()", {expr = true}) +map("i", "", "v:lua.s_tab_complete()", {expr = true}) +map("s", "", "v:lua.s_tab_complete()", {expr = true}) + +map('i', '', 'compe#confirm("")', { expr = true }) +map('i', '', 'compe#complete()', { expr = true }) diff --git a/scripts/install_bashls_server.sh b/scripts/install_bashls_server.sh new file mode 100644 index 0000000..fab818a --- /dev/null +++ b/scripts/install_bashls_server.sh @@ -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 diff --git a/scripts/install_ccls_server.sh b/scripts/install_ccls_server.sh new file mode 100644 index 0000000..5f0056b --- /dev/null +++ b/scripts/install_ccls_server.sh @@ -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 diff --git a/scripts/install_clangd_server.sh b/scripts/install_clangd_server.sh new file mode 100644 index 0000000..0e5e707 --- /dev/null +++ b/scripts/install_clangd_server.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +printf 'Install from clang-tools or similar ' +printf 'with your OS or from releases on LLVM site\n' diff --git a/scripts/install_pylsp_server.sh b/scripts/install_pylsp_server.sh new file mode 100644 index 0000000..9f2ada2 --- /dev/null +++ b/scripts/install_pylsp_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'pip' + +if response == 'y' then + pip install python-lsp-server +fi diff --git a/scripts/install_pyright_server.sh b/scripts/install_pyright_server.sh new file mode 100644 index 0000000..383039b --- /dev/null +++ b/scripts/install_pyright_server.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +source scripts/query_dependencies.sh +query_dep 'npm' + +if response == 'y' then + npm -i -g pyright +fi diff --git a/scripts/install_sumneko_lua.sh b/scripts/install_sumneko_lua.sh new file mode 100644 index 0000000..cd5b854 --- /dev/null +++ b/scripts/install_sumneko_lua.sh @@ -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 diff --git a/scripts/install_zls_server.sh b/scripts/install_zls_server.sh new file mode 100644 index 0000000..f8fbd3d --- /dev/null +++ b/scripts/install_zls_server.sh @@ -0,0 +1,10 @@ +#!/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 diff --git a/scripts/query_dependency.sh b/scripts/query_dependency.sh new file mode 100644 index 0000000..1cef7d5 --- /dev/null +++ b/scripts/query_dependency.sh @@ -0,0 +1,7 @@ +function query_dep(){ + printf 'Did you install ' + printf $1 + printf '?\n (y/N)' + response='n' + read response +} From f6d4e367d21700114a082a30154a2252dfe6e94d Mon Sep 17 00:00:00 2001 From: Just Midi Date: Fri, 27 Aug 2021 07:12:57 +0000 Subject: [PATCH 6/7] Added lsp stuff --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ca2d94..d2cee99 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ My vim config written in lua designed for *smol boi minimal vibes* Most of the code is in separate modules. Each will later be its own true plugin. -### Install +### Installation Install the package manager `paq` to start: @@ -14,6 +14,29 @@ git clone --depth=1 https://github.com/savq/paq-nvim.git \ "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/paqs/start/paq-nvim ``` +#### LSP servers + +Scripts are supplied in `scripts/` for each server I use. Run these for the +corresponding server that you would like to be installed. + +The process in no way is automated or "purely in lua or vimscript", but it more +just holds your hand a bit. There may be plans in the future to automate this +with our own package manager. But I might start writing my own editor by that +point. So we'll see. + +If you'd like to add a new LSP server, feel free. Just make sure to ask the +user if all dependencies are installed. Currently, this is achieved using +`query_dep` in `query_dependency.sh`. All it does is ask the user if the +dependency is installed and quits the install script if any dependency is not +installed. *(don't even remind me how hacky that is)* + +However, a proper package management system would be more prefered. So never +feel like this pattern is in any way enforced. I can't be biased toward which +packages for which package managers will get maintained. And I can't be +bothered to write a package for every package manager that ever exists. If it +bothers you enough, change it to specifically work with your system. And maybe +contribute so others maybe follow suit. + ### Configure From f81c4bde28918b7144c0477915415774cb604a69 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Sat, 15 Jan 2022 20:27:27 +0000 Subject: [PATCH 7/7] nvim-lsp-installer, nvim-cmp, and other plugins Other plugins: - gitsigns - lightbulb - indent-blankline - treesitter - light theme Removed lsp install scripts b/c of nvim-lsp-installer --- init.lua | 8 +- lua/gitsigns-nvim.lua | 65 ++++++++++ lua/indent-blankline.lua | 5 + lua/lightbulb.lua | 1 + lua/native-lsp/init.lua | 170 +++----------------------- lua/native-lsp/nvim-cmp.lua | 154 +++++++++++++++++++++++ lua/native-lsp/nvim-lsp-installer.lua | 75 ++++++++++++ lua/plugins/init.lua | 54 +++++++- lua/tree-sitter.lua | 26 ++++ lua/ui/init.lua | 7 +- lua/ui/statusbar.lua | 47 +++---- scripts/install_bashls_server.sh | 8 -- scripts/install_ccls_server.sh | 14 --- scripts/install_clangd_server.sh | 4 - scripts/install_pylsp_server.sh | 8 -- scripts/install_pyright_server.sh | 8 -- scripts/install_sumneko_lua.sh | 17 --- scripts/install_zls_server.sh | 10 -- scripts/query_dependency.sh | 7 -- 19 files changed, 429 insertions(+), 259 deletions(-) create mode 100644 lua/gitsigns-nvim.lua create mode 100644 lua/indent-blankline.lua create mode 100644 lua/lightbulb.lua create mode 100644 lua/native-lsp/nvim-cmp.lua create mode 100644 lua/native-lsp/nvim-lsp-installer.lua create mode 100644 lua/tree-sitter.lua delete mode 100644 scripts/install_bashls_server.sh delete mode 100644 scripts/install_ccls_server.sh delete mode 100644 scripts/install_clangd_server.sh delete mode 100644 scripts/install_pylsp_server.sh delete mode 100644 scripts/install_pyright_server.sh delete mode 100644 scripts/install_sumneko_lua.sh delete mode 100644 scripts/install_zls_server.sh delete mode 100644 scripts/query_dependency.sh diff --git a/init.lua b/init.lua index a968659..562a6b1 100755 --- a/init.lua +++ b/init.lua @@ -20,10 +20,14 @@ v = vim.v -- variables env = vim.env -- environment variables local modules = { + 'ui', 'general', 'keymap', - 'ui', - 'native-lsp' + 'plugins', + 'native-lsp', + 'indent-blankline', + 'gitsigns-nvim', + 'lightbulb' } local async diff --git a/lua/gitsigns-nvim.lua b/lua/gitsigns-nvim.lua new file mode 100644 index 0000000..4c294f4 --- /dev/null +++ b/lua/gitsigns-nvim.lua @@ -0,0 +1,65 @@ +require('gitsigns').setup { + signs = { + add = {hl = 'GitSignsAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, + change = {hl = 'GitSignsChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + topdelete = {hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + keymaps = { + -- Default keymap options + noremap = true, + + ['n ]c'] = { expr = true, "&diff ? ']c' : 'Gitsigns next_hunk'"}, + ['n [c'] = { expr = true, "&diff ? '[c' : 'Gitsigns prev_hunk'"}, + + ['n hs'] = 'Gitsigns stage_hunk', + ['v hs'] = ':Gitsigns stage_hunk', + ['n hu'] = 'Gitsigns undo_stage_hunk', + ['n hr'] = 'Gitsigns reset_hunk', + ['v hr'] = ':Gitsigns reset_hunk', + ['n hR'] = 'Gitsigns reset_buffer', + ['n hp'] = 'Gitsigns preview_hunk', + ['n hb'] = 'lua require"gitsigns".blame_line{full=true}', + ['n hS'] = 'Gitsigns stage_buffer', + ['n hU'] = 'Gitsigns reset_buffer_index', + + -- Text objects + ['o ih'] = ':Gitsigns select_hunk', + ['x ih'] = ':Gitsigns select_hunk' + }, + watch_gitdir = { + interval = 1000, + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter_opts = { + relative_time = false + }, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + yadm = { + enable = false + }, +} diff --git a/lua/indent-blankline.lua b/lua/indent-blankline.lua new file mode 100644 index 0000000..6c3b3a5 --- /dev/null +++ b/lua/indent-blankline.lua @@ -0,0 +1,5 @@ +require("indent_blankline").setup { + -- for example, context is off by default, use this to turn it on + show_current_context = true, + show_current_context_start = true, +} diff --git a/lua/lightbulb.lua b/lua/lightbulb.lua new file mode 100644 index 0000000..ef03877 --- /dev/null +++ b/lua/lightbulb.lua @@ -0,0 +1 @@ +require('nvim-lightbulb').update_lightbulb() diff --git a/lua/native-lsp/init.lua b/lua/native-lsp/init.lua index 71912b3..3666541 100644 --- a/lua/native-lsp/init.lua +++ b/lua/native-lsp/init.lua @@ -19,163 +19,23 @@ -- v = vim.v -- variables -- env = vim.env -- environment variables --- dependent on https://github.com/neovim/nvim-lspconfig -local lspconfig = require 'lspconfig' +require("native-lsp/nvim-lsp-installer") -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'} +local lspconfig = require('lspconfig') + +local on_attach = function(_, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + require('completion').on_attach() +end + +local servers = {'zls'} +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, } - - 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 +opt.completeopt = "menu,menuone,noselect" +g.completion_enable_auto_popup = 1 - 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' +require("native-lsp/nvim-cmp") diff --git a/lua/native-lsp/nvim-cmp.lua b/lua/native-lsp/nvim-cmp.lua new file mode 100644 index 0000000..62ad48c --- /dev/null +++ b/lua/native-lsp/nvim-cmp.lua @@ -0,0 +1,154 @@ +local cmp = require("cmp") +local luasnip = require("luasnip") + +if not luasnip then + return +end + +local lsp_symbols = { + Text = "  (Text) ", + Method = "  (Method)", + Function = "  (Function)", + Constructor = "  (Constructor)", + Field = " ﴲ (Field)", + Variable = "  (Variable)", + Class = "  (Class)", + Interface = "  (Interface)", + Module = "  (Module)", + Property = " 襁 (Property)", + Unit = "  (Unit)", + Value = "  (Value)", + Enum = " 練 (Enum)", + Keyword = "  (Keyword)", + Snippet = "  (Snippet)", + Color = "  (Color)", + File = "  (File)", + Reference = "  (Reference)", + Folder = "  (Folder)", + EnumMember = "  (EnumMember)", + Constant = "  (Constant)", + Struct = "  (Struct)", + Event = "  (Event)", + Operator = "  (Operator)", + TypeParameter = "  (TypeParameter)" +} + +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +end + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + + mapping = { + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + + formatting = { + format = function(entry, item) + item.kind = lsp_symbols[item.kind] .. " " .. item.kind + -- set a name for each source + item.menu = ({ + spell = "[Spell]", + buffer = "[Buffer]", + calc = "[Calc]", + emoji = "[Emoji]", + nvim_lsp = "[LSP]", + path = "[Path]", + look = "[Look]", + treesitter = "[treesitter]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]", + cmp_tabnine = "[Tab9]" + })[entry.source.name] + return item + end + }, + + sources = { + { name = 'nvim_lsp' }, + { name = 'cmp_tabnine' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'latex_symbols'}, + { name = 'treesitter' }, + { name = 'buffer' }, + { + name = 'look', + keyword_length = 2, + option = { + convert_case = true, + loud = true + } + }, + { name = 'emoji' }, + { name = 'calc' } + }, + + cmp.setup.cmdline('-', { + sources = { + { name = 'path' }, + { name = 'cmdline' }, + { name = 'nvim_lua' }, + { name = 'buffer' } + } + }), + + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } + }), + + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }), +}) + +local tabnine = require('cmp_tabnine.config') + +tabnine:setup({ + max_lines = 1000; + max_num_results = 20; + sort = true; + run_on_every_keystroke = true; + snippet_placeholder = '..'; + ignored_file_types = { -- default is not to ignore + -- uncomment to ignore in lua: + -- lua = true + }; +}) diff --git a/lua/native-lsp/nvim-lsp-installer.lua b/lua/native-lsp/nvim-lsp-installer.lua new file mode 100644 index 0000000..3e74c80 --- /dev/null +++ b/lua/native-lsp/nvim-lsp-installer.lua @@ -0,0 +1,75 @@ +local lsp_installer = require("nvim-lsp-installer") + + +local lang_servers = { + "bashls", + "ccls", + "clangd", + "cmake", + "cssls", + "cssmodules_ls", + "diagnosticls", + "dockerls", + "dotls", + "efm", + --"eslint", + "emmet_ls", + --"grammarly", + "graphql", + "html", + --"hls", + "jsonls", + --"jdtls", + --"quick_lint_js", + "tsserver", + --"ltex", + "texlab", + "sumneko_lua", + "remark_ls", + --"zk", + "puppet", + --"jedi_language_server", + "pyright", + --"pylsp", + "sqlls", + --"sqls", + --"svelte", + "taplo", + --"tailwindcss", + --"tflint", -- going to use tsserver first + "lemminx", + "yamlls", + "zls", +} + +for _, name in pairs(lang_servers) do + local server_is_found, server = lsp_installer.get_server(name) + if server_is_found then + if not server:is_installed() then + print("Installing " .. name) + server:install() + end + end +end + + + +lsp_installer.on_server_ready(function(server) + local opts = {} + opts.on_attach = on_attach + opts.capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + + server:setup(opts) + vim.cmd [[ do User LspAttachBuffers ]] +end) + + +lsp_installer.settings({ + ui = { + icons = { + server_installed = "✓", + server_pending = "➜", + server_uninstalled = "✗" + } + } +}) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index af44810..1816eb1 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,8 +1,58 @@ require "paq" { - "savq/paq-nvim"; -- Let Paq manage itself + -- let paq manage itself + "savq/paq-nvim"; + -- lsp "neovim/nvim-lspconfig"; - "hrsh7th/nvim-compe"; + {"williamboman/nvim-lsp-installer", branch="dont-prepare-root-dir"}; + -- cmp + "hrsh7th/nvim-cmp"; + "hrsh7th/cmp-nvim-lsp"; + "hrsh7th/cmp-buffer"; + "hrsh7th/cmp-path"; + "hrsh7th/cmp-cmdline"; + "hrsh7th/cmp-nvim-lua"; + "hrsh7th/cmp-calc"; + "hrsh7th/cmp-emoji"; + "hrsh7th/cmp-latex-symbols"; + "octaltree/cmp-look"; + {"tzachar/cmp-tabnine", run="./install.sh"}; + + -- lua snips + "L3MON4D3/LuaSnip"; + "saadparwaiz1/cmp_luasnip"; + + -- diagnostics + "folke/trouble.nvim"; + "kyazdani42/nvim-web-devicons"; + + -- pandoc + "vim-pandoc/vim-pandoc"; + + -- zig ls + "zigtools/zls"; + + -- theme + "rakr/vim-one"; + + "mattn/emmet-vim"; --{"lervag/vimtex", opt=true}; + + -- tree sitter + "nvim-treesitter/nvim-treesitter"; + "nvim-treesitter/nvim-treesitter-textobjects"; + "ray-x/cmp-treesitter"; + + "lukas-reineke/indent-blankline.nvim"; + + "kosayoda/nvim-lightbulb"; + + "turbio/bracey.vim"; + + -- git symbols + "lewis6991/gitsigns.nvim"; + "nvim-lua/plenary.nvim"; } + +cmd 'PaqSync' diff --git a/lua/tree-sitter.lua b/lua/tree-sitter.lua new file mode 100644 index 0000000..6866e67 --- /dev/null +++ b/lua/tree-sitter.lua @@ -0,0 +1,26 @@ +cmd [[ +TSInstall bash +TSInstall bibtex +TSInstall c +TSInstall cmake +TSInstall cpp +TSInstall css +TSInstall dockerfile +TSInstall dot +TSInstall graphql +TSInstall html +TSInstall http +TSInstall javascript +TSInstall latex +TSInstall llvm +TSInstall lua +TSInstall make +TSInstall python +TSInstall regex +TSInstall verilog +TSInstall vim +TSInstall yaml +TSInstall zig +TSUpdate +]] + diff --git a/lua/ui/init.lua b/lua/ui/init.lua index 78c0222..92a0402 100755 --- a/lua/ui/init.lua +++ b/lua/ui/init.lua @@ -30,8 +30,8 @@ o.showmatch = true -- matching bracket -- Completion Menu -o.wildmenu = true -o.wildmode = 'list:longest,full' +--o.wildmenu = true +--o.wildmode = 'list:longest,full' -- Character Representation @@ -104,6 +104,9 @@ autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929 autocmd BufEnter * match OverLength /\%71v.*/ ]]) --rewrite in lua +-- Theme +o.background = "light" +cmd('colorscheme one') --WIP -- Filetype: txt, md, tex diff --git a/lua/ui/statusbar.lua b/lua/ui/statusbar.lua index 01362e0..5613408 100755 --- a/lua/ui/statusbar.lua +++ b/lua/ui/statusbar.lua @@ -31,27 +31,30 @@ local function file_state() return "" end -local function diagnostics() - local buffer_number = vim.fn.bufnr('%') - local severity_levels = { - -- level,prefix - errors = {'Error', 'E:'}, - warnings = {'Warning', 'W:'}, - info = {'Information', 'I:'}, - hints = {'Hint', 'H:'} - } - local out = '' - for _,v in pairs(severity_levels) do - local d = vim.lsp.diagnostic.get_count( - buffer_number, - v[1] -- level - ) - if d > 0 then - out = out .. v[2] .. d .. ' ' - end - end - return out -end +--local function diagnostics() +-- --local buffer_number = vim.fn.bufnr('%') +-- local severity_levels = { +-- -- level,prefix +-- errors = {'Error', 'E:'}, +-- warnings = {'Warning', 'W:'}, +-- info = {'Information', 'I:'}, +-- hints = {'Hint', 'H:'} +-- } +-- local out = '' +-- for _,v in pairs(severity_levels) do +-- local d = vim.diagnostic.get( +-- 0, +-- ) +-- --local d = vim.lsp.diagnostic.get_count( +-- -- buffer_number, +-- -- v[1] -- level +-- --) +-- if d > 0 then +-- out = out .. v[2] .. d .. ' ' +-- end +-- end +-- return out +--end local function highlight(group, color) cmd('highlight ' .. group .. ' cterm='..color .. ' gui='..color) @@ -100,7 +103,7 @@ function status_bar() return table.concat(sections({ -- Stage Left {'%f', file_state()}, - {diagnostics()}, + --{diagnostics()}, '%=', -- Stage Right { diff --git a/scripts/install_bashls_server.sh b/scripts/install_bashls_server.sh deleted file mode 100644 index fab818a..0000000 --- a/scripts/install_bashls_server.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -source scripts/query_dependencies.sh -query_dep 'npm' - -if response == 'y' then - npm -i -g bash-language-server -fi diff --git a/scripts/install_ccls_server.sh b/scripts/install_ccls_server.sh deleted file mode 100644 index 5f0056b..0000000 --- a/scripts/install_ccls_server.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/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 diff --git a/scripts/install_clangd_server.sh b/scripts/install_clangd_server.sh deleted file mode 100644 index 0e5e707..0000000 --- a/scripts/install_clangd_server.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -printf 'Install from clang-tools or similar ' -printf 'with your OS or from releases on LLVM site\n' diff --git a/scripts/install_pylsp_server.sh b/scripts/install_pylsp_server.sh deleted file mode 100644 index 9f2ada2..0000000 --- a/scripts/install_pylsp_server.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -source scripts/query_dependencies.sh -query_dep 'pip' - -if response == 'y' then - pip install python-lsp-server -fi diff --git a/scripts/install_pyright_server.sh b/scripts/install_pyright_server.sh deleted file mode 100644 index 383039b..0000000 --- a/scripts/install_pyright_server.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -source scripts/query_dependencies.sh -query_dep 'npm' - -if response == 'y' then - npm -i -g pyright -fi diff --git a/scripts/install_sumneko_lua.sh b/scripts/install_sumneko_lua.sh deleted file mode 100644 index cd5b854..0000000 --- a/scripts/install_sumneko_lua.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/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 diff --git a/scripts/install_zls_server.sh b/scripts/install_zls_server.sh deleted file mode 100644 index f8fbd3d..0000000 --- a/scripts/install_zls_server.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/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 diff --git a/scripts/query_dependency.sh b/scripts/query_dependency.sh deleted file mode 100644 index 1cef7d5..0000000 --- a/scripts/query_dependency.sh +++ /dev/null @@ -1,7 +0,0 @@ -function query_dep(){ - printf 'Did you install ' - printf $1 - printf '?\n (y/N)' - response='n' - read response -}