From 6b61beb0ef6ccb193640e0a28ad466216a583b78 Mon Sep 17 00:00:00 2001 From: n3oney Date: Tue, 23 May 2023 22:53:18 +0200 Subject: [PATCH 1/2] feat: give null-ls priority over other formatters --- docs/release-notes/rl-0.4.adoc | 2 ++ modules/lsp/config.nix | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/rl-0.4.adoc b/docs/release-notes/rl-0.4.adoc index 318732e0..1d9076ae 100644 --- a/docs/release-notes/rl-0.4.adoc +++ b/docs/release-notes/rl-0.4.adoc @@ -20,6 +20,8 @@ https://github.com/n3oney[n3oney]: * Refactored the resolveDag function - you can just provide a string now, which will default to dag.entryAnywhere +* Fixed formatting issues and gave null-ls priority over other formatters + https://github.com/horriblename[horriblename]: * Added `clangd` as alternative lsp for C/++. diff --git a/modules/lsp/config.nix b/modules/lsp/config.nix index bcd69d49..10851187 100644 --- a/modules/lsp/config.nix +++ b/modules/lsp/config.nix @@ -39,15 +39,43 @@ in { local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) format_callback = function(client, bufnr) - if vim.g.formatsave and client.supports_method("textDocument/formatting") then + if vim.g.formatsave then vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_create_autocmd("BufWritePre", { group = augroup, buffer = bufnr, callback = function() - vim.lsp.buf.format({ - bufnr = bufnr + ${ + if config.vim.lsp.null-ls.enable + then '' + 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( + file_type, + require("null-ls.methods").internal.FORMATTING + ) + return #generators > 0 + end + + if is_null_ls_formatting_enabled(bufnr) then + vim.lsp.buf.format({ + bufnr = bufnr, + filter = function(client) + return client.name == "null-ls" + end }) + else + vim.lsp.buf.format({ + bufnr = bufnr, + }) + end + '' + else " + vim.lsp.buf.format({ + bufnr = bufnr, + }) + " + } end, }) end From 9d3f74b70cb50d09ca481df35224e8284679d4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= <30625554+n3oney@users.noreply.github.com> Date: Fri, 26 May 2023 08:59:24 +0200 Subject: [PATCH 2/2] chore: update release notes --- docs/release-notes/rl-0.4.adoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/rl-0.4.adoc b/docs/release-notes/rl-0.4.adoc index 1d9076ae..7093debf 100644 --- a/docs/release-notes/rl-0.4.adoc +++ b/docs/release-notes/rl-0.4.adoc @@ -20,7 +20,11 @@ https://github.com/n3oney[n3oney]: * Refactored the resolveDag function - you can just provide a string now, which will default to dag.entryAnywhere -* Fixed formatting issues and gave null-ls priority over other formatters +* Fixed formatting sometimes removing parts of files + +* Made formatting synchronous + +* Gave null-ls priority over other formatters https://github.com/horriblename[horriblename]: