diff --git a/init.lua b/init.lua index bfab37c..8ee93fa 100644 --- a/init.lua +++ b/init.lua @@ -425,7 +425,7 @@ require('lazy').setup({ -- -- 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) + local map = function(keys, func, desc) vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end @@ -433,31 +433,31 @@ require('lazy').setup({ -- -- Jump to the definition of the word under your cursor. -- To jump back, press . - nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- Rename the variable under your cursor - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('rn', vim.lsp.buf.rename, '[R]e[n]ame') -- Execute a code action, usually your cursor needs to be on top of an error -- or a suggestion from your LSP for this to activate. - nmap('ca', function() + map('ca', function() vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } } end, '[C]ode [A]ction') -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + map('K', vim.lsp.buf.hover, 'Hover Documentation') -- Show the signature of the function you're currently completing. - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + map('', vim.lsp.buf.signature_help, 'Signature Documentation') end, }) @@ -473,7 +473,7 @@ require('lazy').setup({ -- Add any additional override configuration in the following tables. Available keys are: -- - cmd (table): Override the default command used to start the server -- - filetypes (table): Override the default list of associated filetypes for the server - -- - capabilities (table): TODO + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { @@ -482,6 +482,7 @@ require('lazy').setup({ -- pyright = {}, -- rust_analyzer = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, + -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- -- If you use something like typescript, where the tooling is as bad as the language, -- then you might need to install and configure something like this: @@ -498,20 +499,23 @@ require('lazy').setup({ Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, - -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- diagnostics = { disable = { 'missing-fields' } }, }, }, }, } + -- You can add other tools here that you want Mason to install + -- for you, so that they are available from within Neovim. + local ensure_installed = vim.tbl_keys(servers) + vim.list_extend(ensure_installed, { + 'stylua', + }) + -- Ensure the servers above are installed require('mason').setup() - - -- TODO: Think about lspconfig mason - local installed = { 'stylua' } - vim.list_extend(installed, vim.tbl_keys(servers)) - require('mason-tool-installer').setup { ensure_installed = installed } + require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { handlers = { function(server_name) @@ -520,9 +524,7 @@ require('lazy').setup({ cmd = server.cmd, settings = server.settings, filetypes = server.filetypes, - -- TODO: Think about what we wanna do here. - -- capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities), - capabilities = server.capabilities or capabilities, + capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities), } end, },