Skip to content

Commit 90ab70a

Browse files
committed
chore: add tests
1 parent 5f32c6a commit 90ab70a

File tree

18 files changed

+540
-16
lines changed

18 files changed

+540
-16
lines changed

apps/expert/lib/expert/configuration.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Expert.Configuration do
2626

2727
@dialyzer {:nowarn_function, set_dialyzer_enabled: 2}
2828

29-
@spec new(map(), String.t() | nil) :: t
29+
@spec new(Structures.ClientCapabilities.t(), String.t() | nil) :: t
3030
def new(%Structures.ClientCapabilities{} = client_capabilities, client_name) do
3131
support = Support.new(client_capabilities)
3232

apps/expert/lib/expert/project/supervisor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule Expert.Project.Supervisor do
3939
DynamicSupervisor.terminate_child(Expert.Project.DynamicSupervisor.name(), pid)
4040
end
4141

42-
defp name(%Project{} = project) do
42+
def name(%Project{} = project) do
4343
:"#{Project.name(project)}::supervisor"
4444
end
4545
end

apps/expert/lib/expert/state.ex

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defmodule Expert.State do
5151
_ -> nil
5252
end
5353

54-
root_path = Forge.Document.Path.from_uri(event.root_uri)
54+
root_path = Document.Path.from_uri(event.root_uri)
5555

5656
root_path
5757
|> Forge.Workspace.new()
@@ -126,8 +126,19 @@ defmodule Expert.State do
126126
removed_projects =
127127
for %{uri: uri} <- removed do
128128
project = Project.new(uri)
129-
Logger.info("Stopping project at uri #{uri}")
129+
130130
Expert.Project.Supervisor.stop(project)
131+
132+
GenLSP.notify(
133+
Expert.get_lsp(),
134+
%GenLSP.Notifications.WindowLogMessage{
135+
params: %GenLSP.Structures.LogMessageParams{
136+
type: GenLSP.Enumerations.MessageType.info(),
137+
message: "Stopping project node for #{Project.name(project)}"
138+
}
139+
}
140+
)
141+
131142
project
132143
end
133144

@@ -138,10 +149,8 @@ defmodule Expert.State do
138149
project
139150
end
140151

141-
projects =
142-
Enum.uniq((added_projects ++ ActiveProjects.projects()) -- removed_projects)
143-
144-
ActiveProjects.set_projects(projects)
152+
ActiveProjects.add_projects(added_projects)
153+
ActiveProjects.remove_projects(removed_projects)
145154

146155
state = %__MODULE__{state | workspace_folders: workspace_folders}
147156

@@ -188,12 +197,8 @@ defmodule Expert.State do
188197
config = state.configuration
189198

190199
project =
191-
case Enum.find(ActiveProjects.projects(), &Project.within_project?(&1, uri)) do
192-
nil ->
193-
Project.find_project(uri)
194-
195-
project ->
196-
project
200+
with nil <- Enum.find(ActiveProjects.projects(), &Project.within_project?(&1, uri)) do
201+
Project.find_project(uri)
197202
end
198203

199204
if project do
@@ -203,11 +208,10 @@ defmodule Expert.State do
203208

204209
case Document.Store.open(uri, text, version, language_id) do
205210
:ok ->
206-
Logger.info("################### opened #{uri}")
207211
{:ok, %{state | configuration: config}}
208212

209213
error ->
210-
Logger.error("################## Could not open #{uri} #{inspect(error)}")
214+
Logger.error("Could not open #{uri} #{inspect(error)}")
211215
error
212216
end
213217
end
@@ -274,13 +278,35 @@ defmodule Expert.State do
274278
{:ok, _pid} ->
275279
Logger.info("Project node started for #{Project.name(project)}")
276280

281+
GenLSP.notify(
282+
Expert.get_lsp(),
283+
%GenLSP.Notifications.WindowLogMessage{
284+
params: %GenLSP.Structures.LogMessageParams{
285+
type: GenLSP.Enumerations.MessageType.info(),
286+
message: "Started project node for #{Project.name(project)}"
287+
}
288+
}
289+
)
290+
277291
{:error, {reason, pid}} when reason in [:already_started, :already_present] ->
278292
{:ok, pid}
279293

280294
{:error, reason} ->
281295
Logger.error(
282296
"Failed to start project node for #{Project.name(project)}: #{inspect(reason, pretty: true)}"
283297
)
298+
299+
GenLSP.notify(
300+
Expert.get_lsp(),
301+
%GenLSP.Notifications.WindowLogMessage{
302+
params: %GenLSP.Structures.LogMessageParams{
303+
type: GenLSP.Enumerations.MessageType.error(),
304+
message: "Failed to start project node for #{Project.name(project)}"
305+
}
306+
}
307+
)
308+
309+
{:error, reason}
284310
end
285311
end
286312

0 commit comments

Comments
 (0)