From: Ruben Beltran del Rio Date: Sun, 24 Sep 2023 20:30:22 +0000 (+0200) Subject: Start replacing CoC with neovim's LSP support X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/commitdiff_plain/73a2d9946ff469afa1a1a30edb1aa350032bb44c Start replacing CoC with neovim's LSP support --- diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 9395a00..1b5fda9 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -84,24 +84,7 @@ vim.keymap.set("n", "", -- Svelte Config vim.g.vim_svelte_plugin_use_typescript = true --- CoC -vim.keymap.set('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true, silent = true}) -vim.keymap.set('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true, silent = true}) -vim.keymap.set('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true, silent = true}) -vim.keymap.set('i', '', 'coc#refresh()', {expr = true, silent = true}) -vim.keymap.set('n', 'K', ':call CocActionAsync("doHover")', {silent = true}) - -vim.keymap.set('n', '[g', '(coc-diagnostic-prev)', {silent = true}) -vim.keymap.set('n', ']g', '(coc-diagnostic-next)', {silent = true}) - -vim.keymap.set('n', 'gd', '(coc-definition)', {silent = true}) -vim.keymap.set('n', 'gy', '(coc-type-definition)', {silent = true}) -vim.keymap.set('n', 'gi', '(coc-implementation)', {silent = true}) -vim.keymap.set('n', 'gr', '(coc-references)', {silent = true}) - -vim.keymap.set('n', 'd', function() - require("dapui").toggle() -end) - -- Plugins require('plugins') +require('lsp') +require('dap_config') diff --git a/config/nvim/lua/dap_config.lua b/config/nvim/lua/dap_config.lua index 446315a..2131958 100644 --- a/config/nvim/lua/dap_config.lua +++ b/config/nvim/lua/dap_config.lua @@ -1,4 +1,9 @@ local dap = require('dap') +require("dapui").setup() + +vim.keymap.set('n', 'd', function() + require("dapui").toggle() +end) dap.adapters.node2 = { type = 'executable', @@ -110,3 +115,4 @@ dap.configurations.python = { require('neodev').setup({ library = { plugins = { "nvim-dap-ui" }, types = true } }) + diff --git a/config/nvim/lua/lsp.lua b/config/nvim/lua/lsp.lua new file mode 100644 index 0000000..eb8b98f --- /dev/null +++ b/config/nvim/lua/lsp.lua @@ -0,0 +1,60 @@ +local lspconfig = require('lspconfig') +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + +lspconfig.tsserver.setup {} +lspconfig.eslint.setup{} +lspconfig.svelte.setup{} +lspconfig.pyright.setup {} +lspconfig.dartls.setup{} +lspconfig.rust_analyzer.setup { + -- Server-specific settings. See `:help lspconfig-setup` + settings = { + ['rust-analyzer'] = {}, + }, +} +lspconfig.cssls.setup { + capabilities = capabilities, +} +lspconfig.html.setup { + capabilities = capabilities, +} +lspconfig.lua_ls.setup{} + +-- Global mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +vim.keymap.set('n', 'e', vim.diagnostic.open_float) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + +-- Use LspAttach autocommand to only map the following keys +-- after the language server attaches to the current buffer +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, +}) diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index 971c441..c4e313a 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -61,8 +61,6 @@ require('lazy').setup({ 'ziglang/zig.vim', -- Debugging - 'neovim/nvim-lspconfig', - 'folke/neodev.nvim', 'mfussenegger/nvim-dap', 'rcarriga/nvim-dap-ui', @@ -71,12 +69,12 @@ require('lazy').setup({ 'rstacruz/vim-closer', 'michaeljsmith/vim-indent-object', + -- LSP + 'neovim/nvim-lspconfig', + 'folke/neodev.nvim', + -- Tools - {'neoclide/coc.nvim', branch='release'}, 'vim-scripts/LargeFile', 'tpope/vim-fugitive', 'milkypostman/vim-togglelist' }) - -require('dap_config') -require("dapui").setup()