feat(nvim): switch virtual_lines

This commit is contained in:
2025-05-04 10:58:47 +08:00
parent bf1539e914
commit 27041ff1fa

View File

@@ -37,7 +37,10 @@ local extra_config = {
settings = {
rust_analyzer = {
check = {
command = "clippy"
command = "cargo clippy"
},
diagnostics = {
experimental = true,
},
formatting = {
command = { "rustfmt" },
@@ -47,22 +50,6 @@ local extra_config = {
},
}
local on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = "rounded",
source = "always",
prefix = " ",
scope = "line",
}
vim.diagnostic.open_float(nil, opts)
end,
})
end
local capabilities = require("cmp_nvim_lsp").default_capabilities()
capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
@@ -73,7 +60,6 @@ local lspconfig = require("lspconfig")
for _, server in ipairs(servers) do
local extra = extra_config[server] or {}
local config = {
on_attach = on_attach,
capabilities = capabilities
}
for k, v in pairs(extra) do
@@ -82,7 +68,29 @@ for _, server in ipairs(servers) do
lspconfig[server].setup(config)
end
vim.diagnostic.config({
virtual_lines = true
})
local diag_config1 = {
virtual_text = {
severity = {
max = vim.diagnostic.severity.WARN,
},
},
virtual_lines = {
severity = {
min = vim.diagnostic.severity.ERROR,
},
},
}
local diag_config2 = {
virtual_text = true,
virtual_lines = false,
}
vim.diagnostic.config(diag_config1)
local diag_config_basic = false
vim.keymap.set("n", "<leader>ll", function()
diag_config_basic = not diag_config_basic
if diag_config_basic then
vim.diagnostic.config(diag_config2)
else
vim.diagnostic.config(diag_config1)
end
end, { desc = "Toggle diagnostic virtual_lines" })