Skip to content

Commit

Permalink
feat: move lsp settings to its own namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
glwbr committed Jun 29, 2024
1 parent 5d5fa68 commit 54c9423
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 47 deletions.
94 changes: 94 additions & 0 deletions home/editors/neovim/plugins/lsp/conform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
_: {
programs.nixvim = {
plugins.conform-nvim = {
enable = true;
notifyOnError = true;
formattersByFt = {
html = [["prettierd" "prettier"]];
css = [["prettierd" "prettier"]];
javascript = [["prettierd" "prettier"]];
javascriptreact = [["prettierd" "prettier"]];
typescript = [["prettierd" "prettier"]];
typescriptreact = [["prettierd" "prettier"]];
java = ["google-java-format"];
python = ["black"];
lua = ["stylua"];
nix = ["alejandra"];
markdown = [["prettierd" "prettier"]];
rust = ["rustfmt"];
};
};

keymaps = [
{
mode = "n";
key = "<leader>uf";
action = ":FormatToggle<CR>";
options = {
desc = "Toggle Format";
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";
};
}
];

extraConfigLua = ''
local conform = require("conform")
local notify = require("notify")
conform.setup({
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_fallback = true }
end,
})
local function show_notification(message, level)
notify(message, level, { title = "conform.nvim" })
end
vim.api.nvim_create_user_command("FormatToggle", function(args)
local is_global = not args.bang
if is_global then
vim.g.disable_autoformat = not vim.g.disable_autoformat
if vim.g.disable_autoformat then
show_notification("Autoformat-on-save disabled globally", "info")
else
show_notification("Autoformat-on-save enabled globally", "info")
end
else
vim.b.disable_autoformat = not vim.b.disable_autoformat
if vim.b.disable_autoformat then
show_notification("Autoformat-on-save disabled for this buffer", "info")
else
show_notification("Autoformat-on-save enabled for this buffer", "info")
end
end
end, {
desc = "Toggle autoformat-on-save",
bang = true,
})
'';
};
}
8 changes: 5 additions & 3 deletions home/editors/neovim/plugins/lsp/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
_: {
imports = [
./lsp.nix
];
imports = [
./conform.nix
./fidget.nix
./lsp.nix
];
}
103 changes: 103 additions & 0 deletions home/editors/neovim/plugins/lsp/fidget.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
programs.nixvim = {
plugins = {
fidget = {
enable = true;
logger = {
level = "warn"; # “off”, “error”, “warn”, “info”, “debug”, “trace”
floatPrecision = 0.01; # 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 = "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 = ''
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 = "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";
};
};
};
};
};
}
60 changes: 16 additions & 44 deletions home/editors/neovim/plugins/lsp/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ _: {

keymaps = {
silent = true;
diagnostic = {
# Navigate in diagnostics
"<C-p>" = "goto_prev";
"<C-n>" = "goto_next";
"<C-y>" = "confirm";
"<C-space>" = "complete";
};
#diagnostic = {
# # Navigate in diagnostics
# "<C-p>" = "goto_prev";
# "<C-n>" = "goto_next";
# "<C-y>" = "confirm";
# "<C-space>" = "complete";
#};

lspBuf = {
gd = "definition";
gD = "references";
gt = "type_definition";
gi = "implementation";
K = "hover";
};
#lspBuf = {
# K = "hover";
# gd = "definition";
# gD = "references";
# gi = "implementation";
# gt = "type_definition";
#};
};

servers = {
clangd.enable = true;
elixirls.enable = true;
eslint.enable = true;
lua-ls = {
enable = true;
Expand All @@ -41,36 +42,7 @@ _: {
};
};
nil-ls.enable = true;
tsserver = {
enable = false;
filetypes = ["javascript" "javascriptreact" "typescript" "typescriptreact"];
extraOptions = {
settings = {
javascript = {
inlayHints = {
includeInlayEnumMemberValueHints = true;
includeInlayFunctionLikeReturnTypeHints = true;
includeInlayFunctionParameterTypeHints = true;
includeInlayParameterNameHints = "all";
includeInlayParameterNameHintsWhenArgumentMatchesName = true;
includeInlayPropertyDeclarationTypeHints = true;
includeInlayVariableTypeHints = true;
};
};
typescript = {
inlayHints = {
includeInlayEnumMemberValueHints = true;
includeInlayFunctionLikeReturnTypeHints = true;
includeInlayFunctionParameterTypeHints = true;
includeInlayParameterNameHints = "all";
includeInlayParameterNameHintsWhenArgumentMatchesName = true;
includeInlayPropertyDeclarationTypeHints = true;
includeInlayVariableTypeHints = true;
};
};
};
};
};
yamlls.enable = true;
};
};
};
Expand Down

0 comments on commit 54c9423

Please sign in to comment.