neovim configuration

This commit is contained in:
2026-03-22 13:00:29 +01:00
commit 2da113baae
10 changed files with 431 additions and 0 deletions

148
lua/plugins/lsp.lua Normal file
View File

@@ -0,0 +1,148 @@
-- Mason (Package Installer)
require("mason").setup({
registries = {
"github:mason-org/mason-registry",
"github:Crashdummyy/mason-registry",
},
})
-- Mason LSPConfig
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"gopls",
"clangd",
"html",
"cssls",
"jsonls",
"yamlls",
"bashls",
"pyright",
"ts_ls",
"rust_analyzer",
"robotcode",
"tinymist",
},
})
-- Blink.cmp (Autocompletion)
require("blink.cmp").setup({
keymap = {
preset = "none",
["<CR>"] = { "accept", "fallback" },
["<Tab>"] = { "select_next", "snippet_forward", "fallback" },
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" },
["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" },
["<C-Space>"] = { "show", "show_documentation", "hide_documentation" },
},
completion = {
list = { selection = { preselect = false, auto_insert = true } },
},
appearance = {
use_nvim_cmp_as_default = true,
nerd_font_variant = "mono",
},
sources = { default = { "lsp", "path", "snippets", "buffer" } },
signature = { enabled = true },
})
-- Global LSP Setup (Using Blink capabilities)
local capabilities = require("blink.cmp").get_lsp_capabilities()
local servers = {
"lua_ls",
"gopls",
"clangd",
"html",
"cssls",
"jsonls",
"yamlls",
"bashls",
"pyright",
"ts_ls",
"rust_analyzer",
"robotcode",
"tinymist",
"marksman",
}
for _, server in ipairs(servers) do
vim.lsp.config(server, { capabilities = capabilities })
end
-- Dedicated C# Setup
require("roslyn").setup({
config = { handlers = require("rzls.roslyn_handlers") },
})
-- Diagnostics Configuration
local sign = function(opts)
vim.fn.sign_define(opts.name, { texthl = opts.name, text = opts.text, numhl = "" })
end
sign({ name = "DiagnosticSignError", text = "" })
sign({ name = "DiagnosticSignWarn", text = "" })
sign({ name = "DiagnosticSignHint", text = "" })
sign({ name = "DiagnosticSignInfo", text = "" })
vim.diagnostic.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = false,
float = { border = "rounded", source = "always", header = "", prefix = "" },
})
-- Formatting (Conform)
require("conform").setup({
formatters_by_ft = {
cs = { "csharpier" },
rust = { "rustfmt" },
lua = { "stylua" },
go = { "gofmt" },
c = { "clang-format" },
cpp = { "clang-format" },
html = { "prettier" },
css = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
sh = { "shfmt" },
bash = { "shfmt" },
python = { "isort", "black" },
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
typst = { "typstyle" },
xml = { "xmlformatter" },
markdown = { "prettier", "injected" },
},
format_on_save = function(bufnr)
if vim.bo[bufnr].filetype ~= "rust" then
return
end
return { timeout_ms = 3000, lsp_fallback = true }
end,
})
-- Formatting Trigger
vim.keymap.set({ "n", "v" }, "<leader>f", function()
require("conform").format({ lsp_fallback = true, async = false, timeout_ms = 3000 })
end, { desc = "Format file or range" })
-- Linting (Nvim-Lint)
require("lint").linters_by_ft = {
python = { "flake8" },
}
-- Dynamic LSP Keymaps (Loaded only when LSP attaches to a buffer)
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
local opts = { buffer = event.buf }
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
end,
})