From a238a27061197580f12eedf3229072c457e01b44 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Wed, 7 Feb 2024 00:14:42 +0100 Subject: [PATCH] add comments on workaround --- .../language_server/lib/language_server/ast_utils.ex | 12 ++++++++++-- .../language_server/providers/selection_ranges.ex | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/language_server/lib/language_server/ast_utils.ex b/apps/language_server/lib/language_server/ast_utils.ex index eb80d6572..a2a599bd2 100644 --- a/apps/language_server/lib/language_server/ast_utils.ex +++ b/apps/language_server/lib/language_server/ast_utils.ex @@ -119,8 +119,16 @@ defmodule ElixirLS.LanguageServer.AstUtils do {start_line, start_column} = cond do form == :%{} -> - # TODO elixir parser bug? - {line, column - 1} + column = + if Version.match?(System.version(), "< 1.16.2") do + # workaround elixir bug + # https://github.com/elixir-lang/elixir/commit/fd4e6b530c0e010712b06909c89820b08e49c238 + column - 1 + else + column + end + + {line, column} form == :-> and match?([[_ | _], _], args) -> [[left | _], _right] = args diff --git a/apps/language_server/lib/language_server/providers/selection_ranges.ex b/apps/language_server/lib/language_server/providers/selection_ranges.ex index 75ddbd017..5e794be26 100644 --- a/apps/language_server/lib/language_server/providers/selection_ranges.ex +++ b/apps/language_server/lib/language_server/providers/selection_ranges.ex @@ -355,7 +355,10 @@ defmodule ElixirLS.LanguageServer.Providers.SelectionRanges do case AstUtils.node_range(ast) do range(start_line, start_character, end_line, end_character) -> start_character = - if form == :%{} and match?({:%, _, _}, parent_ast_from_stack) do + if form == :%{} and match?({:%, _, _}, parent_ast_from_stack) and + Version.match?(System.version(), "< 1.16.2") do + # workaround elixir bug + # https://github.com/elixir-lang/elixir/commit/fd4e6b530c0e010712b06909c89820b08e49c238 # undo column offset for structs inner map node start_character + 1 else