From 2b517b2b562aaf7948aeaa00d6d61d466f78e378 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Tue, 18 Jul 2023 21:31:42 +0200 Subject: [PATCH] remove not needed regex recompiles --- apps/language_server/lib/language_server/cli.ex | 2 +- .../lib/language_server/dialyzer.ex | 2 +- .../lib/language_server/erlang_source_file.ex | 6 +++--- .../lib/language_server/providers/completion.ex | 16 ++++++++-------- .../providers/execute_command/apply_spec.ex | 2 +- .../providers/on_type_formatting.ex | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/language_server/lib/language_server/cli.ex b/apps/language_server/lib/language_server/cli.ex index 7f6c7e77c..d732d61dc 100644 --- a/apps/language_server/lib/language_server/cli.ex +++ b/apps/language_server/lib/language_server/cli.ex @@ -132,7 +132,7 @@ defmodule ElixirLS.LanguageServer.CLI do erlang_erl_path = beam_filename |> to_string - |> String.replace(Regex.recompile!(~r/(.+)\/ebin\/([^\s]+)\.beam$/), "\\1/src/\\2.erl") + |> String.replace(~r/(.+)\/ebin\/([^\s]+)\.beam$/, "\\1/src/\\2.erl") unless File.exists?(erlang_erl_path, [:raw]) do dir = Path.join(erlang_erl_path, "../../../..") |> Path.expand() diff --git a/apps/language_server/lib/language_server/dialyzer.ex b/apps/language_server/lib/language_server/dialyzer.ex index 962625175..3b2aa7408 100644 --- a/apps/language_server/lib/language_server/dialyzer.ex +++ b/apps/language_server/lib/language_server/dialyzer.ex @@ -570,7 +570,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do defp dialyzer_raw_warning_message(raw_warning) do message = String.trim(to_string(:dialyzer.format_warning(raw_warning))) - Regex.replace(Regex.recompile!(~r/^.*:\d+: /), message, "") + Regex.replace(~r/^.*:\d+: /, message, "") end # Because mtime-based stale-checking has 1-second granularity, we err on the side of diff --git a/apps/language_server/lib/language_server/erlang_source_file.ex b/apps/language_server/lib/language_server/erlang_source_file.ex index ecc1ff31c..f57f81431 100644 --- a/apps/language_server/lib/language_server/erlang_source_file.ex +++ b/apps/language_server/lib/language_server/erlang_source_file.ex @@ -14,13 +14,13 @@ defmodule ElixirLS.LanguageServer.ErlangSourceFile do beam_file |> to_string |> String.replace( - Regex.recompile!(~r/(.+)\/ebin\/([^\s]+)\.beam$/), + ~r/(.+)\/ebin\/([^\s]+)\.beam$/, "\\1/src/\\2.erl" ) end def module_line(file) do - find_line_by_regex(file, Regex.recompile!(~r/^-module/)) + find_line_by_regex(file, ~r/^-module/) end def function_line(file, function) do @@ -30,7 +30,7 @@ defmodule ElixirLS.LanguageServer.ErlangSourceFile do |> Atom.to_string() |> Regex.escape() - find_line_by_regex(file, Regex.recompile!(~r/^#{escaped}\b/)) + find_line_by_regex(file, ~r/^#{escaped}\b/) end defp find_line_by_regex(file, regex) do diff --git a/apps/language_server/lib/language_server/providers/completion.ex b/apps/language_server/lib/language_server/providers/completion.ex index fbcb861eb..5cfd20eeb 100644 --- a/apps/language_server/lib/language_server/providers/completion.ex +++ b/apps/language_server/lib/language_server/providers/completion.ex @@ -119,11 +119,11 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do def_before = cond do - Regex.match?(Regex.recompile!(~r/(defdelegate|defp?)\s*#{prefix}$/), text_before_cursor) -> + Regex.match?(~r/(defdelegate|defp?)\s*#{prefix}$/, text_before_cursor) -> :def Regex.match?( - Regex.recompile!(~r/(defguardp?|defmacrop?)\s*#{prefix}$/), + ~r/(defguardp?|defmacrop?)\s*#{prefix}$/, text_before_cursor ) -> :defmacro @@ -138,8 +138,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do prefix: prefix, remote_calls?: match?({:dot, _, _}, Code.Fragment.cursor_context(prefix)), def_before: def_before, - pipe_before?: Regex.match?(Regex.recompile!(~r/\|>\s*#{prefix}$/), text_before_cursor), - capture_before?: Regex.match?(Regex.recompile!(~r/&#{prefix}$/), text_before_cursor), + pipe_before?: Regex.match?(~r/\|>\s*#{prefix}$/, text_before_cursor), + capture_before?: Regex.match?(~r/&#{prefix}$/, text_before_cursor), scope: scope, module: env.module } @@ -302,7 +302,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do %{def_before: nil, capture_before?: false, pipe_before?: false}, _options ) do - snippet = Regex.replace(Regex.recompile!(~r/"\$\{(.*)\}\$"/U), snippet, "${\\1}") + snippet = Regex.replace(~r/"\$\{(.*)\}\$"/U, snippet, "${\\1}") %__MODULE__{ label: description, @@ -991,7 +991,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do end defp get_prefix(text_before_cursor) do - regex = Regex.recompile!(~r/[\w0-9\._!\?\:@\->]+$/) + regex = ~r/[\w0-9\._!\?\:@\->]+$/ case Regex.run(regex, text_before_cursor) do [prefix] -> prefix @@ -1113,7 +1113,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do defp use_name_only?(module_name, function_name) do module_name in @use_name_only or {module_name, function_name} in @use_name_only or String.starts_with?(function_name, "__") or - function_name =~ Regex.recompile!(~r/^[^a-zA-Z0-9]+$/) + function_name =~ ~r/^[^a-zA-Z0-9]+$/ end defp sort_items(items) do @@ -1126,7 +1126,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do priority end - {priority, label =~ Regex.recompile!(~r/^[^a-zA-Z0-9]/), label} + {priority, label =~ ~r/^[^a-zA-Z0-9]/, label} end) end diff --git a/apps/language_server/lib/language_server/providers/execute_command/apply_spec.ex b/apps/language_server/lib/language_server/providers/execute_command/apply_spec.ex index 9c61154cd..3041ecab7 100644 --- a/apps/language_server/lib/language_server/providers/execute_command/apply_spec.ex +++ b/apps/language_server/lib/language_server/providers/execute_command/apply_spec.ex @@ -49,7 +49,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ApplySpec do end cur_line = Enum.at(SourceFile.lines(cur_text), line - 1) - [indentation] = Regex.run(Regex.recompile!(~r/^\s*/), cur_line) + [indentation] = Regex.run(~r/^\s*/, cur_line) # Attempt to format to fit within the preferred line length, fallback to having it all on one # line if anything fails diff --git a/apps/language_server/lib/language_server/providers/on_type_formatting.ex b/apps/language_server/lib/language_server/providers/on_type_formatting.ex index 6665b1376..b45f2cb22 100644 --- a/apps/language_server/lib/language_server/providers/on_type_formatting.ex +++ b/apps/language_server/lib/language_server/providers/on_type_formatting.ex @@ -57,11 +57,11 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do end defp tokens(line) do - Regex.scan(Regex.recompile!(~r/(?:->)|(?:[\w\:]+)/), line) |> List.flatten() + Regex.scan(~r/(?:->)|(?:[\w\:]+)/, line) |> List.flatten() end defp indentation(line) do - [indentation] = Regex.run(Regex.recompile!(~r/^\s*/), line) + [indentation] = Regex.run(~r/^\s*/, line) indentation end