From 052b4513c25a1e4f28841e3e22ac01c8a820e711 Mon Sep 17 00:00:00 2001 From: Just Midi Date: Wed, 11 Aug 2021 20:52:37 +0000 Subject: [PATCH] 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 {}')