configure lsps directly instead of with mason

pull/1705/head
peturparkur 1 year ago
parent 3f99900ede
commit a7ebd6fde7

@ -46,6 +46,58 @@ return {
-- That is to say, every time a new file is opened that is associated with
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
-- function will be executed to configure the current buffer
local on_attach = function(_, buffr)
local kset = function(key, func, buffer, desc)
vim.keymap.set('n', key, func, { buffer = buffer, desc = 'LSP: ' .. desc })
end
print('Called on attach', _)
for k, v in pairs(_) do
print(k, v)
end
-- Jump to the definition of the word under your cursor.
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-t>.
kset('gd', require('telescope.builtin').lsp_definitions, buffr, '[G]oto [D]efinition')
-- Find references for the word under your cursor.
kset('gr', require('telescope.builtin').lsp_references, buffr, '[G]oto [R]eferences')
-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
kset('gI', require('telescope.builtin').lsp_implementations, buffr, '[G]oto [I]mplementation')
-- Jump to the type of the word under your cursor.
-- Useful when you're not sure what type a variable is and you want to see
-- the definition of its *type*, not where it was *defined*.
kset('<leader>D', require('telescope.builtin').lsp_type_definitions, buffr, 'Type [D]efinition')
-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
kset('<leader>ds', require('telescope.builtin').lsp_document_symbols, buffr, '[D]ocument [S]ymbols')
-- Fuzzy find all the symbols in your current workspace.
-- Similar to document symbols, except searches over your entire project.
kset('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, buffr, '[W]orkspace [S]ymbols')
-- Rename the variable under your cursor.
-- Most Language Servers support renaming across files, etc.
kset('<leader>rn', vim.lsp.buf.rename, buffr, '[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.
kset('<leader>ca', vim.lsp.buf.code_action, buffr, '[C]ode [A]ction')
-- Opens a popup that displays documentation about the word under your cursor
-- See `:help K` for why this keymap.
kset('K', vim.lsp.buf.hover, buffr, 'Hover Documentation')
-- WARN: This is not Goto Definition, this is Goto Declaration.
-- For example, in C this would take you to the header.
kset('gD', vim.lsp.buf.declaration, buffr, '[G]oto [D]eclaration')
end
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
@ -216,7 +268,7 @@ return {
-- :Mason
--
-- You can press `g?` for help in this menu.
require('mason').setup()
-- require('mason').setup()
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.
@ -237,18 +289,27 @@ return {
-- "nil",
}
require('mason-lspconfig').setup {
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for tsserver)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
end,
},
}
local lsp = require 'lspconfig'
for server, config in pairs(servers) do
print(server)
config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {})
config.on_attach = on_attach
lsp[server].setup(config)
end
-- require('mason-lspconfig').setup {
-- handlers = {
-- function(server_name)
-- local server = servers[server_name] or {}
-- -- This handles overriding only values explicitly passed
-- -- by the server configuration above. Useful when disabling
-- -- certain features of an LSP (for example, turning off formatting for tsserver)
-- server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
-- require('lspconfig')[server_name].setup(server)
-- end,
-- },
-- }
end,
},
-- Show LSP explorer of functions and classes etc.

Loading…
Cancel
Save