From d4f7e7148ae2e90182f6b4746dd95e0463a73cb3 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Wed, 7 Feb 2024 22:43:31 +0100 Subject: [PATCH] increase compatibility --- .../lib/language_server/ast_utils.ex | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/language_server/lib/language_server/ast_utils.ex b/apps/language_server/lib/language_server/ast_utils.ex index dc923a83c..c2d6d54f7 100644 --- a/apps/language_server/lib/language_server/ast_utils.ex +++ b/apps/language_server/lib/language_server/ast_utils.ex @@ -68,7 +68,10 @@ defmodule ElixirLS.LanguageServer.AstUtils do end lines = SourceFile.lines(literal) - {line + length(lines), meta[:indentation] + get_delimiter_length(delimiter)} + # meta[:indentation] is nil on 1.12 + indentation = Keyword.get(meta, :indentation, 0) + + {line + length(lines), indentation + get_delimiter_length(delimiter)} else get_literal_end(literal, {line, column}, delimiter) end @@ -194,13 +197,18 @@ defmodule ElixirLS.LanguageServer.AstUtils do form == :__aliases__ -> last = meta[:last] - last_length = - case List.last(args) do - atom when is_atom(atom) -> atom |> to_string() |> String.length() - _ -> 0 - end + if last do + last_length = + case List.last(args) do + atom when is_atom(atom) -> atom |> to_string() |> String.length() + _ -> 0 + end - {last[:line] - 1, last[:column] - 1 + last_length} + {last[:line] - 1, last[:column] - 1 + last_length} + else + # last is nil on 1.12 + get_eoe_by_formatting(ast, {line, column}) + end form == :% and match?([_, _], args) -> [_alias, map] = args