diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-01-08 09:58:56 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-01-08 09:58:56 +0100 |
| commit | f7bcac5ee5db56081981bb946a66d3fc34807988 (patch) | |
| tree | 2cfc8d60054508d5297cd392d6df1e540057bcc7 /after/plugin | |
| parent | fb9196e7766f53115009c081f0b4308ca6c081b4 (diff) | |
| download | nvim-conf-f7bcac5ee5db56081981bb946a66d3fc34807988.tar.gz nvim-conf-f7bcac5ee5db56081981bb946a66d3fc34807988.zip | |
feat: refactor lsp & cmp to lua folder from after
Diffstat (limited to 'after/plugin')
| -rw-r--r-- | after/plugin/cmp.lua | 140 | ||||
| -rw-r--r-- | after/plugin/lsp.lua | 162 | ||||
| -rw-r--r-- | after/plugin/mason.lua | 62 | ||||
| -rw-r--r-- | after/plugin/null-ls.lua | 17 |
4 files changed, 12 insertions, 369 deletions
diff --git a/after/plugin/cmp.lua b/after/plugin/cmp.lua deleted file mode 100644 index 8e980d1..0000000 --- a/after/plugin/cmp.lua +++ /dev/null @@ -1,140 +0,0 @@ -local ok, cmp = pcall(require, "cmp") -if not ok then - return -end - -local lspkind = require("lspkind") -local luasnip = require("luasnip") -local cmp_autopairs = require("nvim-autopairs.completion.cmp") - -if cmp == nil then - return -end - -cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) - -cmp.setup({ - mapping = { - ["<C-d>"] = cmp.mapping.scroll_docs(-4), - ["<C-f>"] = cmp.mapping.scroll_docs(4), - ["<C-e>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.close() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - ["<C-n>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.choice_active() then - luasnip.change_choice(1) - else - fallback() - end - end, { "i", "s" }), - ["<C-p>"] = cmp.mapping.select_prev_item(), - ["<C-y>"] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }), - ["<c-space>"] = cmp.mapping.complete(), - }, - sources = { - { name = "nvim_lua" }, - { name = "nvim_lsp" }, - { name = "path" }, - { name = "luasnip" }, - { - name = "buffer", - keyword_length = 4, - option = { - get_bufnrs = function() - local bufs = {} - for _, win in ipairs(vim.api.nvim_list_wins()) do - bufs[vim.api.nvim_win_get_buf(win)] = true - end - return vim.tbl_keys(bufs) - end, - }, - }, - }, - - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - - formatting = { - format = lspkind.cmp_format({ - with_text = true, - menu = { - buffer = "[buf]", - nvim_lsp = "[LSP]", - nvim_lua = "[api]", - path = "[path]", - luasnip = "[snip]", - ["vim-dadbod-completion"] = "[DB]", - }, - }), - }, - - experimental = { - native_menu = false, - - ghost_text = true, - }, -}) - --- Set configuration for specific filetype. -cmp.setup.filetype("gitcommit", { - sources = cmp.config.sources({ - { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = "buffer" }, - }), -}) - --- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline("/", { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" }, - }, -}) - --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" }, - }, { - { name = "cmdline" }, - }), -}) - -cmp.setup.filetype({ "sql", "mysql", "plsql" }, { - sources = cmp.config.sources({ - { name = "vim-dadbod-completion" }, - }, { - { name = "buffer" }, - }), -}) - -cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { - sources = cmp.config.sources({ - { name = "dap" }, - }, { - { name = "buffer" }, - }), -}) - --- Setup lspconfig. -local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) --- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled. -require("lspconfig")["emmet_ls"].setup({ - capabilities = capabilities, -}) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua deleted file mode 100644 index e2f5652..0000000 --- a/after/plugin/lsp.lua +++ /dev/null @@ -1,162 +0,0 @@ -local telescope_mapper = require("alpha.telescope.mappings") -local lspconfig = require("lspconfig") - -local lsp_formatting = function(bufnr, allowed_clientes) - vim.lsp.buf.format({ - filter = function(client) - for _, value in pairs(allowed_clientes) do - if client.name == value then - return true - end - end - - return false - end, - bufnr = bufnr, - }) -end - --- if you want to set up formatting on save, you can use this as a callback -local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - -local format_on_save = function(allowed_clients) - return 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() - lsp_formatting(bufnr, allowed_clients) - end, - }) - end - end -end - -local filetype_attach = setmetatable({ - go = format_on_save({ "gopls" }), - -- php = format_on_save, - -- lua = format_on_save, - - gdscript = function(_) end, -}, { - __index = function() - return function() end - end, -}) - --- Since I use null os this allows to have the format and actions --- in all buffers not just configured servers -vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {}) - -vim.keymap.set("n", "<leader>vf", function() - return vim.lsp.buf.format({ async = true }) -end, {}) - - -local function on_attach(client, bufnr) - local filetype = vim.api.nvim_buf_get_option(0, "filetype") - -- keymaps for lsp - vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 }) - vim.keymap.set("n", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0 }) - vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0 }) - vim.keymap.set("n", "<leader>vo", ":LspRestart<cr>", { noremap = true }) - - telescope_mapper("gr", "lsp_references", nil, true) - telescope_mapper("<leader>pv", "find_symbol", nil, true) - telescope_mapper("<leader>pd", "lsp_document_symbols", nil, true) - telescope_mapper("<c-]>", "lsp_definitions", nil, true) - - vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" - - -- Attach any filetype specific options to the client - filetype_attach[filetype](client, bufnr) -end - --- Actual configs -local lsp_flags = { - debounce_text_changes = 150, -} - --- Server configurations - -lspconfig["rust_analyzer"].setup({ - on_attach = on_attach, - flags = lsp_flags, - -- Server-specific settings... - settings = { - ["rust-analyzer"] = {}, - }, -}) - -lspconfig.dockerls.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -lspconfig.phpactor.setup({ - on_attach = on_attach, - flags = lsp_flags, - filetypes = { "php", "cucumber" }, -}) - -lspconfig.jsonls.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) -lspconfig.html.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true - -lspconfig.emmet_ls.setup({ - on_attach = on_attach, - flags = lsp_flags, - capabilities = capabilities, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, -}) - -lspconfig.gopls.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -lspconfig.gdscript.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -lspconfig.tsserver.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -lspconfig.volar.setup({ - on_attach = on_attach, - flags = lsp_flags, -}) - -lspconfig["sumneko_lua"].setup({ - on_attach = on_attach, - flags = lsp_flags, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - }, - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - enable = false, - }, - }, - }, -}) diff --git a/after/plugin/mason.lua b/after/plugin/mason.lua deleted file mode 100644 index f3655c2..0000000 --- a/after/plugin/mason.lua +++ /dev/null @@ -1,62 +0,0 @@ -local ok, mason = pcall(require, "mason") -if not ok then - return -end - -local mason_lspconfig = require("mason-lspconfig") - -mason.setup({ - ui = { - icons = { - package_installed = "โ", - package_pending = "โ", - package_uninstalled = "โ", - }, - }, -}) - -mason_lspconfig.setup({ - automatic_installation = false, -}) - -require('mason-tool-installer').setup { - - -- a list of all tools you want to ensure are installed upon - -- start; they should be the names Mason uses for each tool - ensure_installed = { - "blade-formatter", - "dockerfile-language-server", - "emmet-ls", - "go-debug-adapter", - "golangci-lint", - "gopls", - "html-lsp", - "json-lsp", - "lua-language-server", - "php-debug-adapter", - "rust-analyzer", - "stylua", - "typescript-language-server", - "vue-language-server", - "phpactor", - "sql-formatter", - }, - - -- if set to true this will check each tool for updates. If updates - -- are available the tool will be updated. This setting does not - -- affect :MasonToolsUpdate or :MasonToolsInstall. - -- Default: false - auto_update = false, - - -- automatically install / update on startup. If set to false nothing - -- will happen on startup. You can use :MasonToolsInstall or - -- :MasonToolsUpdate to install tools and check for updates. - -- Default: true - run_on_start = true, - - -- set a delay (in ms) before the installation starts. This is only - -- effective if run_on_start is set to true. - -- e.g.: 5000 = 5 second delay, 10000 = 10 second delay, etc... - -- Default: 0 - start_delay = 3000, -- 3 second delay -} diff --git a/after/plugin/null-ls.lua b/after/plugin/null-ls.lua index b3bc7d1..7bccec2 100644 --- a/after/plugin/null-ls.lua +++ b/after/plugin/null-ls.lua @@ -7,19 +7,26 @@ local composer = require("composer") local php_actions = require("php-code-actions") local laravel_actions = require("laravel.code-actions") + +-- format and code actions for non lsp buffers +vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {}) +vim.keymap.set("n", "<leader>vf", function() + return vim.lsp.buf.format({ async = true }) +end, {}) + local sources = { - -- null_ls.builtins.code_actions.gitsigns, - null_ls.builtins.formatting.stylua, + null_ls.builtins.code_actions.gitsigns, + -- null_ls.builtins.formatting.stylua, -- null_ls.builtins.diagnostics.eslint, -- null_ls.builtins.formatting.phpcsfixer, - null_ls.builtins.diagnostics.golangci_lint, + -- null_ls.builtins.diagnostics.golangci_lint, -- null_ls.builtins.diagnostics.codespell.with({ -- args = { "--ignore-words-list", "crate" }, -- }), null_ls.builtins.formatting.jq, - null_ls.builtins.code_actions.gitrebase, + -- null_ls.builtins.code_actions.gitrebase, null_ls.builtins.code_actions.refactoring, - null_ls.builtins.formatting.sql_formatter, + -- null_ls.builtins.formatting.sql_formatter, php_actions.getter_setter, php_actions.file_creator, } |