diff --git a/apps/debug_adapter/lib/debug_adapter/server.ex b/apps/debug_adapter/lib/debug_adapter/server.ex index e373a04ea..92619ae84 100644 --- a/apps/debug_adapter/lib/debug_adapter/server.ex +++ b/apps/debug_adapter/lib/debug_adapter/server.ex @@ -2925,8 +2925,7 @@ defmodule ElixirLS.DebugAdapter.Server do if String.ends_with?(file, ".ex") or String.ends_with?(file, ".exs") do code = File.read!(file) buffer_file_metadata = ElixirSense.Core.Parser.parse_string(code, false, true, {line, 1}) - - env = ElixirSense.Core.Metadata.get_env(buffer_file_metadata, {line, 1}) + env = Metadata.get_cursor_env(buffer_file_metadata, {line, 1}) {buffer_file_metadata, env, ElixirSense.Core.State.Env.to_macro_env(env, file, line)} else diff --git a/apps/language_server/lib/language_server/providers/code_action/replace_remote_function.ex b/apps/language_server/lib/language_server/providers/code_action/replace_remote_function.ex index 52031c4b2..4e9c3168f 100644 --- a/apps/language_server/lib/language_server/providers/code_action/replace_remote_function.ex +++ b/apps/language_server/lib/language_server/providers/code_action/replace_remote_function.ex @@ -12,6 +12,7 @@ defmodule ElixirLS.LanguageServer.Providers.CodeAction.ReplaceRemoteFunction do alias ElixirLS.LanguageServer.Providers.CodeMod.Text alias ElixirLS.LanguageServer.SourceFile alias ElixirSense.Core.Parser + alias ElixirSense.Core.Metadata import ElixirLS.LanguageServer.Providers.CodeAction.Helpers @@ -180,12 +181,9 @@ defmodule ElixirLS.LanguageServer.Providers.CodeAction.ReplaceRemoteFunction do defp aliases_at(source_file, line_number) do one_based_line = line_number + 1 - metadata = Parser.parse_string(source_file.text, true, true, {one_based_line, 1}) - - case metadata.lines_to_env[one_based_line] do - %ElixirSense.Core.State.Env{aliases: aliases} -> {:ok, aliases} - _ -> :error - end + metadata = Parser.parse_string(source_file.text, true, false, {one_based_line, 1}) + env = Metadata.get_cursor_env(metadata, {one_based_line, 1}) + {:ok, env.aliases} end defp module_to_alias(module) do diff --git a/apps/language_server/lib/language_server/providers/completion/suggestion.ex b/apps/language_server/lib/language_server/providers/completion/suggestion.ex index 5199afeba..adb407d29 100644 --- a/apps/language_server/lib/language_server/providers/completion/suggestion.ex +++ b/apps/language_server/lib/language_server/providers/completion/suggestion.ex @@ -113,7 +113,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Suggestion do metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) {text_before, text_after} = Source.split_at(code, line, column) @@ -192,17 +192,18 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Suggestion do # TODO this may no longer be needed # only fix_incomplete_call has some tests depending on it + # on 1.17 no tests depend on those hacks fixers = [ - fix_incomplete_call, - fix_incomplete_kw, - fix_incomplete_kw_key + # fix_incomplete_call, + # fix_incomplete_kw, + # fix_incomplete_kw_key ] - Enum.reduce_while(fixers, nil, fn fun, _ -> + Enum.reduce_while(fixers, metadata, fn fun, metadata -> new_buffer = fun.(text_before, text_after) with true <- new_buffer != nil, - meta <- Parser.parse_string(new_buffer, false, true, {line, column}), + meta <- Parser.parse_string(new_buffer, false, false, {line, column}), %Metadata{error: error} <- meta, true <- error == nil do {:halt, meta} diff --git a/apps/language_server/lib/language_server/providers/definition/locator.ex b/apps/language_server/lib/language_server/providers/definition/locator.ex index 1a7fa1c48..0a7d19015 100644 --- a/apps/language_server/lib/language_server/providers/definition/locator.ex +++ b/apps/language_server/lib/language_server/providers/definition/locator.ex @@ -34,7 +34,7 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.Locator do context -> metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) env = Metadata.get_cursor_env(metadata, {line, column}, {context.begin, context.end}) diff --git a/apps/language_server/lib/language_server/providers/execute_command/expand_macro.ex b/apps/language_server/lib/language_server/providers/execute_command/expand_macro.ex index c9302bbbe..e07ae4b6c 100644 --- a/apps/language_server/lib/language_server/providers/execute_command/expand_macro.ex +++ b/apps/language_server/lib/language_server/providers/execute_command/expand_macro.ex @@ -52,9 +52,8 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro do end def expand_full(buffer, code, file, line) do - buffer_file_metadata = Parser.parse_string(buffer, true, true, {line, 1}) - - env = Metadata.get_env(buffer_file_metadata, {line, 1}) + buffer_file_metadata = Parser.parse_string(buffer, true, false, {line, 1}) + env = Metadata.get_cursor_env(buffer_file_metadata, {line, 1}) do_expand_full(code, env, file, line) end diff --git a/apps/language_server/lib/language_server/providers/hover/docs.ex b/apps/language_server/lib/language_server/providers/hover/docs.ex index d418a87bf..4ff12eeef 100644 --- a/apps/language_server/lib/language_server/providers/hover/docs.ex +++ b/apps/language_server/lib/language_server/providers/hover/docs.ex @@ -77,7 +77,7 @@ defmodule ElixirLS.LanguageServer.Providers.Hover.Docs do %{begin: begin_pos, end: end_pos} = context -> metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) env = diff --git a/apps/language_server/lib/language_server/providers/implementation/locator.ex b/apps/language_server/lib/language_server/providers/implementation/locator.ex index fd4b24817..73dec8c81 100644 --- a/apps/language_server/lib/language_server/providers/implementation/locator.ex +++ b/apps/language_server/lib/language_server/providers/implementation/locator.ex @@ -30,10 +30,10 @@ defmodule ElixirLS.LanguageServer.Providers.Implementation.Locator do context -> metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) - env = Metadata.get_env(metadata, {line, column}) + env = Metadata.get_cursor_env(metadata, {line, column}, {context.begin, context.end}) find( context, diff --git a/apps/language_server/lib/language_server/providers/references/locator.ex b/apps/language_server/lib/language_server/providers/references/locator.ex index 810dc4e07..0fc7e0b88 100644 --- a/apps/language_server/lib/language_server/providers/references/locator.ex +++ b/apps/language_server/lib/language_server/providers/references/locator.ex @@ -27,7 +27,7 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do context -> metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) # if context is var try to find env by scope_id diff --git a/apps/language_server/lib/language_server/providers/signature_help/signature.ex b/apps/language_server/lib/language_server/providers/signature_help/signature.ex index d38b141e2..4c4d74aa2 100644 --- a/apps/language_server/lib/language_server/providers/signature_help/signature.ex +++ b/apps/language_server/lib/language_server/providers/signature_help/signature.ex @@ -21,10 +21,10 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.Signature do metadata = Keyword.get_lazy(options, :metadata, fn -> - Parser.parse_string(code, true, true, {line, column}) + Parser.parse_string(code, true, false, {line, column}) end) - env = Metadata.get_env(metadata, {line, column}) + env = Metadata.get_cursor_env(metadata, {line, column}) find(prefix, {line, column}, env, metadata) end