Skip to content

Commit 415c190

Browse files
committed
Log project uri
1 parent d71cc76 commit 415c190

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

apps/expert/lib/expert.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ defmodule Expert do
5959
Task.Supervisor.start_child(:expert_task_queue, fn ->
6060
config = state.configuration
6161

62-
log_info(lsp, "Starting project at uri #{config.project.root_uri}")
62+
log_info(lsp, "Starting project")
6363

6464
start_result = Project.Supervisor.start(config.project)
6565

@@ -209,13 +209,15 @@ defmodule Expert do
209209
end
210210

211211
def log_info(lsp \\ get_lsp(), message) do
212+
message = log_prepend_project_root(message, assigns(lsp).state)
212213
Logger.info(message)
213214

214215
GenLSP.info(lsp, message)
215216
end
216217

217218
# When logging errors we also notify the client to display the message
218219
def log_error(lsp \\ get_lsp(), message) do
220+
message = log_prepend_project_root(message, assigns(lsp).state)
219221
Logger.error(message)
220222

221223
log_level = Enumerations.MessageType.error()
@@ -331,4 +333,12 @@ defmodule Expert do
331333
"Failed to start engine #{name}: #{inspect(reason)}"
332334
end
333335
end
336+
337+
defp log_prepend_project_root(message, %State{
338+
configuration: %Expert.Configuration{project: %Forge.Project{} = project}
339+
}) do
340+
"[Project #{project.root_uri}] #{message}"
341+
end
342+
343+
defp log_prepend_project_root(message, _state), do: message
334344
end

apps/expert/test/expert_test.exs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
defmodule Expert.ExpertTest do
2+
alias Expert.State
3+
alias Forge.Test.Fixtures
4+
25
use ExUnit.Case, async: true
36
use Patch
47

@@ -8,15 +11,39 @@ defmodule Expert.ExpertTest do
811
with_patched_transport()
912

1013
assigns = start_supervised!(GenLSP.Assigns, id: make_ref())
11-
GenLSP.Assigns.merge(assigns, %{state: %{}})
14+
project = Fixtures.project()
15+
16+
root_uri = project.root_uri
17+
root_path = Forge.Project.root_path(project)
18+
19+
request = %GenLSP.Requests.Initialize{
20+
id: 1,
21+
jsonrpc: "2.0",
22+
method: "initialize",
23+
params: %GenLSP.Structures.InitializeParams{
24+
capabilities: %GenLSP.Structures.ClientCapabilities{},
25+
process_id: "",
26+
root_uri: root_uri,
27+
root_path: root_path,
28+
workspace_folders: [
29+
%GenLSP.Structures.WorkspaceFolder{
30+
name: root_path,
31+
uri: root_uri
32+
}
33+
]
34+
}
35+
}
36+
37+
{:ok, _response, state} = State.initialize(State.new(), request)
38+
GenLSP.Assigns.merge(assigns, %{state: state})
1239

1340
lsp = %GenLSP.LSP{mod: Expert, assigns: assigns}
1441

1542
reason = :something_bad
1643

1744
assert {:noreply, ^lsp} = Expert.handle_info({:engine_initialized, {:error, reason}}, lsp)
1845

19-
error_message = "Failed to initialize: #{inspect(reason)}"
46+
error_message = "[Project #{project.root_uri}] Failed to initialize: #{inspect(reason)}"
2047
error_message_type = GenLSP.Enumerations.MessageType.error()
2148

2249
assert_receive {:transport,

0 commit comments

Comments
 (0)