-- ============================================================================= -- lsp.lua — LSP 语言服务器 -- ============================================================================= -- 【保留】你的完整 LSP 配置(lua_ls/bashls/clangd/neocmake/rust_analyzer)。 -- 【修改】🔧 on_attach 改为引用 config.keymaps 的 lsp_on_attach(统一管理键位); -- 🔧 diagnostic 配补 sign 图标和 float 边框。 return { -- Mason: 外部工具管理 { "williamboman/mason.nvim", cmd = "Mason", opts = { ui = { border = "rounded", -- ✅ 新增:圆角边框 icons = { package_installed = "✓", package_pending = "➜", package_uninstalled = "✗", }, }, }, }, -- Mason 与 LSP 桥接 { "williamboman/mason-lspconfig.nvim", dependencies = { "williamboman/mason.nvim" }, opts = { ensure_installed = { "lua_ls", "bashls", "clangd", "neocmake", }, automatic_installation = function(server_name) -- 🔧 保留你的逻辑:rust_analyzer 由 rustup 管理 return server_name ~= "rust_analyzer" end, }, }, -- LSP 配置 { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "saghen/blink.cmp", }, config = function() local caps = require("blink.cmp").get_lsp_capabilities() local keymaps = require("config.keymaps") -- ✅ 新增:诊断图标和样式 vim.diagnostic.config({ virtual_text = { prefix = "●", spacing = 4, }, signs = true, update_in_insert = false, severity_sort = true, float = { border = "rounded", source = "always", }, }) local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end -- LSP 附加时绑定键位 vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) -- 🔧 修改:使用统一 on_attach keymaps.lsp_on_attach(nil, args.buf) -- 保留你的 inlay hints 开启 vim.lsp.inlay_hint.enable(true, { bufnr = args.buf }) end, }) -- Lua vim.lsp.config['lua_ls'] = { cmd = { 'lua-language-server' }, filetypes = { 'lua' }, root_markers = { '.luarc.json', '.luarc.jsonc', '.git', 'init.lua' }, capabilities = caps, settings = { Lua = { runtime = { version = "LuaJIT" }, workspace = { checkThirdParty = false }, diagnostics = { globals = { "vim" } }, }, }, } -- Bash vim.lsp.config['bashls'] = { cmd = { 'bash-language-server', 'start' }, filetypes = { 'sh', 'bash' }, root_markers = { '.git' }, capabilities = caps, } -- C/C++ (clangd) vim.lsp.config['clangd'] = { cmd = { 'clangd' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, root_markers = { '.clangd', 'compile_commands.json', '.git' }, capabilities = caps, } -- CMake vim.lsp.config['neocmake'] = { cmd = { 'neocmakelsp', 'stdio' }, filetypes = { 'cmake' }, root_markers = { 'CMakeLists.txt', '.git' }, capabilities = caps, init_options = { format = { enable = true }, lint = { enable = true }, }, } -- Rust (rust-analyzer) vim.lsp.config['rust_analyzer'] = { cmd = { 'rust-analyzer' }, filetypes = { 'rust' }, root_markers = { 'Cargo.toml', '.git' }, capabilities = caps, settings = { ["rust-analyzer"] = { cargo = { allFeatures = true, loadOutDirsFromCheck = true, buildScripts = { enable = true }, }, checkOnSave = true, diagnostics = { enable = true }, procMacro = { enable = true }, files = { exclude = { ".direnv", ".git", ".jj", ".github", ".gitlab", "bin", "node_modules", "target", "venv", ".venv", }, watcher = "client", }, }, }, } vim.lsp.enable({ 'lua_ls', 'bashls', 'clangd', 'neocmake', 'rust_analyzer' }) end, }, }