Skip to content

Commit 16c5664

Browse files
committed
fixup! wip
1 parent b27d981 commit 16c5664

File tree

10 files changed

+51
-56
lines changed

10 files changed

+51
-56
lines changed

apps/engine/lib/engine/engine/api.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ defmodule Engine.Api do
109109
end
110110

111111
def broadcast(%Project{} = project, message) do
112-
dbg(message)
113112
Engine.call(project, Engine, :broadcast, [message])
114113
end
115114

apps/engine/lib/engine/engine/api/proxy.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ defmodule Engine.Api.Proxy do
6868

6969
def broadcast(message) do
7070
mfa = to_mfa(Engine.Dispatch.broadcast(message))
71-
dbg(mfa)
7271
:gen_statem.call(__MODULE__, buffer(contents: mfa))
7372
end
7473

apps/engine/lib/engine/engine/dispatch.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ defmodule Engine.Dispatch do
4040
end
4141

4242
def broadcast(message) do
43-
dbg(message)
4443
:gen_event.notify(__MODULE__, message)
4544
end
4645

apps/engine/lib/engine/engine/dispatch/pub_sub.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ defmodule Engine.Dispatch.PubSub do
2222

2323
def registrations(%__MODULE__{} = state, message_type) do
2424
all = Map.get(state.registrations, :all, [])
25-
dbg(all)
2625
specific = Map.get(state.registrations, message_type, [])
27-
dbg(specific)
2826
all ++ specific
2927
end
3028

@@ -102,13 +100,11 @@ defmodule Engine.Dispatch.PubSub do
102100

103101
@impl :gen_event
104102
def handle_event(message, %State{} = state) do
105-
dbg(message)
106103
message_type = extract_message_type(message)
107104

108105
state
109106
|> State.registrations(message_type)
110-
|> dbg()
111-
|> Enum.each(&send(dbg(&1), message))
107+
|> Enum.each(&send(&1, message))
112108

113109
{:ok, state}
114110
end

apps/expert/lib/expert.ex

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ defmodule Expert do
1010

1111
use GenLSP
1212

13-
# FIXME(mhanberg): these were not being namespaced correctly
1413
@server_specific_messages [
1514
GenLSP.Notifications.TextDocumentDidChange,
1615
GenLSP.Notifications.WorkspaceDidChangeConfiguration,
@@ -53,6 +52,7 @@ defmodule Expert do
5352
end
5453

5554
lsp = assign(lsp, state: state)
55+
{:ok, response} = Forge.Protocol.Convert.to_lsp(response)
5656

5757
{:reply, response, lsp}
5858

@@ -69,10 +69,11 @@ defmodule Expert do
6969
def handle_request(%mod{} = request, lsp) when mod in @server_specific_messages do
7070
GenLSP.error(lsp, "handling server specific request #{Macro.to_string(mod)}")
7171

72-
case apply_to_state(assigns(lsp).state, request) do
73-
{:ok, response, state} ->
74-
{:reply, response, assign(lsp, state: state)}
75-
72+
with {:ok, request} <- Forge.Protocol.Convert.to_native(request),
73+
{:ok, response, state} <- apply_to_state(assigns(lsp).state, request),
74+
{:ok, response} <- Forge.Protocol.Convert.to_lsp(response) do
75+
{:reply, Forge.Protocol.Convert.to_lsp(response), assign(lsp, state: state)}
76+
else
7677
error ->
7778
message = "Failed to handle #{mod}, #{inspect(error)}"
7879
Logger.error(message)
@@ -85,19 +86,13 @@ defmodule Expert do
8586
end
8687
end
8788

88-
# TODO: i'm not sure if we need this
89-
# def handle_message(nil, %State{} = state) do
90-
# # NOTE: This deals with the response after a request is requested by the server,
91-
# # such as the response of `CreateWorkDoneProgress`.
92-
# {:ok, state}
93-
# end
94-
95-
def handle_request(%_{} = request, lsp) do
89+
def handle_request(request, lsp) do
9690
state = assigns(lsp).state
9791

9892
with {:ok, handler} <- fetch_handler(request),
99-
{:ok, req} <- Convert.to_native(request),
100-
{:ok, response} <- handler.handle(req, state.configuration) do
93+
{:ok, request} <- Convert.to_native(request),
94+
{:ok, response} <- handler.handle(request, state.configuration),
95+
{:ok, response} <- Forge.Protocol.Convert.to_lsp(response) do
10196
{:reply, response, lsp}
10297
else
10398
{:error, {:unhandled, _}} ->
@@ -109,30 +104,50 @@ defmodule Expert do
109104
message: "Method not found"
110105
}, lsp}
111106

112-
_ ->
113-
{:noreply, lsp}
107+
error ->
108+
message = "Failed to handle #{request.method}, #{inspect(error)}"
109+
Logger.error(message)
110+
111+
{:reply,
112+
%GenLSP.ErrorResponse{
113+
code: GenLSP.Enumerations.ErrorCodes.internal_error(),
114+
message: message
115+
}, lsp}
114116
end
115117
end
116118

