Skip to content

Commit

Permalink
PR Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
scohen committed Dec 10, 2024
1 parent ea42c2d commit 01fa37b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions apps/remote_control/lib/lexical/remote_control/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/server/lib/lexical/server/task_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: %{}
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions projects/lexical_shared/lib/lexical/debug.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 01fa37b

Please sign in to comment.