fix(nvim): migrate to Neovim 0.12 compatible APIs

- lsp: replace deprecated require('lspconfig') with vim.lsp.config +
  vim.lsp.enable (native Neovim 0.11+ API)
- lsp: replace removed mason-lspconfig setup_handlers with
  get_installed_servers() loop
- lsp: fix client.supports_method -> client:supports_method (colon syntax)
- lsp: replace jsonls on_new_config with inline pcall schemastore loading
- ui: disable lang='vim' in noice cmdline to fix treesitter 'tab' node
  error on Neovim 0.12 (vim grammar removed 'tab' node type)
- ui: extend noice route filter to cover both msg_show and notify events

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-08 14:52:45 +08:00
parent 6fd5d96043
commit ed9800ce66
2 changed files with 35 additions and 30 deletions

View File

@@ -155,18 +155,14 @@ return {
-- ts_ls 由 typescript-tools.nvim 接管,此处不配置
eslint = {},
jsonls = {
-- 延迟加载 schemastore插件安装后才可用
on_new_config = function(new_config)
new_config.settings = new_config.settings or {}
new_config.settings.json = new_config.settings.json or {}
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
local ok, schemastore = pcall(require, "schemastore")
if ok then
vim.list_extend(new_config.settings.json.schemas, schemastore.json.schemas())
end
end,
settings = {
json = { validate = { enable = true } },
json = {
validate = { enable = true },
schemas = (function()
local ok, schemastore = pcall(require, "schemastore")
return ok and schemastore.json.schemas() or {}
end)(),
},
},
},
yamlls = {},
@@ -215,7 +211,7 @@ return {
map("n", "<leader>cd", function() vim.diagnostic.open_float() end, "行诊断")
-- Inlay hints 切换
if client and client.supports_method("textDocument/inlayHint") then
if client and client:supports_method("textDocument/inlayHint") then
map("n", "<leader>uh", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = buf }), { bufnr = buf })
end, "切换 Inlay Hints")
@@ -226,21 +222,22 @@ return {
-- 构建 capabilitiesblink.cmp 提供)
local capabilities = require("blink.cmp").get_lsp_capabilities()
-- 通过 mason-lspconfig 自动启动服务器
require("mason-lspconfig").setup_handlers({
function(server)
local server_opts = vim.tbl_deep_extend("force", {
capabilities = vim.deepcopy(capabilities),
}, opts.servers[server] or {})
-- 通过 mason-lspconfig 自动启动服务器(使用原生 vim.lsp.config API
local mlsp = require("mason-lspconfig")
for _, server in ipairs(mlsp.get_installed_servers()) do
-- Rust 由 rustaceanvim 接管,跳过
if server == "rust_analyzer" then goto continue end
-- TypeScript 由 typescript-tools.nvim 接管,跳过
if server == "ts_ls" or server == "tsserver" then goto continue end
-- Rust 由 rustaceanvim 接管,跳过
if server == "rust_analyzer" then return end
-- TypeScript 由 typescript-tools.nvim 接管,跳过
if server == "ts_ls" or server == "tsserver" then return end
local server_opts = vim.tbl_deep_extend("force", {
capabilities = vim.deepcopy(capabilities),
}, opts.servers[server] or {})
require("lspconfig")[server].setup(server_opts)
end,
})
vim.lsp.config(server, server_opts)
vim.lsp.enable(server)
::continue::
end
end,
},

View File

@@ -241,15 +241,23 @@ return {
signature = { enabled = false }, -- blink.cmp 处理签名
progress = { enabled = true, format_done = "" },
},
-- 禁用 vim 命令行的 treesitter 语法高亮Neovim 0.12 的 vim grammar 移除了 "tab" 节点类型)
cmdline = {
format = {
cmdline = { pattern = "^:", icon = "" },
},
},
routes = {
{
-- 屏蔽 treesitter query 字段兼容性警告(Neovim 0.12 校验更严格,功能不受影响
-- 屏蔽 treesitter query 兼容性警告(msg_show 和 notify 两种来源
filter = {
event = "msg_show",
any = {
{ find = "Invalid field name" },
{ find = "Invalid node type" },
{ find = "Query error" },
{ event = "msg_show", find = "Query error" },
{ event = "msg_show", find = "Invalid field name" },
{ event = "msg_show", find = "Invalid node type" },
{ event = "notify", find = "Query error" },
{ event = "notify", find = "Invalid field name" },
{ event = "notify", find = "Invalid node type" },
},
},
opts = { skip = true },