diff options
author | christianchiarulli <[email protected]> | 2021-06-30 18:45:40 -0400 |
---|---|---|
committer | christianchiarulli <[email protected]> | 2021-06-30 18:45:40 -0400 |
commit | 9e7ad6074746a3f7d60e164be919b53ad17a33dd (patch) | |
tree | 6ccd7982f850908d317945fd8967119b298c4ffb /lua/lsp | |
parent | d8cf871a389d9900fa21077870a817cdb6a6b47b (diff) |
refactor autocommands
Diffstat (limited to 'lua/lsp')
-rw-r--r-- | lua/lsp/go-ls.lua | 19 | ||||
-rw-r--r-- | lua/lsp/init.lua | 7 | ||||
-rw-r--r-- | lua/lsp/java-ls.lua | 9 | ||||
-rw-r--r-- | lua/lsp/js-ts-ls.lua | 37 | ||||
-rw-r--r-- | lua/lsp/json-ls.lua | 12 | ||||
-rw-r--r-- | lua/lsp/lua-ls.lua | 16 | ||||
-rw-r--r-- | lua/lsp/python-ls.lua | 34 | ||||
-rw-r--r-- | lua/lsp/ruby-ls.lua | 16 | ||||
-rw-r--r-- | lua/lsp/rust-ls.lua | 91 |
9 files changed, 215 insertions, 26 deletions
diff --git a/lua/lsp/go-ls.lua b/lua/lsp/go-ls.lua index 201873a8..4af87a9d 100644 --- a/lua/lsp/go-ls.lua +++ b/lua/lsp/go-ls.lua @@ -1,7 +1,22 @@ -require'lspconfig'.gopls.setup{ +require'lspconfig'.gopls.setup { cmd = {DATA_PATH .. "/lspinstall/go/gopls"}, settings = {gopls = {analyses = {unusedparams = true}, staticcheck = true}}, - root_dir = require'lspconfig'.util.root_pattern(".git","go.mod"), + root_dir = require'lspconfig'.util.root_pattern(".git", "go.mod"), init_options = {usePlaceholders = true, completeUnimported = true}, on_attach = require'lsp'.common_on_attach } + +if O.lang.go.autoformat then + require('lv-utils').define_augroups({ + _go_format = { + 'BufWritePre', '*.go', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + }, + _go = { + -- Go generally requires Tabs instead of spaces. + {'FileType', 'go', 'setlocal tabstop=4'}, + {'FileType', 'go', 'setlocal shiftwidth=4'}, + {'FileType', 'go', 'setlocal softtabstop=4'}, + {'FileType', 'go', 'setlocal noexpandtab'} + } + }) +end diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index ef2e2f9b..367aefba 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -111,6 +111,13 @@ function lsp_config.tsserver_on_attach(client, bufnr) client.resolved_capabilities.document_formatting = false end + +require('lv-utils').define_augroups({ + _general_lsp = { + {'FileType', 'lspinfo', 'nnoremap <silent> <buffer> q :q<CR>'}, + } +}) + -- Use a loop to conveniently both setup defined servers -- and map buffer local keybindings when the language server attaches -- local servers = {"pyright", "tsserver"} diff --git a/lua/lsp/java-ls.lua b/lua/lsp/java-ls.lua index 90985ff4..0b151b66 100644 --- a/lua/lsp/java-ls.lua +++ b/lua/lsp/java-ls.lua @@ -39,3 +39,12 @@ require'lspconfig'.jdtls.setup { -- root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}), -- init_options = {bundles = bundles} -- }) + +-- TODO setup autoformat stuff later + -- _java = { + -- -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'}, + -- { + -- 'FileType', 'java', + -- 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>' + -- } + -- } diff --git a/lua/lsp/js-ts-ls.lua b/lua/lsp/js-ts-ls.lua index 94e1b72d..0006dab7 100644 --- a/lua/lsp/js-ts-ls.lua +++ b/lua/lsp/js-ts-ls.lua @@ -7,17 +7,27 @@ -- require'completion'.on_attach(client) -- require'illuminate'.on_attach(client) -- end - require'lspconfig'.tsserver.setup { - cmd = {DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio"}, - filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }, + cmd = { + DATA_PATH .. + "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio" + }, + filetypes = { + "javascript", "javascriptreact", "javascript.jsx", "typescript", + "typescriptreact", "typescript.tsx" + }, on_attach = require'lsp'.tsserver_on_attach, -- This makes sure tsserver is not used for formatting (I prefer prettier) -- on_attach = require'lsp'.common_on_attach, - root_dir = require('lspconfig/util').root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), + root_dir = require('lspconfig/util').root_pattern("package.json", + "tsconfig.json", + "jsconfig.json", ".git"), settings = {documentFormatting = false}, handlers = { - ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic + .on_publish_diagnostics, + { virtual_text = O.lang.tsserver.diagnostics.virtual_text, signs = O.lang.tsserver.diagnostics.signs, underline = O.lang.tsserver.diagnostics.underline, @@ -26,3 +36,20 @@ require'lspconfig'.tsserver.setup { }) } } + +if O.lang.tsserver.autoformat then + require('lv-utils').define_augroups({ + _javascript_autoformat = { + 'BufWritePre', '*.js', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + }, + _javascriptreact_autoformat = { + 'BufWritePre', '*.jsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + }, + _typescript_autoformat = { + 'BufWritePre', '*.ts', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + }, + _typescriptreact_autoformat = { + 'BufWritePre', '*.tsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + }) +end diff --git a/lua/lsp/json-ls.lua b/lua/lsp/json-ls.lua index 952673ac..7d3c3716 100644 --- a/lua/lsp/json-ls.lua +++ b/lua/lsp/json-ls.lua @@ -1,7 +1,8 @@ -- npm install -g vscode-json-languageserver require'lspconfig'.jsonls.setup { cmd = { - "node", DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", + "node", DATA_PATH .. + "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", "--stdio" }, on_attach = require'lsp'.common_on_attach, @@ -14,3 +15,12 @@ require'lspconfig'.jsonls.setup { } } } + +if O.lang.json.autoformat then + require('lv-utils').define_augroups({ + _json_format = { + 'BufWritePre', '*.json', + 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + }) +end diff --git a/lua/lsp/lua-ls.lua b/lua/lsp/lua-ls.lua index 775eb92f..4257605f 100644 --- a/lua/lsp/lua-ls.lua +++ b/lua/lsp/lua-ls.lua @@ -19,9 +19,23 @@ require'lspconfig'.sumneko_lua.setup { }, workspace = { -- Make the server aware of Neovim runtime files - library = {[vim.fn.expand('$VIMRUNTIME/lua')] = true, [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true}, + library = { + [vim.fn.expand('$VIMRUNTIME/lua')] = true, + [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true + }, maxPreload = 10000 } } } } +if O.lang.lua.autoformat then + require('lv-utils').define_augroups({ + _lua_autoformat = { + { + 'BufWritePre', '*.lua', + 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + } + }) +end + diff --git a/lua/lsp/python-ls.lua b/lua/lsp/python-ls.lua index 7ffcbb25..e2ccf42e 100644 --- a/lua/lsp/python-ls.lua +++ b/lua/lsp/python-ls.lua @@ -1,22 +1,38 @@ -- npm i -g pyright require'lspconfig'.pyright.setup { - cmd = {DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio"}, + cmd = { + DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", + "--stdio" + }, on_attach = require'lsp'.common_on_attach, handlers = { - ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic + .on_publish_diagnostics, + { virtual_text = O.lang.python.diagnostics.virtual_text, signs = O.lang.python.diagnostics.signs, underline = O.lang.python.diagnostics.underline, update_in_insert = true }) }, - settings = { - python = { - analysis = { - typeCheckingMode = O.lang.python.analysis.type_checking, - autoSearchPaths = O.lang.python.analysis.auto_search_paths, - useLibraryCodeForTypes = O.lang.python.analysis.use_library_code_types + settings = { + python = { + analysis = { + typeCheckingMode = O.lang.python.analysis.type_checking, + autoSearchPaths = O.lang.python.analysis.auto_search_paths, + useLibraryCodeForTypes = O.lang.python.analysis + .use_library_code_types + } } - } } } +if O.lang.python.autoformat then + require('lv-utils').define_augroups({ + _python_autoformat = { + { + 'BufWritePre', '*.py', + 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + } + }) +end diff --git a/lua/lsp/ruby-ls.lua b/lua/lsp/ruby-ls.lua index 079616b1..960b220a 100644 --- a/lua/lsp/ruby-ls.lua +++ b/lua/lsp/ruby-ls.lua @@ -1,9 +1,11 @@ -- If you are using rvm, make sure to change below configuration require'lspconfig'.solargraph.setup { - cmd = { DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "--stdio" }, + cmd = {DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "--stdio"}, on_attach = require'lsp'.common_on_attach, handlers = { - ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic + .on_publish_diagnostics, + { virtual_text = O.lang.ruby.diagnostics.virtual_text, signs = O.lang.ruby.diagnostics.signs, underline = O.lang.ruby.diagnostics.underline, @@ -11,5 +13,13 @@ require'lspconfig'.solargraph.setup { }) }, - filetypes = O.lang.ruby.filetypes, + filetypes = O.lang.ruby.filetypes } + +if O.lang.ruby.autoformat then + require('lv-utils').define_augroups({ + _ruby_format = { + 'BufWritePre', '*.rb', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + } + }) +end diff --git a/lua/lsp/rust-ls.lua b/lua/lsp/rust-ls.lua index e08ebb08..22f66f2d 100644 --- a/lua/lsp/rust-ls.lua +++ b/lua/lsp/rust-ls.lua @@ -1,6 +1,87 @@ --- the rust-tools plugin will configure this automatically ---require'lspconfig'.rust_analyzer.setup{ --- cmd = {DATA_PATH .. "/lspinstall/rust/rust-analyzer"}, --- on_attach = require'lsp'.common_on_attach ---} +local opts = { + tools = { -- rust-tools options + -- automatically set inlay hints (type hints) + -- There is an issue due to which the hints are not applied on the first + -- opened file. For now, write to the file to trigger a reapplication of + -- the hints or just run :RustSetInlayHints. + -- default: true + autoSetHints = true, + + -- whether to show hover actions inside the hover window + -- this overrides the default hover handler + -- default: true + hover_with_actions = true, + + runnables = { + -- whether to use telescope for selection menu or not + -- default: true + use_telescope = true + + -- rest of the opts are forwarded to telescope + }, + + inlay_hints = { + -- wheter to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, + + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<-", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=>", + + -- whether to align to the lenght of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7 + }, + + hover_actions = { + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + {"â•", "FloatBorder"}, {"─", "FloatBorder"}, + {"â•®", "FloatBorder"}, {"│", "FloatBorder"}, + {"╯", "FloatBorder"}, {"─", "FloatBorder"}, + {"â•°", "FloatBorder"}, {"│", "FloatBorder"} + } + } + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer + server = { + cmd = {DATA_PATH .. "/lspinstall/rust/rust-analyzer"}, + on_attach = require'lsp'.common_on_attach + } -- rust-analyser options +} + +require('rust-tools').setup(opts) + +-- TODO add this later +vim.api.nvim_exec([[ + autocmd Filetype rust nnoremap <leader>lm <Cmd>RustExpandMacro<CR> + autocmd Filetype rust nnoremap <leader>lH <Cmd>RustToggleInlayHints<CR> + autocmd Filetype rust nnoremap <leader>le <Cmd>RustRunnables<CR> + autocmd Filetype rust nnoremap <leader>lh <Cmd>RustHoverActions<CR> + ]], true) + +if O.lang.rust.autoformat then + require('lv-utils').define_augroups({ + _rust_format = { + 'BufWritePre', '*.rs', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + } + }) +end |