From 09f3f5fe6caf1c0689f4d6885ab7a688d739ff38 Mon Sep 17 00:00:00 2001 From: Nikurasu Date: Mon, 26 Dec 2022 16:40:39 +0100 Subject: [PATCH] Fixed not working lsp shortcuts in neovim --- nvim/init.lua | 43 +----------------------------------- nvim/lua/plugins/mason.lua | 45 +++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index a646180..9cb09e1 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -86,50 +86,9 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist) local api = require("nvim-tree.api") vim.keymap.set('n', 'ft', api.tree.toggle) + require('plugins') --- LSP settings. --- This function gets run when an LSP connects to a particular buffer. -local on_attach = function(_, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end - - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end - - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') - nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') - - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') - - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') - - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, { desc = 'Format current buffer with LSP' }) -end - -- Setup neovim lua configuration -- require('neodev').setup() -- diff --git a/nvim/lua/plugins/mason.lua b/nvim/lua/plugins/mason.lua index c4e87f0..dda5baa 100644 --- a/nvim/lua/plugins/mason.lua +++ b/nvim/lua/plugins/mason.lua @@ -1,5 +1,48 @@ require('mason').setup() +-- LSP settings. +-- This function gets run when an LSP connects to a particular buffer. +--vim.keymap.set('n', 'rn', vim.lsp.buf.rename) +local on_attach = function(_, bufnr) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local nmap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end + + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end + + nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + + nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') + nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, { desc = 'Format current buffer with LSP' }) +end + local servers = { tsserver = {}, @@ -26,4 +69,4 @@ mason_lspconfig.setup_handlers { settings = servers[server_name], } end, -} \ No newline at end of file +}