mirror of
https://github.com/harivansh-afk/nvim.git
synced 2026-04-15 10:05:17 +00:00
net config
This commit is contained in:
parent
93b7b93d64
commit
dd59a54b92
36 changed files with 960 additions and 631 deletions
|
|
@ -1,89 +1,66 @@
|
|||
return {
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
},
|
||||
config = function()
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"lua_ls", -- Lua
|
||||
"pyright", -- Python
|
||||
"ts_ls", -- TypeScript/JavaScript (tsserver renamed)
|
||||
"rust_analyzer", -- Rust
|
||||
"gopls", -- Go
|
||||
"clangd", -- C/C++
|
||||
"bashls", -- Bash
|
||||
"jsonls", -- JSON
|
||||
"yamlls", -- YAML
|
||||
"html", -- HTML
|
||||
"cssls", -- CSS
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
},
|
||||
automatic_installation = true,
|
||||
})
|
||||
config = function()
|
||||
local lsp_config = require("config.lsp")
|
||||
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
-- Basic LSP keymaps
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
local opts = { buffer = ev.buf }
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, opts) -- Ctrl+] for go to definition
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
||||
vim.keymap.set("n", "<leader>f", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Auto-setup all installed servers
|
||||
require("mason-lspconfig").setup_handlers({
|
||||
-- Default handler for all servers
|
||||
function(server_name)
|
||||
lspconfig[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
|
||||
-- Custom configuration for specific servers
|
||||
["lua_ls"] = function()
|
||||
lspconfig.lua_ls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
-- Set up Mason for auto-installation
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"lua_ls",
|
||||
"pyright",
|
||||
"ts_ls",
|
||||
"rust_analyzer",
|
||||
"gopls",
|
||||
"clangd",
|
||||
"bashls",
|
||||
"jsonls",
|
||||
"html",
|
||||
"cssls",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
automatic_installation = true,
|
||||
})
|
||||
|
||||
["pyright"] = function()
|
||||
lspconfig.pyright.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
typeCheckingMode = "basic",
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = lsp_config.capabilities()
|
||||
|
||||
-- LspAttach autocmd for keymaps
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client then
|
||||
lsp_config.on_attach(client, ev.buf)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Helper to load per-server config from lua/lsp/ if it exists
|
||||
local function get_server_config(server_name)
|
||||
local ok, server_config = pcall(require, "lsp." .. server_name)
|
||||
if ok then
|
||||
return server_config
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
-- Auto-setup all installed servers
|
||||
require("mason-lspconfig").setup_handlers({
|
||||
-- Default handler for all servers
|
||||
function(server_name)
|
||||
local server_config = get_server_config(server_name)
|
||||
local config = vim.tbl_deep_extend("force", {
|
||||
capabilities = capabilities,
|
||||
}, server_config)
|
||||
|
||||
lspconfig[server_name].setup(config)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue