From aa273e3741bb0576d423a5d86461597f97185e42 Mon Sep 17 00:00:00 2001 From: Daniil Leontev Date: Sun, 30 Mar 2025 16:11:59 +0200 Subject: [PATCH] fix: return empty response to textDocument/formatting if no changes Do not send "edits" if the content remains unchanged after LSP formatting. Otherwise, Neovim reports an unsaved buffer even when no actual changes were made --- changelog.md | 1 + script/core/formatting.lua | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/changelog.md b/changelog.md index 7c92fd523..893eaaf8b 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` prevent unnecessary edits by LSP formatting when content did not change ## 3.13.9 `2025-3-13` diff --git a/script/core/formatting.lua b/script/core/formatting.lua index de7f30ed9..d9fcf4444 100644 --- a/script/core/formatting.lua +++ b/script/core/formatting.lua @@ -21,6 +21,10 @@ return function(uri, options) return end + if text == formattedText then + return + end + return { { start = state.ast.start,