From 01fa37b3732345ae676880f119cd63757b92415b Mon Sep 17 00:00:00 2001 From: Steve Cohen Date: Tue, 10 Dec 2024 09:01:42 -0800 Subject: [PATCH] PR Suggestions --- .../lib/lexical/remote_control/completion.ex | 9 ++++----- apps/server/lib/lexical/server/task_queue.ex | 4 ++-- projects/lexical_shared/lib/lexical/debug.ex | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/remote_control/lib/lexical/remote_control/completion.ex b/apps/remote_control/lib/lexical/remote_control/completion.ex index 94a3cadb2..fedd3a558 100644 --- a/apps/remote_control/lib/lexical/remote_control/completion.ex +++ b/apps/remote_control/lib/lexical/remote_control/completion.ex @@ -8,7 +8,7 @@ defmodule Lexical.RemoteControl.Completion do alias Lexical.RemoteControl.Completion.Candidate import Document.Line - import Lexical.Debug + import Lexical.Logging def elixir_sense_expand(%Env{} = env) do {doc_string, position} = strip_struct_operator(env) @@ -21,19 +21,18 @@ defmodule Lexical.RemoteControl.Completion do [] else {_formatter, opts} = - log_timed("formatter for file", fn -> + timed_log("formatter for file", fn -> Format.formatter_for_file(env.project, env.document.path) end) - locals_without_parens = Keyword.fetch!(opts, :locals_without_parens) for suggestion <- - log_timed("ES suggestions", fn -> + timed_log("ES suggestions", fn -> ElixirSense.suggestions(doc_string, line, character) end), candidate = - log_timed("from_elixir_sense", fn -> + timed_log("from_elixir_sense", fn -> from_elixir_sense(suggestion, locals_without_parens) end), candidate != nil do diff --git a/apps/server/lib/lexical/server/task_queue.ex b/apps/server/lib/lexical/server/task_queue.ex index 44c7dc0ff..c31f2d3ff 100644 --- a/apps/server/lib/lexical/server/task_queue.ex +++ b/apps/server/lib/lexical/server/task_queue.ex @@ -3,7 +3,7 @@ defmodule Lexical.Server.TaskQueue do alias Lexical.Proto.Convert alias Lexical.Proto.LspTypes.ResponseError alias Lexical.Server.Transport - import Lexical.Debug + import Lexical.Logging require Logger defstruct ids_to_tasks: %{}, pids_to_ids: %{} @@ -99,7 +99,7 @@ defmodule Lexical.Server.TaskQueue do end defp write_reply(response) do - case log_timed("convert", fn -> Convert.to_lsp(response) end) do + case timed_log("convert", fn -> Convert.to_lsp(response) end) do {:ok, lsp_response} -> Transport.write(lsp_response) diff --git a/projects/lexical_shared/lib/lexical/debug.ex b/projects/lexical_shared/lib/lexical/debug.ex index 382a5a236..0e09f8a28 100644 --- a/projects/lexical_shared/lib/lexical/debug.ex +++ b/projects/lexical_shared/lib/lexical/debug.ex @@ -1,17 +1,17 @@ -defmodule Lexical.Debug do +defmodule Lexical.Logging do require Logger defmacro timed(label, do: block) do if enabled?() do quote do - log_timed(unquote(label), fn -> unquote(block) end) + timed_log(unquote(label), fn -> unquote(block) end) end else block end end - def log_timed(label, threshold_ms \\ 1, function) when is_function(function, 0) do + def timed_log(label, threshold_ms \\ 1, function) when is_function(function, 0) do if enabled?() do {elapsed_us, result} = :timer.tc(function) elapsed_ms = elapsed_us / 1000