Skip to content

Commit 04968a1

Browse files
committed
fix: remove heuristics and just default to no workspace folders
1 parent 1cf3bd9 commit 04968a1

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

apps/expert/lib/expert/state.ex

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,10 @@ defmodule Expert.State do
6363
response = initialize_result()
6464

6565
projects =
66-
case event.workspace_folders do
67-
nil ->
68-
find_projects(event.root_uri)
69-
70-
_ ->
71-
for %{uri: uri} <- event.workspace_folders,
72-
project = Project.new(uri),
73-
project.mix_project? do
74-
project
75-
end
66+
for %{uri: uri} <- event.workspace_folders || [],
67+
project = Project.new(uri),
68+
project.mix_project? do
69+
project
7670
end
7771

7872
ActiveProjects.set_projects(projects)
@@ -96,34 +90,6 @@ defmodule Expert.State do
9690
Configuration.default(config)
9791
end
9892

99-
defp find_projects(root_uri) do
100-
root_path = Forge.Document.Path.from_uri(root_uri)
101-
root_mix_exs = Path.join(root_path, "mix.exs")
102-
103-
projects =
104-
if File.exists?(root_mix_exs) do
105-
[Project.new(root_uri)]
106-
else
107-
find_multiroot_projects(root_path)
108-
end
109-
110-
if projects == [], do: [Project.new(root_uri)], else: projects
111-
end
112-
113-
defp find_multiroot_projects(root_path) do
114-
mix_exs_blob = Path.join([root_path, "**", "mix.exs"])
115-
116-
for mix_exs_path <- Path.wildcard(mix_exs_blob),
117-
"deps" not in Path.split(mix_exs_path) do
118-
project_uri =
119-
mix_exs_path
120-
|> Path.dirname()
121-
|> Forge.Document.Path.to_uri()
122-
123-
Project.new(project_uri)
124-
end
125-
end
126-
12793
def apply(%__MODULE__{initialized?: false}, request) do
12894
Logger.error("Received #{request.method} before server was initialized")
12995
{:error, :not_initialized}
@@ -257,7 +223,7 @@ defmodule Expert.State do
257223

258224
def apply(%__MODULE__{} = state, %GenLSP.Notifications.TextDocumentDidSave{params: params}) do
259225
uri = params.text_document.uri
260-
project = Forge.Project.project_for_uri(state.configuration.projects, uri)
226+
project = Forge.Project.project_for_uri(ActiveProjects.projects(), uri)
261227

262228
case Document.Store.save(uri) do
263229
:ok ->
@@ -282,7 +248,7 @@ defmodule Expert.State do
282248
end
283249

284250
def apply(%__MODULE__{} = state, %Notifications.WorkspaceDidChangeWatchedFiles{params: params}) do
285-
for project <- state.configuration.projects,
251+
for project <- ActiveProjects.projects(),
286252
change <- params.changes do
287253
params = filesystem_event(project: Project, uri: change.uri, event_type: change.type)
288254
EngineApi.broadcast(project, params)

apps/expert/test/expert/expert_test.exs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ defmodule ExpertTest do
239239

240240
test "supports missing workspace_folders in the request", %{
241241
client: client,
242-
project_root: project_root,
243-
main_project: main_project,
244-
secondary_project: secondary_project
242+
project_root: project_root
245243
} do
246244
assert :ok =
247245
request(
@@ -253,13 +251,7 @@ defmodule ExpertTest do
253251
"capabilities" => %{"workspace" => %{"workspaceFolders" => %{"supported" => true}}}
254252
})
255253

256-
assert [_, _] = projects = Expert.ActiveProjects.projects()
257-
258-
for project <- projects do
259-
assert project.root_uri in [main_project.root_uri, secondary_project.root_uri]
260-
261-
assert_project_alive?(project)
262-
end
254+
assert [] = Expert.ActiveProjects.projects()
263255
end
264256
end
265257

0 commit comments

Comments
 (0)