* remove doc/tags

* use cmd instead of alias for clarity

* use alias and proper checking of existing command installation

* mason pkg name override

* we still want to enforce local by default

* remove unused on_attach since we have event to control it

* fallback to using existing docker language servers

* add yaml language server + remove table setup logging

* write comment what symbol we expect

* more notes

* use mason-lspconfig for getting lsp->mason map and better utilities

* use very lazy
This commit is contained in:
peturparkur 2025-08-03 18:23:21 +02:00 committed by GitHub
parent 115243d395
commit 2985d98684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 109 deletions

View file

@ -17,8 +17,8 @@ return {
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs and related tools to stdpath for Neovim
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
'williamboman/mason-lspconfig.nvim',
{ 'mason-org/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
'mason-org/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
-- Useful status updates for LSP.
@ -61,52 +61,6 @@ 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
-- 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 }),
@ -222,14 +176,16 @@ return {
severity_sort = true,
float = { border = 'rounded', source = 'if_many' },
underline = { severity = vim.diagnostic.severity.ERROR },
signs = vim.g.have_nerd_font and {
text = {
[vim.diagnostic.severity.ERROR] = '󰅚 ',
[vim.diagnostic.severity.WARN] = '󰀪 ',
[vim.diagnostic.severity.INFO] = '󰋽 ',
[vim.diagnostic.severity.HINT] = '󰌶 ',
},
} or {},
signs = vim.g.have_nerd_font
and {
text = {
[vim.diagnostic.severity.ERROR] = '󰅚 ', -- circle with cross
[vim.diagnostic.severity.WARN] = '󰀪 ', -- triangle warning
[vim.diagnostic.severity.INFO] = '󰋽 ', -- circle with i
[vim.diagnostic.severity.HINT] = '󰌶 ', -- lightbulb
},
}
or {},
virtual_text = {
source = 'if_many',
spacing = 2,
@ -268,40 +224,28 @@ return {
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.
-- require('mason-tool-installer').setup { ensure_installed = ensure_installed }
-- INFO: Using my own utils function instead of mason-lspconfig as it checks if the stuff is already installed
-- outside of mason. This is useful for NixOS setup where mason version just doesn't work sometimes due to libc issues.
-- We take the languages configured for a given profile
-- Given the profile we take the LSPs configured for the languages
-- Then we guarantee use or install the LSPs
local languages = require('utils.profile').Languages()
local languageServers = require 'utils.languages'
local tmpTable = {}
for _, lang in ipairs(languages) do
for lsp, config in pairs(languageServers[lang]) do
tmpTable[lsp] = config
end
end
require('utils.mason').install(tmpTable, true)
local lsp = require 'lspconfig'
for server, config in pairs(tmpTable) do
config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {})
config.on_attach = on_attach
lsp[server].setup(config)
end
local lsps = require('utils.profile').LanguageServers()
-- print(vim.inspect(lsps))
local missing_lsps = require('utils.mason').missing(lsps) -- find missing lsps
-- print(vim.inspect(missing_lsps))
missing_lsps = {} -- TODO: this is only for NixOS to prefer installing via nixpkgs instead of mason
-- 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,
-- },
-- }
-- install the executables of the language servers that we don't already have installed locally outside of mason
require('utils.mason').install(missing_lsps)
-- configure nvim lsp via lspconfig package for our list of lsps
local lspconfig = require 'lspconfig'
for server, config in pairs(lsps) do
config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {})
-- config.on_attach = on_attach -- we don't need this because of the events
lspconfig[server].setup(config)
end
end,
},
-- Show LSP explorer of functions and classes etc.