From 57521cebfd8d5ca56c74c43e3fbdbc85fb517800 Mon Sep 17 00:00:00 2001 From: Samuel Heldak Date: Thu, 14 Mar 2024 10:02:04 +0100 Subject: [PATCH] no code action for potentially unformatted line --- .../language_server/providers/code_action/helpers.ex | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/language_server/lib/language_server/providers/code_action/helpers.ex b/apps/language_server/lib/language_server/providers/code_action/helpers.ex index 3dab92000..f5c4ea91e 100644 --- a/apps/language_server/lib/language_server/providers/code_action/helpers.ex +++ b/apps/language_server/lib/language_server/providers/code_action/helpers.ex @@ -15,9 +15,7 @@ defmodule ElixirLS.LanguageServer.Providers.CodeAction.Helpers do is_line_formatted = unformatted_text |> Diff.diff(formatted_text) - |> Enum.filter(fn %TextEdit{range: range} -> - range["start"]["line"] == changed_line or range["end"]["line"] == changed_line - end) + |> Enum.filter(&near_changed_line(&1, changed_line)) |> Enum.empty?() if is_line_formatted do @@ -28,6 +26,13 @@ defmodule ElixirLS.LanguageServer.Providers.CodeAction.Helpers do end end + defp near_changed_line(%TextEdit{range: range}, changed_line) do + changed_line_neighborhood = [changed_line - 1, changed_line, changed_line + 1] + + range["start"]["line"] in changed_line_neighborhood or + range["end"]["line"] in changed_line_neighborhood + end + defp changed_line(text_edits) do lines = text_edits