From 39a2d68c8ca1a33d446a577f5f8250e39b363a1d Mon Sep 17 00:00:00 2001 From: maye Date: Thu, 4 Sep 2025 11:04:51 +0800 Subject: [PATCH] misc: update lsp config --- lua/commons/init.lua | 3 ++ lua/lsp/bacon-ls.lua | 2 ++ lua/lsp/basedpyright.lua | 28 ++++++++++++++++ lua/lsp/clangd.lua | 33 +++++++++++++++++++ lua/lsp/gopls.lua | 18 ++++++++-- lua/lsp/{pyright.lua => pyright.lua.bak} | 0 ...ust_analyzer.lua => rust_analyzer.lua.bak} | 0 lua/lsp/yamlls.lua | 24 ++++++++++++++ lua/plugins/snacks.lua | 3 ++ 9 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 lua/lsp/bacon-ls.lua create mode 100644 lua/lsp/basedpyright.lua create mode 100644 lua/lsp/clangd.lua rename lua/lsp/{pyright.lua => pyright.lua.bak} (100%) rename lua/lsp/{rust_analyzer.lua => rust_analyzer.lua.bak} (100%) create mode 100644 lua/lsp/yamlls.lua diff --git a/lua/commons/init.lua b/lua/commons/init.lua index c6d0b54..4437914 100644 --- a/lua/commons/init.lua +++ b/lua/commons/init.lua @@ -15,6 +15,9 @@ local M = { return false end, }, + lsp_servers = { + "goimports", "gofumpt", "basedpyright" + } } return M diff --git a/lua/lsp/bacon-ls.lua b/lua/lsp/bacon-ls.lua new file mode 100644 index 0000000..0dca34d --- /dev/null +++ b/lua/lsp/bacon-ls.lua @@ -0,0 +1,2 @@ +---@type vim.lsp.Config +return {} diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua new file mode 100644 index 0000000..7af0faa --- /dev/null +++ b/lua/lsp/basedpyright.lua @@ -0,0 +1,28 @@ +return { + -- File types that should automatically attach this LSP server + filetypes = { "python" }, + + -- Root directory markers - LSP will search for these files/directories + -- to determine the project root. Nested arrays indicate equal priority. + -- The first match wins within each priority level. + root_markers = { + "pyproject.toml", + "setup.py", + "setup.cfg", + "requirements.txt", + "pyrightconfig.json", + ".git", + ".hg", + }, + + -- Server-specific settings (varies by language server) + -- Check your language server's documentation for available options + settings = { + python = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + }, + }, + }, +} diff --git a/lua/lsp/clangd.lua b/lua/lsp/clangd.lua new file mode 100644 index 0000000..bc2fff5 --- /dev/null +++ b/lua/lsp/clangd.lua @@ -0,0 +1,33 @@ +---@type vim.lsp.Config +return { + keys = { + { "ch", "ClangdSwitchSourceHeader", desc = "Switch Source/Header (C/C++)" }, + }, + root_dir = function(name) + return require("lspconfig.util").root_pattern( + "Makefile", + "configure.ac", + "configure.in", + "config.h.in", + "meson.build", + "meson_options.txt", + "build.ninja" + )(fname) or require("lspconfig.util").root_pattern("compile_commands.json", "compile_flags.txt")(fname) or require( + "lspconfig.util" + ).find_git_ancestor(name) + end, + cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--header-insertion=iwyu", + "--completion-arg-placeholders", + "--function-arg-placeholders", + "--fallback-style=llvm", + }, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true, + }, +} diff --git a/lua/lsp/gopls.lua b/lua/lsp/gopls.lua index f804754..a231684 100644 --- a/lua/lsp/gopls.lua +++ b/lua/lsp/gopls.lua @@ -1,6 +1,5 @@ ---@type vim.lsp.Config return { - cmd = { "gopls" }, filetypes = { "go", "gomod", "gosum" }, root_markers = { "go.mod", @@ -8,8 +7,21 @@ return { }, settings = { gopls = { + gofumpt = true, + codelenses = { + gc_details = false, + generate = true, + regenerate_cgo = true, + run_govulncheck = true, + test = true, + tidy = true, + upgrade_dependency = true, + vendor = true, + }, analyses = { + nliness = true, unusedparams = true, + unusedwrite = true, }, hints = { assignVariableTypes = true, @@ -20,8 +32,10 @@ return { parameterNames = true, rangeVariableTypes = true, }, + usePlaceholders = true, + completeUnimported = true, staticcheck = true, - gofumpt = true, + directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" }, semanticTokens = true, }, }, diff --git a/lua/lsp/pyright.lua b/lua/lsp/pyright.lua.bak similarity index 100% rename from lua/lsp/pyright.lua rename to lua/lsp/pyright.lua.bak diff --git a/lua/lsp/rust_analyzer.lua b/lua/lsp/rust_analyzer.lua.bak similarity index 100% rename from lua/lsp/rust_analyzer.lua rename to lua/lsp/rust_analyzer.lua.bak diff --git a/lua/lsp/yamlls.lua b/lua/lsp/yamlls.lua new file mode 100644 index 0000000..b1117ab --- /dev/null +++ b/lua/lsp/yamlls.lua @@ -0,0 +1,24 @@ +return { + capabilities = { + textDocument = { + foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, + }, + }, + }, + settings = { + redhat = { telemetry = { enabled = false } }, + yaml = { + keyOrdering = false, + format = { + enable = true, + }, + validate = true, + schemaStore = { + enable = false, + url = "", + }, + }, + }, +} diff --git a/lua/plugins/snacks.lua b/lua/plugins/snacks.lua index 2781244..5e67b7f 100644 --- a/lua/plugins/snacks.lua +++ b/lua/plugins/snacks.lua @@ -18,6 +18,9 @@ return { words = { enabled = false }, }, keys = { + { ",", function() Snacks.picker.buffers() end, desc = "Buffers" }, + { ":", function() Snacks.picker.command_history() end, desc = "Command History" }, + { "n", function() Snacks.picker.notifications() end, desc = "Notification History" }, { "e", function() Snacks.explorer() end, desc = "Snack File Explorer" }, { "", function() Snacks.picker.smart() end, desc = "Smart Find Files" }, { "fg", function() Snacks.picker.git_files() end, desc = "Find Git Files" },