update python/rust lsp

main
maye 2025-09-04 15:01:20 +08:00
parent 39a2d68c8c
commit e53cf715f5
9 changed files with 68 additions and 82 deletions

View File

@ -15,9 +15,24 @@ local M = {
return false
end,
},
lsp_servers = {
"goimports", "gofumpt", "basedpyright"
}
lsp_servers = {
code = {
"lua_ls",
"gopls",
"clangd",
"bashls",
"yamlls",
"ts_ls",
"rust_analyzer",
"ruff",
},
format_lint = {
"goimports",
"gofumpt",
},
mason_ensure_installed = { "lua_ls", "bashls", "bacon", "rust-analyzer" },
treesitter_ensure_installed = { "go", "rust", "python" },
},
}
return M

View File

@ -1,6 +1,12 @@
-- Get all LSP servers to configure
local function get_all_servers()
local servers = {}
local commons = require("commons")
-- Use configured LSP servers from commons
for _, server in ipairs(commons.lsp_servers.code) do
servers[server] = true
end
-- Auto-detect LSP servers installed by Mason using mason-lspconfig
local ok, mason_lspconfig = pcall(require, "mason-lspconfig")
@ -11,29 +17,34 @@ local function get_all_servers()
end
end
-- If no servers detected, fall back to common servers that might be system-installed
if vim.tbl_isempty(servers) then
local fallback_servers = {
"lua_ls",
}
for _, server in pairs(fallback_servers) do
servers[server] = true
end
end
return servers
end
-- Configure a single LSP server
local function configure_server(server, lspconfig, capabilities)
local ok, settings = pcall(require, "lsp." .. server)
if ok then
if lspconfig then
settings.capabilities = capabilities
lspconfig[server].setup(settings)
-- Only attempt to load .lua files from lsp folder
local lsp_config_path = "lsp." .. server
local lua_file_path = vim.fn.stdpath("config") .. "/lua/lsp/" .. server .. ".lua"
-- Check if the .lua file exists
if vim.fn.filereadable(lua_file_path) == 1 then
local ok, settings = pcall(require, lsp_config_path)
if ok then
if lspconfig then
settings.capabilities = capabilities
lspconfig[server].setup(settings)
else
vim.lsp.config(server, settings)
vim.lsp.enable(server)
end
else
vim.lsp.config(server, settings)
vim.lsp.enable(server)
-- Fallback to default config if .lua file exists but fails to load
if lspconfig then
lspconfig[server].setup({ capabilities = capabilities })
else
vim.lsp.config(server, {})
vim.lsp.enable(server)
end
end
else
if lspconfig then

View File

@ -1,2 +0,0 @@
---@type vim.lsp.Config
return {}

View File

@ -18,10 +18,19 @@ return {
-- Server-specific settings (varies by language server)
-- Check your language server's documentation for available options
settings = {
python = {
basedpyright = {
analysis = {
autoImportCompletions = true,
ignorePatterns = { "*.pyi" },
diagnosticSeverityOverrides = {
reportAny = false,
reportExplicitAny = false,
},
typeCheckingMode = "standard",
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = "workspace",
disableOrganizeImports = true,
},
},
},

View File

@ -1,48 +0,0 @@
return {
-- Command to start the language server
-- This should match the executable name installed by Mason or system package manager
cmd = { "pyright" },
-- 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,
},
},
},
-- Optional: Additional capabilities (usually handled globally)
-- capabilities = require("blink.cmp").get_lsp_capabilities(),
-- Optional: Custom initialization options
-- init_options = {
-- hostInfo = "neovim",
-- },
-- Optional: Custom handlers for LSP methods
-- handlers = {
-- ["textDocument/hover"] = vim.lsp.with(
-- vim.lsp.handlers.hover,
-- { border = "rounded" }
-- ),
-- },
}

9
lua/lsp/ruff.lua Normal file
View File

@ -0,0 +1,9 @@
return {
cmd_env = { RUFF_TRACE = "messages" },
init_options = {
settings = {
logLevel = "error",
},
},
keys = { { "<leader>co", function() end, desc = "Organize Imports" } },
}

View File

@ -19,9 +19,8 @@ return {
},
formatters_by_ft = {
lua = { "stylua" },
python = { "black" },
rust = { "rustfmt" },
javascript = { "prettier", stop_after_first = true },
javascript = { "biome" },
sh = { "shfmt" },
xml = { "xmlformat" },
},

View File

@ -3,15 +3,8 @@ return {
cmd = "Mason",
build = ":MasonUpdate",
opts_extend = { "ensure_installed" },
opts = {
ensure_installed = {
-- Formatters and tools
"stylua",
-- LSP servers (will be auto-detected by mason-lspconfig)
"lua-language-server",
"gopls",
"pyright"
}
opts = {
ensure_installed = {},
},
event = "VeryLazy",
config = function(_, opts)