117119
def handle_notification(%mod{} = notification, lsp) when mod in @server_specific_messages do
118-
GenLSP.error(lsp, "handling server specific notification #{Macro.to_string(mod)}")
119-
120-
case apply_to_state(assigns(lsp).state, notification) do
121-
{:ok, state} ->
122-
{:noreply, assign(lsp, state: state)}
123-
120+
with {:ok, notification} <- Convert.to_native(notification),
121+
{:ok, state} <- apply_to_state(assigns(lsp).state, notification) do
122+
{:noreply, assign(lsp, state: state)}
123+
else
124124
error ->
125-
message = "Failed to handle #{mod}, #{inspect(error)}"
125+
message = "Failed to handle #{notification.method}, #{inspect(error)}"
126126
Logger.error(message)
127127

128128
{:noreply, lsp}
129129
end
130130
end
131131

132-
def handle_notification(%mod{}, lsp) do
133-
GenLSP.error(lsp, inspect(@server_specific_messages))
134-
GenLSP.error(lsp, "handling other notification #{inspect(mod)}")
135-
{:noreply, lsp}
132+
def handle_notification(notification, lsp) do
133+
state = assigns(lsp).state
134+
135+
with {:ok, handler} <- fetch_handler(notification),
136+
{:ok, notification} <- Convert.to_native(notification),
137+
{:ok, _response} <- handler.handle(notification, state.configuration) do
138+
{:noreply, lsp}
139+
else
140+
{:error, {:unhandled, _}} ->
141+
Logger.info("Unhandled notification: #{notification.method}")
142+
143+
{:noreply, lsp}
144+
145+
error ->
146+
message = "Failed to handle #{notification.method}, #{inspect(error)}"
147+
Logger.error(message)
148+
149+
{:noreply, lsp}
150+
end
136151
end
137152

138153
def handle_info(:default_config, %State{configuration: nil} = state) do

apps/expert/lib/expert/project/diagnostics.ex

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ defmodule Expert.Project.Diagnostics do
6262
file_diagnostics(uri: uri, build_number: build_number, diagnostics: diagnostics),
6363
%State{} = state
6464
) do
65-
dbg(diagnostics)
66-
6765
state =
6866
case diagnostics do
6967
[] ->
@@ -94,14 +92,13 @@ defmodule Expert.Project.Diagnostics do
9492
# Private
9593

9694
defp publish_diagnostics(%State{} = state) do
97-
dbg(state)
98-
9995
Enum.each(state.entries_by_uri, fn {uri, %State.Entry{} = entry} ->
100-
diagnostics_list = State.Entry.diagnostics(entry)
101-
102-
GenLSP.notify(state.project.lsp, %TextDocumentPublishDiagnostics{
103-
params: %Structures.PublishDiagnosticsParams{uri: uri, diagnostics: diagnostics_list}
104-
})
96+
with {:ok, diagnostics} <-
97+
entry |> State.Entry.diagnostics() |> Forge.Protocol.Convert.to_lsp() do
98+
GenLSP.notify(state.project.lsp, %TextDocumentPublishDiagnostics{
99+
params: %Structures.PublishDiagnosticsParams{uri: uri, diagnostics: diagnostics}
100+
})
101+
end
105102
end)
106103
end
107104

apps/expert/lib/expert/provider/handlers/completion.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ defmodule Expert.Provider.Handlers.Completion do
99
alias GenLSP.Structures
1010
alias GenLSP.Structures.CompletionContext
1111

12-
require Logger
13-
1412
def handle(
1513
%Requests.TextDocumentCompletion{
1614
params: %Structures.CompletionParams{} = params

apps/expert/test/expert/project/diagnostics_test.exs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ defmodule Expert.Project.DiagnosticsTest do
3939
test = self()
4040

4141
patch(GenLSP, :notify_server, fn _, message ->
42-
dbg(message)
4342
send(test, {:transport, message})
4443
end)
4544

@@ -92,9 +91,7 @@ defmodule Expert.Project.DiagnosticsTest do
9291
}
9392
}}
9493

95-
dbg(self())
96-
97-
Document.Store.get_and_update(document.uri, &{:ok, Document.mark_clean(&1)}) |> dbg()
94+
Document.Store.get_and_update(document.uri, &{:ok, Document.mark_clean(&1)})
9895

9996
Engine.Api.broadcast(project, project_compile_requested())
10097
Engine.Api.broadcast(project, project_diagnostics(diagnostics: []))

apps/expert/test/support/test/dispatch_fake.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ defmodule Expert.Test.DispatchFake do
1717
end)
1818

1919
patch(Engine.Api, :broadcast, fn _project, message ->
20-
dbg(message)
2120
Dispatch.broadcast(message)
2221
end)
2322

apps/forge/lib/forge/document/store.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,11 @@ defmodule Forge.Document.Store do
134134
@spec get_and_update(t, Forge.uri(), Store.updater()) ::
135135
{:ok, Document.t(), t} | {:error, any()}
136136
def get_and_update(%__MODULE__{} = store, uri, updater_fn) do
137-
dbg(self())
138-
139137
with {:ok, open_doc(document: document)} <- Map.fetch(store.open, uri),
140138
{:ok, document} <- updater_fn.(document) do
141-
dbg(document)
142139
{:ok, document, put_open_doc(store, document)}
143140
else
144141
error ->
145-
dbg(error)
146142
normalize_error(error)
147143
end
148144
end

0 commit comments

Comments
 (0)