Merge branch 'main' into dev

This commit is contained in:
chuyanlong 2025-09-17 09:02:13 +08:00
commit 4221caf01c
15 changed files with 80 additions and 69 deletions

View file

@ -1,4 +1,4 @@
*LazyVim.txt* For Neovim Last change: 2025 September 15 *LazyVim.txt* For Neovim Last change: 2025 September 16
============================================================================== ==============================================================================
Table of Contents *LazyVim-table-of-contents* Table of Contents *LazyVim-table-of-contents*

View file

@ -49,7 +49,7 @@ return {
opts.sections.lualine_x, opts.sections.lualine_x,
2, 2,
LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function() LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function()
local clients = package.loaded["copilot"] and LazyVim.lsp.get_clients({ name = "copilot", bufnr = 0 }) or {} local clients = package.loaded["copilot"] and vim.lsp.get_clients({ name = "copilot", bufnr = 0 }) or {}
if #clients > 0 then if #clients > 0 then
local status = require("copilot.status").data.status local status = require("copilot.status").data.status
return (status == "InProgress" and "pending") or (status == "Warning" and "error") or "ok" return (status == "InProgress" and "pending") or (status == "Warning" and "error") or "ok"

View file

@ -31,7 +31,7 @@ return {
version = not vim.g.lazyvim_blink_main and "*", version = not vim.g.lazyvim_blink_main and "*",
}, },
}, },
event = "InsertEnter", event = { "InsertEnter", "CmdlineEnter" },
---@module 'blink.cmp' ---@module 'blink.cmp'
---@type blink.cmp.Config ---@type blink.cmp.Config
@ -41,6 +41,7 @@ return {
return LazyVim.cmp.expand(snippet) return LazyVim.cmp.expand(snippet)
end, end,
}, },
appearance = { appearance = {
-- sets the fallback highlight groups to nvim-cmp's highlight groups -- sets the fallback highlight groups to nvim-cmp's highlight groups
-- useful for when your theme doesn't support blink.cmp -- useful for when your theme doesn't support blink.cmp
@ -50,6 +51,7 @@ return {
-- adjusts spacing to ensure icons are aligned -- adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono", nerd_font_variant = "mono",
}, },
completion = { completion = {
accept = { accept = {
-- experimental auto-brackets support -- experimental auto-brackets support
@ -82,7 +84,17 @@ return {
}, },
cmdline = { cmdline = {
enabled = false, enabled = true,
keymap = { preset = "cmdline" },
completion = {
list = { selection = { preselect = false } },
menu = {
auto_show = function(ctx)
return vim.fn.getcmdtype() == ":"
end,
},
ghost_text = { enabled = true },
},
}, },
keymap = { keymap = {
@ -171,8 +183,9 @@ return {
"saghen/blink.cmp", "saghen/blink.cmp",
opts = { opts = {
sources = { sources = {
-- add lazydev to your completion providers per_filetype = {
default = { "lazydev" }, lua = { inherit_defaults = true, "lazydev" },
},
providers = { providers = {
lazydev = { lazydev = {
name = "LazyDev", name = "LazyDev",

View file

@ -25,6 +25,9 @@ return {
-- } -- }
-- ``` -- ```
opts = function() opts = function()
-- Register nvim-cmp lsp capabilities
vim.lsp.config("*", { capabilities = require("cmp_nvim_lsp").default_capabilities() })
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
local cmp = require("cmp") local cmp = require("cmp")
local defaults = require("cmp.config.default")() local defaults = require("cmp.config.default")()

View file

@ -122,7 +122,7 @@ return {
-- height is number of items minus 15 lines for the preview, with a max of 80% screen height -- height is number of items minus 15 lines for the preview, with a max of 80% screen height
height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16, height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
width = 0.5, width = 0.5,
preview = not vim.tbl_isempty(LazyVim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) and { preview = not vim.tbl_isempty(vim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) and {
layout = "vertical", layout = "vertical",
vertical = "down:15,border-top", vertical = "down:15,border-top",
hidden = "hidden", hidden = "hidden",

View file

@ -30,34 +30,39 @@ return {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
}, },
keys = { keys = {
{ "<leader>r", "", desc = "+refactor", mode = { "n", "v" } }, { "<leader>r", "", desc = "+refactor", mode = { "n", "x" } },
{ {
"<leader>rs", "<leader>rs",
pick, pick,
mode = "v", mode = { "n", "x" },
desc = "Refactor", desc = "Refactor",
}, },
{ {
"<leader>ri", "<leader>ri",
function() function()
require("refactoring").refactor("Inline Variable") return require("refactoring").refactor("Inline Variable")
end, end,
mode = { "n", "v" }, mode = { "n", "x" },
desc = "Inline Variable", desc = "Inline Variable",
expr = true,
}, },
{ {
"<leader>rb", "<leader>rb",
function() function()
require("refactoring").refactor("Extract Block") return require("refactoring").refactor("Extract Block")
end, end,
mode = { "n", "x" },
desc = "Extract Block", desc = "Extract Block",
expr = true,
}, },
{ {
"<leader>rf", "<leader>rf",
function() function()
require("refactoring").refactor("Extract Block To File") return require("refactoring").refactor("Extract Block To File")
end, end,
mode = { "n", "x" },
desc = "Extract Block To File", desc = "Extract Block To File",
expr = true,
}, },
{ {
"<leader>rP", "<leader>rP",
@ -71,6 +76,7 @@ return {
function() function()
require("refactoring").debug.print_var({ normal = true }) require("refactoring").debug.print_var({ normal = true })
end, end,
mode = { "n", "x" },
desc = "Debug Print Variable", desc = "Debug Print Variable",
}, },
{ {
@ -83,33 +89,36 @@ return {
{ {
"<leader>rf", "<leader>rf",
function() function()
require("refactoring").refactor("Extract Function") return require("refactoring").refactor("Extract Function")
end, end,
mode = "v", mode = { "n", "x" },
desc = "Extract Function", desc = "Extract Function",
expr = true,
}, },
{ {
"<leader>rF", "<leader>rF",
function() function()
require("refactoring").refactor("Extract Function To File") return require("refactoring").refactor("Extract Function To File")
end, end,
mode = "v", mode = { "n", "x" },
desc = "Extract Function To File", desc = "Extract Function To File",
expr = true,
}, },
{ {
"<leader>rx", "<leader>rx",
function() function()
require("refactoring").refactor("Extract Variable") return require("refactoring").refactor("Extract Variable")
end, end,
mode = "v", mode = { "n", "x" },
desc = "Extract Variable", desc = "Extract Variable",
expr = true,
}, },
{ {
"<leader>rp", "<leader>rp",
function() function()
require("refactoring").debug.print_var() require("refactoring").debug.print_var()
end, end,
mode = "v", mode = { "n", "x" },
desc = "Debug Print Variable", desc = "Debug Print Variable",
}, },
}, },

View file

@ -70,7 +70,7 @@ return {
"luc-tielen/telescope_hoogle", "luc-tielen/telescope_hoogle",
ft = { "haskell", "lhaskell", "cabal", "cabalproject" }, ft = { "haskell", "lhaskell", "cabal", "cabalproject" },
dependencies = { dependencies = {
{ "nvim-telescope/telescope.nvim" }, { "nvim-telescope/telescope.nvim", optional = true },
}, },
config = function() config = function()
local ok, telescope = pcall(require, "telescope") local ok, telescope = pcall(require, "telescope")

View file

@ -91,6 +91,7 @@ return {
table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar)) table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar))
end end
return { return {
root_dir = require("lspconfig.util").root_pattern(vim.lsp.config.jdtls.root_markers),
-- How to find the project name for a given root dir. -- How to find the project name for a given root dir.
project_name = function(root_dir) project_name = function(root_dir)
@ -164,10 +165,12 @@ return {
end end
end end
local function attach_jdtls() local function attach_jdtls()
local fname = vim.api.nvim_buf_get_name(0)
-- Configuration can be augmented and overridden by opts.jdtls -- Configuration can be augmented and overridden by opts.jdtls
local config = extend_or_override({ local config = extend_or_override({
cmd = opts.full_cmd(opts), cmd = opts.full_cmd(opts),
root_dir = vim.fs.root(0, vim.lsp.config.jdtls.root_markers), root_dir = opts.root_dir(fname),
init_options = { init_options = {
bundles = bundles, bundles = bundles,
}, },

View file

@ -26,15 +26,12 @@ return {
"reason", "reason",
"dune", "dune",
}, },
root_markers = { root_dir = function(bufnr, on_dir)
"*.opam", local util = require("lspconfig.util")
"esy.json", local fname = vim.api.nvim_buf_get_name(bufnr)
"package.json", --stylua: ignore
".git", on_dir(util.root_pattern("*.opam", "esy.json", "package.json", ".git", "dune-project", "dune-workspace", "*.ml")( fname))
"dune-project", end,
"dune-workspace",
"*.ml",
},
}, },
}, },
}, },

View file

@ -27,7 +27,7 @@ return {
end end
local function get_client(buf) local function get_client(buf)
return LazyVim.lsp.get_clients({ name = "eslint", bufnr = buf })[1] return vim.lsp.get_clients({ name = "eslint", bufnr = buf })[1]
end end
local formatter = LazyVim.lsp.formatter({ local formatter = LazyVim.lsp.formatter({

View file

@ -31,19 +31,21 @@ return {
vim.list_extend(installed, install) vim.list_extend(installed, install)
end end
-- backwards compatibility with the old treesitter config for indent -- backwards compatibility with the old treesitter config for highlight and indent
if vim.tbl_get(opts, "indent", "enable") then local highlight, indent = vim.tbl_get(opts, "highlight", "enable"), vim.tbl_get(opts, "indent", "enable")
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" if highlight or indent then
end
-- backwards compatibility with the old treesitter config for highlight
if vim.tbl_get(opts, "highlight", "enable") then
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
callback = function(ev) callback = function(ev)
local lang = vim.treesitter.language.get_lang(ev.match) local lang = vim.treesitter.language.get_lang(ev.match)
if vim.tbl_contains(installed, lang) then if not vim.tbl_contains(installed, lang) then
return
end
if highlight then
pcall(vim.treesitter.start) pcall(vim.treesitter.start)
end end
if indent then
vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end, end,
}) })
end end

View file

@ -63,7 +63,7 @@ return {
timeout_ms = nil, timeout_ms = nil,
}, },
-- LSP Server Settings -- LSP Server Settings
---@type table<string, vim.lsp.Config> ---@type table<string, vim.lsp.Config|{mason?:boolean, enabled?:boolean}|boolean>
servers = { servers = {
lua_ls = { lua_ls = {
-- mason = false, -- set to false if you don't want this server to be installed with mason -- mason = false, -- set to false if you don't want this server to be installed with mason
@ -163,14 +163,9 @@ return {
end end
vim.diagnostic.config(vim.deepcopy(opts.diagnostics)) vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
local capabilities = vim.tbl_deep_extend( if opts.capabilities then
"force", vim.lsp.config("*", { capabilities = opts.capabilities })
{}, end
vim.lsp.protocol.make_client_capabilities(),
LazyVim.has("nvim-cmp") and require("cmp_nvim_lsp").default_capabilities() or {},
LazyVim.has("blink.nvim") and require("blink.cmp").get_lsp_capabilities() or {},
opts.capabilities or {}
)
-- get all the servers that are available through mason-lspconfig -- get all the servers that are available through mason-lspconfig
local have_mason = LazyVim.has("mason-lspconfig.nvim") local have_mason = LazyVim.has("mason-lspconfig.nvim")
@ -181,9 +176,7 @@ return {
local exclude_automatic_enable = {} ---@type string[] local exclude_automatic_enable = {} ---@type string[]
local function configure(server) local function configure(server)
local server_opts = vim.tbl_deep_extend("force", { local server_opts = opts.servers[server] or {}
capabilities = vim.deepcopy(capabilities),
}, opts.servers[server] or {})
local setup = opts.setup[server] or opts.setup["*"] local setup = opts.setup[server] or opts.setup["*"]
if setup and setup(server, server_opts) then if setup and setup(server, server_opts) then

View file

@ -51,7 +51,7 @@ function M.has(buffer, method)
return false return false
end end
method = method:find("/") and method or "textDocument/" .. method method = method:find("/") and method or "textDocument/" .. method
local clients = LazyVim.lsp.get_clients({ bufnr = buffer }) local clients = vim.lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
if client:supports_method(method) then if client:supports_method(method) then
return true return true
@ -68,7 +68,7 @@ function M.resolve(buffer)
end end
local spec = vim.tbl_extend("force", {}, M.get()) local spec = vim.tbl_extend("force", {}, M.get())
local opts = LazyVim.opts("nvim-lspconfig") local opts = LazyVim.opts("nvim-lspconfig")
local clients = LazyVim.lsp.get_clients({ bufnr = buffer }) local clients = vim.lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {} local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
vim.list_extend(spec, maps) vim.list_extend(spec, maps)

View file

@ -1,15 +1,6 @@
---@class lazyvim.util.lsp ---@class lazyvim.util.lsp
local M = {} local M = {}
---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: vim.lsp.Client):boolean}
---@param opts? lsp.Client.filter
function M.get_clients(opts)
local ret = {} ---@type vim.lsp.Client[]
ret = vim.lsp.get_clients(opts)
return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret
end
---@param on_attach fun(client:vim.lsp.Client, buffer) ---@param on_attach fun(client:vim.lsp.Client, buffer)
---@param name? string ---@param name? string
function M.on_attach(on_attach, name) function M.on_attach(on_attach, name)
@ -107,12 +98,12 @@ function M.on_supports_method(method, fn)
}) })
end end
---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)} ---@param opts? LazyFormatter| {filter?: (string|vim.lsp.get_clients.Filter)}
function M.formatter(opts) function M.formatter(opts)
opts = opts or {} opts = opts or {}
local filter = opts.filter or {} local filter = opts.filter or {}
filter = type(filter) == "string" and { name = filter } or filter filter = type(filter) == "string" and { name = filter } or filter
---@cast filter lsp.Client.filter ---@cast filter vim.lsp.get_clients.Filter
---@type LazyFormatter ---@type LazyFormatter
local ret = { local ret = {
name = "LSP", name = "LSP",
@ -122,7 +113,7 @@ function M.formatter(opts)
M.format(LazyVim.merge({}, filter, { bufnr = buf })) M.format(LazyVim.merge({}, filter, { bufnr = buf }))
end, end,
sources = function(buf) sources = function(buf)
local clients = M.get_clients(LazyVim.merge({}, filter, { bufnr = buf })) local clients = vim.lsp.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))
---@param client vim.lsp.Client ---@param client vim.lsp.Client
local ret = vim.tbl_filter(function(client) local ret = vim.tbl_filter(function(client)
return client:supports_method("textDocument/formatting") return client:supports_method("textDocument/formatting")
@ -137,7 +128,7 @@ function M.formatter(opts)
return LazyVim.merge(ret, opts) --[[@as LazyFormatter]] return LazyVim.merge(ret, opts) --[[@as LazyFormatter]]
end end
---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | lsp.Client.filter ---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | vim.lsp.get_clients.Filter
---@param opts? lsp.Client.format ---@param opts? lsp.Client.format
function M.format(opts) function M.format(opts)

View file

@ -29,10 +29,10 @@ function M.detectors.lsp(buf)
return {} return {}
end end
local roots = {} ---@type string[] local roots = {} ---@type string[]
local clients = LazyVim.lsp.get_clients({ bufnr = buf }) local clients = vim.lsp.get_clients({ bufnr = buf })
clients = vim.tbl_filter(function(client) clients = vim.tbl_filter(function(client)
return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name) return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name)
end, clients) end, clients) --[[@as vim.lsp.Client[] ]]
for _, client in pairs(clients) do for _, client in pairs(clients) do
local workspace = client.config.workspace_folders local workspace = client.config.workspace_folders
for _, ws in pairs(workspace or {}) do for _, ws in pairs(workspace or {}) do