This commit is contained in:
2025-02-06 17:45:39 +02:00
commit a3f3abb460
84 changed files with 5567 additions and 0 deletions

115
config/lsp/conform.nix Normal file
View File

@ -0,0 +1,115 @@
{
lib,
config,
...
}: {
options = {
conform.enable = lib.mkEnableOption "Enable conform module";
};
config = lib.mkIf config.conform.enable {
plugins.conform-nvim = {
enable = true;
settings = {
notify_on_error = true;
# default_format_opts = {
# lsp_format = "fallback";
# };
# format_after_save = {
# lsp_format = "fallback";
# };
format_on_save = ''
function(bufnr)
-- Disable with a global or buffer-local variable
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_format = 'fallback' }
end
'';
formatters_by_ft = {
html = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
css = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
javascript = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
javascriptreact = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
typescript = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
typescriptreact = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
java = ["google-java-format"];
python = ["black"];
lua = ["stylua"];
nix = ["alejandra"];
typst = ["typstfmt"];
markdown = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
rust = ["rustfmt"];
};
};
};
keymaps = [
{
mode = "n";
key = "<leader>uf";
action = ":FormatToggle<CR>";
options = {
desc = "Toggle Format Globally";
silent = true;
};
}
{
mode = "n";
key = "<leader>uF";
action = ":FormatToggle!<CR>";
options = {
desc = "Toggle Format Locally";
silent = true;
};
}
{
mode = "n";
key = "<leader>cf";
action = "<cmd>lua require('conform').format()<cr>";
options = {
silent = true;
desc = "Format Buffer";
};
}
{
mode = "v";
key = "<leader>cF";
action = "<cmd>lua require('conform').format()<cr>";
options = {
silent = true;
desc = "Format Lines";
};
}
];
};
}

24
config/lsp/default.nix Normal file
View File

@ -0,0 +1,24 @@
{
lib,
config,
...
}: {
imports = [
./conform.nix
./fidget.nix
./lsp-nvim.nix
./lspsaga.nix
./trouble.nix
];
options = {
lsp.enable = lib.mkEnableOption "Enable lsp module";
};
config = lib.mkIf config.dap.enable {
conform.enable = lib.mkDefault true;
fidget.enable = lib.mkDefault true;
lsp-nvim.enable = lib.mkDefault true;
lspsaga.enable = lib.mkDefault false;
trouble.enable = lib.mkDefault true;
};
}

108
config/lsp/fidget.nix Normal file
View File

@ -0,0 +1,108 @@
{
lib,
config,
...
}: {
options = {
fidget.enable = lib.mkEnableOption "Enable fidget module";
};
config = lib.mkIf config.fidget.enable {
plugins.fidget = {
enable = true;
logger = {
level = "warn"; # “off”, “error”, “warn”, “info”, “debug”, “trace”
floatPrecision = 1.0e-2; # Limit the number of decimals displayed for floats
};
progress = {
pollRate = 0; # How and when to poll for progress messages
suppressOnInsert = true; # Suppress new messages while in insert mode
ignoreDoneAlready = false; # Ignore new tasks that are already complete
ignoreEmptyMessage = false; # Ignore new tasks that don't contain a message
clearOnDetach =
# Clear notification group when LSP server detaches
''
function(client_id)
local client = vim.lsp.get_client_by_id(client_id)
return client and client.name or nil
end
'';
notificationGroup =
# How to get a progress message's notification group key
''
function(msg) return msg.lsp_client.name end
'';
ignore = []; # List of LSP servers to ignore
lsp = {
progressRingbufSize = 0; # Configure the nvim's LSP progress ring buffer size
};
display = {
renderLimit = 16; # How many LSP messages to show at once
doneTtl = 3; # How long a message should persist after completion
doneIcon = ""; # Icon shown when all LSP progress tasks are complete
doneStyle = "Constant"; # Highlight group for completed LSP tasks
progressTtl = lib.nixvim.mkRaw "math.huge"; # How long a message should persist when in progress
progressIcon = {
pattern = "dots";
period = 1;
}; # Icon shown when LSP progress tasks are in progress
progressStyle = "WarningMsg"; # Highlight group for in-progress LSP tasks
groupStyle = "Title"; # Highlight group for group name (LSP server name)
iconStyle = "Question"; # Highlight group for group icons
priority = 30; # Ordering priority for LSP notification group
skipHistory = true; # Whether progress notifications should be omitted from history
formatMessage = ''
require ("fidget.progress.display").default_format_message
''; # How to format a progress message
formatAnnote = ''
function (msg) return msg.title end
''; # How to format a progress annotation
formatGroupName = ''
function (group) return tostring (group) end
''; # How to format a progress notification group's name
overrides = {
rust_analyzer = {
name = "rust-analyzer";
};
}; # Override options from the default notification config
};
};
notification = {
pollRate = 10; # How frequently to update and render notifications
filter = "info"; # “off”, “error”, “warn”, “info”, “debug”, “trace”
historySize = 128; # Number of removed messages to retain in history
overrideVimNotify = true;
redirect = lib.nixvim.mkRaw ''
function(msg, level, opts)
if opts and opts.on_open then
return require("fidget.integration.nvim-notify").delegate(msg, level, opts)
end
end
'';
configs = {
default = lib.nixvim.mkRaw "require('fidget.notification').default_config";
};
window = {
normalHl = "Comment";
winblend = 0;
border = "none"; # none, single, double, rounded, solid, shadow
zindex = 45;
maxWidth = 0;
maxHeight = 0;
xPadding = 1;
yPadding = 0;
align = "bottom";
relative = "editor";
};
view = {
stackUpwards = true; # Display notification items from bottom to top
iconSeparator = " "; # Separator between group name and icon
groupSeparator = "---"; # Separator between notification groups
groupSeparatorHl =
# Highlight group used for group separator
"Comment";
};
};
};
};
}

