176 lines
5.7 KiB
Lua
176 lines
5.7 KiB
Lua
require("lz.n").load({
|
|
{ "nvim-navic" },
|
|
{ "SchemaStore.nvim" },
|
|
{
|
|
"lazydev.nvim",
|
|
ft = "lua",
|
|
after = function()
|
|
require("lazydev").setup({
|
|
library = {
|
|
{ words = { "nix%-info", "settings" }, path = "nix-info" },
|
|
},
|
|
})
|
|
end,
|
|
},
|
|
{
|
|
"nvim-lspconfig",
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
after = function()
|
|
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 }),
|
|
callback = function(args)
|
|
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
|
local bufnr = args.buf
|
|
local map = function(mode, lhs, rhs, desc)
|
|
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
|
|
end
|
|
|
|
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", "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")
|
|
|
|
if client:supports_method("textDocument/documentSymbol", bufnr) then
|
|
map("n", "gO", function()
|
|
require("telescope.builtin").lsp_document_symbols()
|
|
end, "Find document symbols")
|
|
require("nvim-navic").attach(client, bufnr)
|
|
end
|
|
|
|
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: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.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.api.nvim_create_autocmd("LspDetach", {
|
|
group = vim.api.nvim_create_augroup("lux-lsp-detach", { clear = true }),
|
|
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", {
|
|
settings = {
|
|
Lua = {
|
|
runtime = { version = "LuaJIT" },
|
|
signatureHelp = { enabled = true },
|
|
diagnostics = { globals = { "vim" } },
|
|
telemetry = { enabled = false },
|
|
completion = { callSnippet = "Replace" },
|
|
},
|
|
},
|
|
})
|
|
|
|
local settings = require("nix-info").settings
|
|
vim.lsp.config("nixd", {
|
|
settings = {
|
|
nixd = {
|
|
nixpkgs = { expr = settings.nixdExtras.nixpkgs },
|
|
options = {
|
|
nixos = { expr = settings.nixdExtras.nixos_options },
|
|
["home-manager"] = { expr = settings.nixdExtras.home_manager_options },
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
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 },
|
|
},
|
|
})
|
|
|
|
vim.lsp.enable({
|
|
"lua_ls",
|
|
"nixd",
|
|
"jsonls",
|
|
"yamlls",
|
|
"vtsls",
|
|
"cssls",
|
|
"html",
|
|
"emmet_language_server",
|
|
"oxlint",
|
|
"tailwindcss",
|
|
"rust_analyzer",
|
|
"ty",
|
|
"ruff",
|
|
"astro",
|
|
"svelte",
|
|
"tinymist",
|
|
})
|
|
end,
|
|
},
|
|
})
|