diff options
| author | seth <[email protected]> | 2022-08-24 15:37:06 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2022-08-24 15:37:06 -0400 |
| commit | 8fef927ede6733c20a53c4b0c13d2ab4cb08b604 (patch) | |
| tree | c5eae97847773355ffd3f2afcc84c7c9c2a5b387 /.config/nvim/lua/getchoo/lsp/config | |
| parent | ee45c4211d79dfb3b62531cc4f974ac3932e5131 (diff) | |
refactor lsp config
Diffstat (limited to '.config/nvim/lua/getchoo/lsp/config')
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/cmp.lua | 71 | ||||
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/init.lua | 34 | ||||
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/lsp_config.lua | 42 | ||||
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/mason.lua | 14 | ||||
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/null_ls.lua | 38 | ||||
| -rw-r--r-- | .config/nvim/lua/getchoo/lsp/config/sources.lua | 27 |
6 files changed, 226 insertions, 0 deletions
diff --git a/.config/nvim/lua/getchoo/lsp/config/cmp.lua b/.config/nvim/lua/getchoo/lsp/config/cmp.lua new file mode 100644 index 0000000..bfade29 --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/cmp.lua @@ -0,0 +1,71 @@ +local cmp = require("cmp") +local mapping = cmp.mapping +local luasnip = require("luasnip") + +local M = {} + +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 + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +M.config = { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + luasnip.lsp_expand(args.body) + end, + }, + mapping = mapping.preset.insert({ + ["<C-Space>"] = mapping.complete(), + ["<CR>"] = mapping.confirm({ + select = true, + }), + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("<Plug>(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + elseif vim.fn["vsnip#available"](-1) == 1 then + feedkey("<Plug>(vsnip-jump-prev)", "") + else + fallback() + end + end, { "i", "s" }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "vsnip" }, + }, { + { name = "buffer" }, + }), +} + +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) +capabilities.textDocument.completion.completionItem.snippetSupport = true + +M.capabilities = capabilities + +M.on_attach = function(_, bufnr) + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") +end + +return M diff --git a/.config/nvim/lua/getchoo/lsp/config/init.lua b/.config/nvim/lua/getchoo/lsp/config/init.lua new file mode 100644 index 0000000..b136dcf --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/init.lua @@ -0,0 +1,34 @@ +-- wrapper for all configs +local cmp = require("getchoo.lsp.config.cmp") +local lsp_config = require("getchoo.lsp.config.lsp_config") +local mason = require("getchoo.lsp.config.mason") +local null_ls = require("getchoo.lsp.config.null_ls") + +local M = {} + +M.bufferline = { + options = { + numbers = "ordinal", + diagnostics = "nvim_lsp", + always_show_bufferline = false, + }, +} + +M.cmp = cmp.config + +M.lsp_servers = lsp_config.servers + +M.mason_tool_installer = mason.mason_tool_installer +M.mason_lsp = mason.mason_lsp_config + +M.null_ls = null_ls.config + +M.tree = {} + +M.treesitter = { + auto_install = true, +} + +M.trouble = {} + +return M diff --git a/.config/nvim/lua/getchoo/lsp/config/lsp_config.lua b/.config/nvim/lua/getchoo/lsp/config/lsp_config.lua new file mode 100644 index 0000000..4bf69e4 --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/lsp_config.lua @@ -0,0 +1,42 @@ +local cmp = require("getchoo.lsp.config.cmp") +local sources = require("getchoo.lsp.config.sources") + +local M = {} + +local on_attach = function(client, bufnr) + cmp.on_attach(client, bufnr) +end + +local all_config = { + on_attach = on_attach, + capabilities = cmp.capabilities, +} + +local servers = {} +for _, server in ipairs(sources.lsp_servers) do + servers[server] = all_config +end + +servers["sumneko_lua"] = { + on_attach = on_attach, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, +} + +M.servers = servers + +return M diff --git a/.config/nvim/lua/getchoo/lsp/config/mason.lua b/.config/nvim/lua/getchoo/lsp/config/mason.lua new file mode 100644 index 0000000..de45c49 --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/mason.lua @@ -0,0 +1,14 @@ +-- config for mason tools +local sources = require("getchoo.lsp.config.sources") + +local M = {} + +M.mason_tool_installer = { + ensure_installed = sources.mason, +} + +M.mason_lsp = { + automatic_installation = true, +} + +return M diff --git a/.config/nvim/lua/getchoo/lsp/config/null_ls.lua b/.config/nvim/lua/getchoo/lsp/config/null_ls.lua new file mode 100644 index 0000000..dd091a9 --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/null_ls.lua @@ -0,0 +1,38 @@ +local sources = require("getchoo.lsp.config.sources") + +local M = {} + +-- only use null-ls for formatting + +--- for neovim >= 8 +--- local lsp_formatting = function(bufnr) +--- vim.lsp.buf.format({ +--- filter = function(client) +--- return client.name == "null-ls" +--- end, +--- bufnr = bufnr, +--- }) +--- end + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) +local formatting_on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + local params = require("vim.lsp.util").make_formatting_params({}) + client.request("textDocument/formatting", params, nil, bufnr) + -- lsp_formatting(bufnr) -- neovim >= 8 + end, + }) + end +end + +M.config = { + on_attach = formatting_on_attach, + sources = sources.null_ls, +} + +return M diff --git a/.config/nvim/lua/getchoo/lsp/config/sources.lua b/.config/nvim/lua/getchoo/lsp/config/sources.lua new file mode 100644 index 0000000..7281508 --- /dev/null +++ b/.config/nvim/lua/getchoo/lsp/config/sources.lua @@ -0,0 +1,27 @@ +local null_ls = require("null-ls") +local diagnostics = null_ls.builtins.diagnostics +local formatting = null_ls.builtins.formatting + +local M = { + lsp_servers = { "rust_analyzer", "pyright", "bashls" }, + null_ls = { + diagnostics.alex, + diagnostics.codespell, + diagnostics.flake8, + formatting.black, + formatting.codespell, + formatting.prettier, + formatting.rustfmt, + formatting.stylua, + }, + mason = { + "alex", + "black", + "codespell", + "flake8", + "prettier", + "stylua", + }, +} + +return M |