214
config/lsp/lsp-nvim.nix Normal file
View File

@ -0,0 +1,214 @@
{
lib,
config,
...
}: {
options = {
lsp-nvim.enable = lib.mkEnableOption "Enable lsp-nvim module";
};
config = lib.mkIf config.lsp-nvim.enable {
plugins = {
lsp-format = {
enable = false; # Enable it if you want lsp-format integration for none-ls
};
lsp = {
enable = true;
capabilities = "offsetEncoding = 'utf-16'";
servers = {
clangd = {
enable = true;
};
lua_ls = {
enable = true;
extraOptions = {
settings = {
Lua = {
completion = {
callSnippet = "Replace";
};
diagnostics = {
globals = ["vim"];
};
telemetry = {
enabled = false;
};
hint = {
enable = true;
};
};
};
};
};
nil_ls = {
enable = false;
};
nixd = {
enable = true;
};
tinymist = {
enable = true;
};
eslint = {
enable = false;
};
pyright = {
enable = false;
};
ruff = {
enable = false;
};
rust_analyzer = {
enable = true;
installCargo = true;
installRustc = true;
settings = {
checkOnSave = true;
check = {
command = "clippy";
};
# inlayHints = {
# enable = true;
# showParameterNames = true;
# parameterHintsPrefix = "<- ";
# otherHintsPrefix = "=> ";
# };
procMacro = {
enable = true;
};
};
};
};
keymaps = {
silent = true;
lspBuf = {
gd = {
action = "definition";
desc = "Goto Definition";
};
gr = {
action = "references";
desc = "Goto References";
};
gD = {
action = "declaration";
desc = "Goto Declaration";
};
gI = {
action = "implementation";
desc = "Goto Implementation";
};
gT = {
action = "type_definition";
desc = "Type Definition";
};
K = {
action = "hover";
desc = "Hover";
};
"<leader>cw" = {
action = "workspace_symbol";
desc = "Workspace Symbol";
};
"<leader>cr" = {
action = "rename";
desc = "Rename";
};
"<leader>ca" = {
action = "code_action";
desc = "Code Action";
};
"<C-k>" = {
action = "signature_help";
desc = "Signature Help";
};
};
diagnostic = {
"<leader>cd" = {
action = "open_float";
desc = "Line Diagnostics";
};
"[d" = {
action = "goto_next";
desc = "Next Diagnostic";
};
"]d" = {
action = "goto_prev";
desc = "Previous Diagnostic";
};
};
};
onAttach = ''
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(false)
end
vim.bo[args.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
end,
})
'';
};
};
extraConfigLua = ''
local _border = "rounded"
require('lspconfig.ui.windows').default_options = {
border = _border
}
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = _border
}
)
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
border = _border
}
)
vim.diagnostic.config({
float = { border = "rounded" },
virtual_text = {
prefix = "",
},
signs = true,
underline = true,
update_in_insert = true,
})
-- vim.api.nvim_create_autocmd("LspAttach", {
-- group = vim.api.nvim_create_augroup("UserLspConfig", {}),
-- callback = function(args)
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- if client.server_capabilities.inlayHintProvider then
-- vim.lsp.inlay_hint.enable(false)
-- end
-- vim.bo[args.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
--
-- local opts = { buffer = args.buf }
-- vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
-- vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
-- vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
-- vim.keymap.set("n", "gI", vim.lsp.buf.implementation, opts)
-- vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts)
-- vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
-- vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
-- vim.keymap.set("n", "<space>cw", vim.lsp.buf.workspace_symbol, opts)
-- vim.keymap.set("n", "<space>cr", vim.lsp.buf.rename, opts)
-- vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
-- vim.keymap.set("n", "<space>cf", function()
-- vim.lsp.buf.format({ async = true })
-- end, opts)
-- vim.keymap.set("n", "<space>cd", vim.diagnostic.open_float, opts)
-- vim.keymap.set("n", "[d", vim.diagnostic.goto_next, opts)
-- vim.keymap.set("n", "]d", vim.diagnostic.goto_prev, opts)
-- end,
-- })
'';
};
}

