Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow disabling format on save per buffer #156

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release-notes/rl-0.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ https://github.com/horriblename[horriblename]:

* Add lua LSP and treesitter support, and neodev.nvim plugin support

* Add <<opt-vim.lsp.mappings.toggleFormatOnSave>> keybind

https://github.com/amanse[amanse]:

* Added daily notes options for obsidian plugin
Expand Down
5 changes: 5 additions & 0 deletions modules/lsp/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ in {
${mkBinding mappings.renameSymbol "vim.lsp.buf.rename()"}
${mkBinding mappings.codeAction "vim.lsp.buf.code_action()"}
${mkBinding mappings.format "vim.lsp.buf.format()"}
${mkBinding mappings.toggleFormatOnSave "vim.b.disableFormatSave = not vim.b.disableFormatSave"}
end

-- Enable formatting
Expand All @@ -56,6 +57,10 @@ in {
${
if config.vim.lsp.null-ls.enable
then ''
if vim.b.disableFormatSave then
return
end

local function is_null_ls_formatting_enabled(bufnr)
local file_type = vim.api.nvim_buf_get_option(bufnr, "filetype")
local generators = require("null-ls.generators").get_available(
Expand Down
3 changes: 3 additions & 0 deletions modules/lsp/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ in {
format =
mkMappingOption "Format"
"<leader>lf";
toggleFormatOnSave =
mkMappingOption "Toggle format on save"
"<leader>ltf";
};
};
}
Loading