neovim refactor

This commit is contained in:
kiri committed 2026-09-04 19:49:42 +02:00
1 parent b12c211a69
commit 883f9d26c2
25 files changed
+1154 -880

No files matched your search

@@ -1,20 +1,8 @@
require("lz.n").load({
{
"typst-preview.nvim",
ft = "typst",
after = function()
-- Setup typst-preview
require("typst-preview").setup({
-- Optionally configure things here
dependencies_bin = require("nix-info").settings.typstPreviewDependencies,
})
vim.keymap.set("n", "<leader>tp", "<cmd>TypstPreviewToggle<cr>", { desc = "[T]ypst [P]review Toggle" })
end,
},
{ "nvim-navic" },
{ "SchemaStore.nvim" },
{
"lazydev.nvim",
cmd = "LazyDev",
ft = "lua",
after = function()
require("lazydev").setup({
@@ -27,163 +15,92 @@ require("lz.n").load({
{
"nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
before = function()
require("lz.n").trigger_load("lazydev.nvim")
end,
after = function()
local telescope_plugins = {
"project.nvim",
"telescope.nvim",
"telescope-fzf-native.nvim",
"telescope-ui-select.nvim",
}
local telescope_picker = function(picker)
return function()
require("lz.n").trigger_load(telescope_plugins)
require("telescope.builtin")[picker]()
end
end
local lsp_float = { border = "single" }
local navic_excluded_filetypes = {
[""] = true,
help = true,
minifiles = true,
TelescopePrompt = true,
Trouble = true,
}
local function navic_enabled(bufnr)
return vim.bo[bufnr].buftype == "" and not navic_excluded_filetypes[vim.bo[bufnr].filetype]
end
_G.lux_navic_location = function()
local ok, navic = pcall(require, "nvim-navic")
if not ok or not navic.is_available() then
return ""
end
return navic.get_location()
end
local function update_winbar(winid, bufnr)
if not vim.api.nvim_win_is_valid(winid) then
return
end
local is_float = vim.api.nvim_win_get_config(winid).relative ~= ""
local winbar = ""
if not is_float and vim.b[bufnr].lux_navic_attached and navic_enabled(bufnr) then
winbar = "%{%v:lua.lux_navic_location()%}"
end
vim.api.nvim_set_option_value("winbar", winbar, { win = winid })
end
local function update_winbars_for_buffer(bufnr)
for _, winid in ipairs(vim.fn.win_findbuf(bufnr)) do
update_winbar(winid, bufnr)
end
end
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "WinEnter" }, {
group = vim.api.nvim_create_augroup("lux-navic-winbar", { clear = true }),
callback = function(args)
update_winbar(vim.api.nvim_get_current_win(), args.buf)
end,
})
local attach_group = vim.api.nvim_create_augroup("lux-lsp-attach", { clear = true })
local detach_group = vim.api.nvim_create_augroup("lux-lsp-detach", { clear = true })
local highlight_group = vim.api.nvim_create_augroup("lux-lsp-highlight", { clear = true })
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("lux-lsp-attach", { clear = true }),
group = attach_group,
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
local bufnr = args.buf
local map = function(keys, func, desc, mode)
mode = mode or "n"
vim.keymap.set(mode, keys, func, { buffer = bufnr, desc = "LSP: " .. desc })
local map = function(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
end
map("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame")
map("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction", { "n", "x" })
map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
map("K", function()
vim.lsp.buf.hover(lsp_float)
end, "Hover Documentation")
map("<C-s>", function()
vim.lsp.buf.signature_help(lsp_float)
end, "Signature Help", { "i", "s" })
map("n", "gd", function()
require("telescope.builtin").lsp_definitions()
end, "Go to definition")
map("n", "gD", vim.lsp.buf.declaration, "Go to declaration")
map("n", "gr", function()
require("telescope.builtin").lsp_references()
end, "Find references")
map("n", "gI", function()
require("telescope.builtin").lsp_implementations()
end, "Go to implementation")
map("n", "gy", function()
require("telescope.builtin").lsp_type_definitions()
end, "Go to type definition")
map("n", "gO", function()
require("telescope.builtin").lsp_document_symbols()
end, "Find document symbols")
map("n", "K", vim.lsp.buf.hover, "Show hover documentation")
map({ "n", "x" }, "<leader>ca", vim.lsp.buf.code_action, "Apply code action")
map("n", "<leader>cr", vim.lsp.buf.rename, "Rename symbol")
map("gd", telescope_picker("lsp_definitions"), "[G]oto [D]efinition")
map("gr", telescope_picker("lsp_references"), "[G]oto [R]eferences")
map("gI", telescope_picker("lsp_implementations"), "[G]oto [I]mplementation")
map("<leader>D", telescope_picker("lsp_type_definitions"), "Type [D]efinition")
map("<leader>ds", telescope_picker("lsp_document_symbols"), "[D]ocument [S]ymbols")
map("<leader>ws", telescope_picker("lsp_dynamic_workspace_symbols"), "[W]orkspace [S]ymbols")
if client:supports_method("textDocument/documentSymbol", bufnr) then
require("nvim-navic").attach(client, bufnr)
end
if client and client:supports_method("textDocument/documentSymbol", bufnr) and navic_enabled(bufnr) then
require("lz.n").trigger_load("nvim-navic")
local ok, navic = pcall(require, "nvim-navic")
if ok then
navic.attach(client, bufnr)
vim.b[bufnr].lux_navic_attached = true
update_winbars_for_buffer(bufnr)
if client:supports_method("textDocument/documentHighlight", bufnr) then
local autocmds = vim.api.nvim_get_autocmds({ group = highlight_group, buffer = bufnr })
if #autocmds == 0 then
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = highlight_group,
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
group = highlight_group,
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
end
if client and client:supports_method("textDocument/documentHighlight", bufnr) then
local highlight_augroup = vim.api.nvim_create_augroup("lux-lsp-highlight", { clear = false })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = bufnr,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = bufnr,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
vim.api.nvim_create_autocmd("LspDetach", {
group = vim.api.nvim_create_augroup("lux-lsp-detach", { clear = true }),
callback = function(event)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({ group = "lux-lsp-highlight", buffer = event.buf })
end,
})
if client:supports_method("textDocument/inlayHint", bufnr) then
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
map("n", "<leader>uh", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
end, "Toggle inlay hints")
end
if client and client:supports_method("textDocument/inlayHint", bufnr) then
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
map("<leader>th", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }))
end, "[T]oggle Inlay [H]ints")
if client.name == "tinymist" then
vim.api.nvim_buf_create_user_command(bufnr, "TinymistPreview", function()
client:exec_cmd({ command = "tinymist.startDefaultPreview" }, { bufnr = bufnr })
end, { desc = "Start Tinymist preview", force = true })
end
end,
})
vim.diagnostic.config({
severity_sort = true,
underline = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.INFO] = "",
[vim.diagnostic.severity.HINT] = "󰠠 ",
},
},
virtual_text = false,
virtual_lines = {
current_line = true,
},
float = {
border = "single",
source = "if_many",
},
vim.api.nvim_create_autocmd("LspDetach", {
group = detach_group,
callback = function(args)
local supports_highlights = vim
.iter(vim.lsp.get_clients({
bufnr = args.buf,
method = "textDocument/documentHighlight",
}))
:any(function(client)
return client.id ~= args.data.client_id
end)
if not supports_highlights then
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({ group = highlight_group, buffer = args.buf })
end
end,
})
vim.lsp.config("lua_ls", {
@@ -197,10 +114,8 @@ require("lz.n").load({
},
},
})
vim.lsp.enable("lua_ls")
local settings = require("nix-info").settings
vim.lsp.config("nixd", {
settings = {
nixd = {
@@ -209,64 +124,53 @@ require("lz.n").load({
nixos = { expr = settings.nixdExtras.nixos_options },
["home-manager"] = { expr = settings.nixdExtras.home_manager_options },
},
formatting = { command = { "nixfmt" } },
},
},
})
vim.lsp.enable("nixd")
vim.lsp.enable("dafny")
vim.lsp.enable("jsonls")
vim.lsp.config("jsonls", {
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
format = { enable = false },
},
},
})
vim.lsp.config("yamlls", {
settings = {
yaml = {
schemas = require("schemastore").yaml.schemas(),
schemaStore = { enable = false, url = "" },
format = { enable = false },
},
},
})
vim.lsp.config("vtsls", {
settings = {
vtsls = {
autoUseWorkspaceTsdk = true,
},
vtsls = { autoUseWorkspaceTsdk = true },
},
})
vim.lsp.enable("vtsls")
vim.lsp.enable("cssls")
vim.lsp.enable("html")
vim.lsp.enable("emmet_language_server")
vim.lsp.enable("oxlint")
vim.lsp.config("oxfmt", {
filetypes = vim.list_extend({ "svelte" }, vim.lsp.config.oxfmt.filetypes),
})
vim.lsp.enable("oxfmt")
vim.lsp.enable("tailwindcss")
vim.lsp.enable("rust_analyzer")
vim.lsp.enable("ty")
vim.lsp.enable("ruff")
vim.lsp.enable("astro")
vim.lsp.enable("svelte")
vim.lsp.config("tinymist", {
settings = {
tinymist = {
formatterMode = "typstyle",
},
},
})
vim.lsp.enable("tinymist")
end,
},
{
"trouble.nvim",
cmd = "Trouble",
keys = {
{ "<leader>xx", "<cmd>Trouble diagnostics toggle<cr>", desc = "Diagnostics (Trouble)" },
{ "<leader>xX", "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", desc = "Buffer Diagnostics (Trouble)" },
},
after = function()
require("trouble").setup({
focus = true,
preview = {
border = "single",
},
vim.lsp.enable({
"lua_ls",
"nixd",
"jsonls",
"yamlls",
"vtsls",
"cssls",
"html",
"emmet_language_server",
"oxlint",
"tailwindcss",
"rust_analyzer",
"ty",
"ruff",
"astro",
"svelte",
"tinymist",
})
end,
},