local gh = require('kickstart.util').gh -- Status updates for LSP vim.pack.add { gh 'j-hui/fidget.nvim' } require('fidget').setup {} -- LspAttach: per-buffer LSP keymaps and inlay hints vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), callback = function(event) local map = function(keys, func, desc, mode) mode = mode or 'n' vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end map('grn', vim.lsp.buf.rename, '[R]e[n]ame') map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- Highlight references on cursor hold local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client:supports_method('textDocument/documentHighlight', event.buf) then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) vim.api.nvim_create_autocmd('LspDetach', { group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } end, }) end -- Inlay hints toggle if client and client:supports_method('textDocument/inlayHint', event.buf) then map('th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') end end, }) -- Language servers ---@type table local servers = { gopls = {}, pyright = {}, terraformls = {}, ansiblels = {}, jinja_lsp = {}, powershell_es = { bundle_path = vim.fn.stdpath('data') .. '/mason/packages/powershell-editor-services', }, stylua = {}, lua_ls = { on_init = function(client) client.server_capabilities.documentFormattingProvider = false if client.workspace_folders then local path = client.workspace_folders[1].name if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end end client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { runtime = { version = 'LuaJIT', path = { 'lua/?.lua', 'lua/?/init.lua' }, }, workspace = { checkThirdParty = false, library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { '${3rd}/luv/library', '${3rd}/busted/library', }), }, }) end, settings = { Lua = { format = { enable = true }, }, }, }, } -- Mason: LSP installer and manager vim.pack.add { gh 'neovim/nvim-lspconfig', gh 'mason-org/mason.nvim', gh 'mason-org/mason-lspconfig.nvim', gh 'WhoIsSethDaniel/mason-tool-installer.nvim', } require('mason').setup {} local ensure_installed = vim.tbl_keys(servers or {}) require('mason-tool-installer').setup { ensure_installed = ensure_installed } -- Enable all configured servers for name, server in pairs(servers) do vim.lsp.config(name, server) vim.lsp.enable(name) end