201
config/lsp/lspsaga.nix Normal file
View File

@ -0,0 +1,201 @@
{
lib,
config,
...
}: {
options = {
lspsaga.enable = lib.mkEnableOption "Enable lspsaga module";
};
config = lib.mkIf config.lspsaga.enable {
plugins.lspsaga = {
enable = true;
beacon = {
enable = true;
};
ui = {
border = "rounded"; # One of none, single, double, rounded, solid, shadow
codeAction = "💡"; # Can be any symbol you want 💡
};
hover = {
openCmd = "!floorp"; # Choose your browser
openLink = "gx";
};
diagnostic = {
borderFollow = true;
diagnosticOnlyCurrent = false;
showCodeAction = true;
};
symbolInWinbar = {
enable = true; # Breadcrumbs
};
codeAction = {
extendGitSigns = false;
showServerName = true;
onlyInCursor = true;
numShortcut = true;
keys = {
exec = "<CR>";
quit = [
"<Esc>"
"q"
];
};
};
lightbulb = {
enable = false;
sign = false;
virtualText = true;
};
implement = {
enable = false;
};
rename = {
autoSave = false;
keys = {
exec = "<CR>";
quit = [
"<C-k>"
"<Esc>"
];
select = "x";
};
};
outline = {
autoClose = true;
autoPreview = true;
closeAfterJump = true;
layout = "normal"; # normal or float
winPosition = "right"; # left or right
keys = {
jump = "e";
quit = "q";
toggleOrJump = "o";
};
};
scrollPreview = {
scrollDown = "<C-f>";
scrollUp = "<C-b>";
};
};
# keymaps = [
# {
# mode = "n";
# key = "gd";
# action = "<cmd>Lspsaga finder def<CR>";
# options = {
# desc = "Goto Definition";
# silent = true;
# };
# }
# {
# mode = "n";
# key = "gr";
# action = "<cmd>Lspsaga finder ref<CR>";
# options = {
# desc = "Goto References";
# silent = true;
# };
# }
#
# # {
# # mode = "n";
# # key = "gD";
# # action = "<cmd>Lspsaga show_line_diagnostics<CR>";
# # options = {
# # desc = "Goto Declaration";
# # silent = true;
# # };
# # }
#
# {
# mode = "n";
# key = "gI";
# action = "<cmd>Lspsaga finder imp<CR>";
# options = {
# desc = "Goto Implementation";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "gT";
# action = "<cmd>Lspsaga peek_type_definition<CR>";
# options = {
# desc = "Type Definition";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "K";
# action = "<cmd>Lspsaga hover_doc<CR>";
# options = {
# desc = "Hover";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "<leader>cw";
# action = "<cmd>Lspsaga outline<CR>";
# options = {
# desc = "Outline";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "<leader>cr";
# action = "<cmd>Lspsaga rename<CR>";
# options = {
# desc = "Rename";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "<leader>ca";
# action = "<cmd>Lspsaga code_action<CR>";
# options = {
# desc = "Code Action";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "<leader>cd";
# action = "<cmd>Lspsaga show_line_diagnostics<CR>";
# options = {
# desc = "Line Diagnostics";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "[d";
# action = "<cmd>Lspsaga diagnostic_jump_next<CR>";
# options = {
# desc = "Next Diagnostic";
# silent = true;
# };
# }
#
# {
# mode = "n";
# key = "]d";
# action = "<cmd>Lspsaga diagnostic_jump_prev<CR>";
# options = {
# desc = "Previous Diagnostic";
# silent = true;
# };
# }
# ];
};
}

61
config/lsp/trouble.nix Normal file
View File

@ -0,0 +1,61 @@
{
lib,
config,
...
}: {
options = {
trouble.enable = lib.mkEnableOption "Enable trouble module";
};
config = lib.mkIf config.trouble.enable {
plugins.trouble = {
enable = true;
settings = {
auto_close = true;
};
};
# TODO: Add keybinds to close trouble (q would be nice), rn I need to use :x to close it...
keymaps = [
{
mode = "n";
key = "<leader>x";
action = "+diagnostics/quickfix";
}
{
mode = "n";
key = "<leader>xx";
action = "<cmd>Trouble diagnostics toggle<cr>";
options = {
silent = true;
desc = "Diagnostics (Trouble)";
};
}
{
mode = "n";
key = "<leader>xX";
action = "<cmd>Trouble diagnostics toggle filter.buf=0<cr>";
options = {
silent = true;
desc = "Buffer Diagnostics (Trouble)";
};
}
{
mode = "n";
key = "<leader>xt";
action = "<cmd>Trouble todo<cr>";
options = {
silent = true;
desc = "Todo (Trouble)";
};
}
{
mode = "n";
key = "<leader>xQ";
action = "<cmd>Trouble qflist toggle<cr>";
options = {
silent = true;
desc = "Quickfix List (Trouble)";
};
}
];
};
}