update python/rust lsp
parent
39a2d68c8c
commit
e53cf715f5
|
@ -15,9 +15,24 @@ local M = {
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
lsp_servers = {
|
lsp_servers = {
|
||||||
"goimports", "gofumpt", "basedpyright"
|
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
|
return M
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
-- Get all LSP servers to configure
|
-- Get all LSP servers to configure
|
||||||
local function get_all_servers()
|
local function get_all_servers()
|
||||||
local 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
|
-- Auto-detect LSP servers installed by Mason using mason-lspconfig
|
||||||
local ok, mason_lspconfig = pcall(require, "mason-lspconfig")
|
local ok, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||||
|
@ -11,29 +17,34 @@ local function get_all_servers()
|
||||||
end
|
end
|
||||||
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
|
return servers
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Configure a single LSP server
|
-- Configure a single LSP server
|
||||||
local function configure_server(server, lspconfig, capabilities)
|
local function configure_server(server, lspconfig, capabilities)
|
||||||
local ok, settings = pcall(require, "lsp." .. server)
|
-- Only attempt to load .lua files from lsp folder
|
||||||
if ok then
|
local lsp_config_path = "lsp." .. server
|
||||||
if lspconfig then
|
local lua_file_path = vim.fn.stdpath("config") .. "/lua/lsp/" .. server .. ".lua"
|
||||||
settings.capabilities = capabilities
|
|
||||||
lspconfig[server].setup(settings)
|
-- 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
|
else
|
||||||
vim.lsp.config(server, settings)
|
-- Fallback to default config if .lua file exists but fails to load
|
||||||
vim.lsp.enable(server)
|
if lspconfig then
|
||||||
|
lspconfig[server].setup({ capabilities = capabilities })
|
||||||
|
else
|
||||||
|
vim.lsp.config(server, {})
|
||||||
|
vim.lsp.enable(server)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if lspconfig then
|
if lspconfig then
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
---@type vim.lsp.Config
|
|
||||||
return {}
|
|
|
@ -18,10 +18,19 @@ return {
|
||||||
-- Server-specific settings (varies by language server)
|
-- Server-specific settings (varies by language server)
|
||||||
-- Check your language server's documentation for available options
|
-- Check your language server's documentation for available options
|
||||||
settings = {
|
settings = {
|
||||||
python = {
|
basedpyright = {
|
||||||
analysis = {
|
analysis = {
|
||||||
|
autoImportCompletions = true,
|
||||||
|
ignorePatterns = { "*.pyi" },
|
||||||
|
diagnosticSeverityOverrides = {
|
||||||
|
reportAny = false,
|
||||||
|
reportExplicitAny = false,
|
||||||
|
},
|
||||||
|
typeCheckingMode = "standard",
|
||||||
autoSearchPaths = true,
|
autoSearchPaths = true,
|
||||||
useLibraryCodeForTypes = true,
|
useLibraryCodeForTypes = true,
|
||||||
|
diagnosticMode = "workspace",
|
||||||
|
disableOrganizeImports = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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" }
|
|
||||||
-- ),
|
|
||||||
-- },
|
|
||||||
}
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
return {
|
||||||
|
cmd_env = { RUFF_TRACE = "messages" },
|
||||||
|
init_options = {
|
||||||
|
settings = {
|
||||||
|
logLevel = "error",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
keys = { { "<leader>co", function() end, desc = "Organize Imports" } },
|
||||||
|
}
|
|
@ -19,9 +19,8 @@ return {
|
||||||
},
|
},
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { "stylua" },
|
lua = { "stylua" },
|
||||||
python = { "black" },
|
|
||||||
rust = { "rustfmt" },
|
rust = { "rustfmt" },
|
||||||
javascript = { "prettier", stop_after_first = true },
|
javascript = { "biome" },
|
||||||
sh = { "shfmt" },
|
sh = { "shfmt" },
|
||||||
xml = { "xmlformat" },
|
xml = { "xmlformat" },
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,15 +3,8 @@ return {
|
||||||
cmd = "Mason",
|
cmd = "Mason",
|
||||||
build = ":MasonUpdate",
|
build = ":MasonUpdate",
|
||||||
opts_extend = { "ensure_installed" },
|
opts_extend = { "ensure_installed" },
|
||||||
opts = {
|
opts = {
|
||||||
ensure_installed = {
|
ensure_installed = {},
|
||||||
-- Formatters and tools
|
|
||||||
"stylua",
|
|
||||||
-- LSP servers (will be auto-detected by mason-lspconfig)
|
|
||||||
"lua-language-server",
|
|
||||||
"gopls",
|
|
||||||
"pyright"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
|
|
Loading…
Reference in New Issue