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*

View file

@ -49,7 +49,7 @@ return {
opts.sections.lualine_x,
2,
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
local status = require("copilot.status").data.status
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 "*",
},
},
event = "InsertEnter",
event = { "InsertEnter", "CmdlineEnter" },
---@module 'blink.cmp'
---@type blink.cmp.Config
@ -41,6 +41,7 @@ return {
return LazyVim.cmp.expand(snippet)
end,
},
appearance = {
-- sets the fallback highlight groups to nvim-cmp's highlight groups
-- useful for when your theme doesn't support blink.cmp
@ -50,6 +51,7 @@ return {
-- adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
},
completion = {
accept = {
-- experimental auto-brackets support
@ -82,7 +84,17 @@ return {
},
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 = {
@ -171,8 +183,9 @@ return {
"saghen/blink.cmp",
opts = {
sources = {
-- add lazydev to your completion providers
default = { "lazydev" },
per_filetype = {
lua = { inherit_defaults = true, "lazydev" },
},
providers = {
lazydev = {
name = "LazyDev",

View file

@ -25,6 +25,9 @@ return {
-- }
-- ```
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 })
local cmp = require("cmp")
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 = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
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",
vertical = "down:15,border-top",
hidden = "hidden",

View file

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

View file

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

View file

@ -91,6 +91,7 @@ return {
table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar))
end
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.
project_name = function(root_dir)
@ -164,10 +165,12 @@ return {
end
end
local function attach_jdtls()
local fname = vim.api.nvim_buf_get_name(0)
-- Configuration can be augmented and overridden by opts.jdtls
local config = extend_or_override({
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 = {
bundles = bundles,
},

View file

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

View file

@ -27,7 +27,7 @@ return {
end
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
local formatter = LazyVim.lsp.formatter({

View file

@ -31,19 +31,21 @@ return {
vim.list_extend(installed, install)
end
-- backwards compatibility with the old treesitter config for indent
if vim.tbl_get(opts, "indent", "enable") then
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
-- backwards compatibility with the old treesitter config for highlight
if vim.tbl_get(opts, "highlight", "enable") then
-- backwards compatibility with the old treesitter config for highlight and indent
local highlight, indent = vim.tbl_get(opts, "highlight", "enable"), vim.tbl_get(opts, "indent", "enable")
if highlight or indent then
vim.api.nvim_create_autocmd("FileType", {
callback = function(ev)
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)
end
if indent then
vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end,
})
end

View file

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

View file

@ -51,7 +51,7 @@ function M.has(buffer, method)
return false
end
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
if client:supports_method(method) then
return true
@ -68,7 +68,7 @@ function M.resolve(buffer)
end
local spec = vim.tbl_extend("force", {}, M.get())
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
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
vim.list_extend(spec, maps)

View file

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

View file

@ -29,10 +29,10 @@ function M.detectors.lsp(buf)
return {}
end
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)
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
local workspace = client.config.workspace_folders
for _, ws in pairs(workspace or {}) do