From d43afa4316455684da5a02b0ecf93c15d41f8080 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 14 Oct 2023 15:01:34 +0200 Subject: [PATCH] feat: keybind to toggle format on save --- modules/lsp/config.nix | 5 +++++ modules/lsp/module.nix | 3 +++ 2 files changed, 8 insertions(+) diff --git a/modules/lsp/config.nix b/modules/lsp/config.nix index 9cbe760..eacbfa2 100644 --- a/modules/lsp/config.nix +++ b/modules/lsp/config.nix @@ -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 @@ -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( diff --git a/modules/lsp/module.nix b/modules/lsp/module.nix index 9b24825..38d73b1 100644 --- a/modules/lsp/module.nix +++ b/modules/lsp/module.nix @@ -63,6 +63,9 @@ in { format = mkMappingOption "Format" "lf"; + toggleFormatOnSave = + mkMappingOption "Toggle format on save" + "ltf"; }; }; }