Skip to content

Commit 7dde1e5

Browse files
committed
correctly handle non standard deps_path in tracer
1 parent 7071fbc commit 7dde1e5

File tree

3 files changed

+72
-29
lines changed

3 files changed

+72
-29
lines changed

apps/language_server/lib/language_server/build.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ defmodule ElixirLS.LanguageServer.Build do
133133
}
134134

135135
ElixirLS.LanguageServer.MixProjectCache.store(state)
136+
Tracer.notify_deps_path(Mix.Project.deps_path(state.config))
136137

137138
:ok
138139
catch

apps/language_server/lib/language_server/tracer.ex

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ defmodule ElixirLS.LanguageServer.Tracer do
2121
GenServer.cast(__MODULE__, {:notify_settings_stored, project_dir})
2222
end
2323

24+
def notify_deps_path(deps_path) do
25+
GenServer.cast(__MODULE__, {:notify_deps_path, deps_path})
26+
end
27+
2428
defp get_project_dir() do
2529
case Process.get(:elixir_ls_project_dir) do
2630
nil ->
@@ -33,6 +37,18 @@ defmodule ElixirLS.LanguageServer.Tracer do
3337
end
3438
end
3539

40+
defp get_deps_path() do
41+
case Process.get(:elixir_ls_deps_path) do
42+
nil ->
43+
deps_path = GenServer.call(__MODULE__, :get_deps_path)
44+
Process.put(:elixir_ls_deps_path, deps_path)
45+
deps_path
46+
47+
deps_path ->
48+
deps_path
49+
end
50+
end
51+
3652
def notify_file_deleted(file) do
3753
GenServer.cast(__MODULE__, {:notify_file_deleted, file})
3854
end
@@ -50,7 +66,7 @@ defmodule ElixirLS.LanguageServer.Tracer do
5066
])
5167
end
5268

53-
state = %{project_dir: nil}
69+
state = %{project_dir: nil, deps_path: nil}
5470

5571
{:ok, state}
5672
end
@@ -60,6 +76,10 @@ defmodule ElixirLS.LanguageServer.Tracer do
6076
{:reply, project_dir, state}
6177
end
6278

79+
def handle_call(:get_deps_path, _from, %{deps_path: deps_path} = state) do
80+
{:reply, deps_path, state}
81+
end
82+
6383
@impl true
6484
def handle_cast({:notify_settings_stored, project_dir}, state) do
6585
for table <- @tables do
@@ -70,6 +90,10 @@ defmodule ElixirLS.LanguageServer.Tracer do
7090
{:noreply, %{state | project_dir: project_dir}}
7191
end
7292

93+
def handle_cast({:notify_deps_path, deps_path}, state) do
94+
{:noreply, %{state | deps_path: deps_path}}
95+
end
96+
7397
def handle_cast({:notify_file_deleted, file}, state) do
7498
delete_modules_by_file(file)
7599
delete_calls_by_file(file)
@@ -283,15 +307,21 @@ defmodule ElixirLS.LanguageServer.Tracer do
283307

284308
defp in_project_sources?(path) do
285309
project_dir = get_project_dir()
310+
deps_path = get_deps_path()
286311

287312
if project_dir != nil do
288-
topmost_path_segment =
289-
path
290-
|> Path.relative_to(project_dir)
291-
|> Path.split()
292-
|> hd
313+
cond do
314+
deps_path && Path.relative_to(path, deps_path) != path ->
315+
# path is in deps_path
316+
false
317+
318+
Path.relative_to(path, project_dir) == path ->
319+
# path not in project_dir, probably a path dep
320+
false
293321

294-
topmost_path_segment != "deps"
322+
true ->
323+
true
324+
end
295325
else
296326
false
297327
end

apps/language_server/test/tracer_test.exs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ defmodule ElixirLS.LanguageServer.TracerTest do
1717
assert GenServer.call(Tracer, :get_project_dir) == project_path
1818
end
1919

20+
test "set deps path" do
21+
project_path = FixtureHelpers.get_path("")
22+
deps_path = Path.join(project_path, "deps")
23+
24+
Tracer.notify_deps_path(deps_path)
25+
26+
assert GenServer.call(Tracer, :get_deps_path) == deps_path
27+
end
28+
2029
describe "call trace" do
2130
setup context do
2231
project_path = FixtureHelpers.get_path("")
2332
Tracer.notify_settings_stored(project_path)
33+
Tracer.notify_deps_path(Path.join(project_path, "deps"))
2434
GenServer.call(Tracer, :get_project_dir)
2535

26-
{:ok, context}
36+
{:ok, context |> Map.put(:project_path, project_path)}
2737
end
2838

2939
defp sorted_calls() do
@@ -34,99 +44,101 @@ defmodule ElixirLS.LanguageServer.TracerTest do
3444
assert sorted_calls() == []
3545
end
3646

37-
test "registers calls same function different files" do
47+
test "registers calls same function different files", %{project_path: project_path} do
3848
Tracer.trace(
3949
{:remote_function, [line: 12, column: 2], CalledModule, :called, 1},
4050
%Macro.Env{
4151
module: CallingModule,
42-
file: "calling_module.ex"
52+
file: Path.join(project_path, "calling_module.ex")
4353
}
4454
)
4555

4656
Tracer.trace(
4757
{:remote_function, [line: 13, column: 3], CalledModule, :called, 1},
4858
%Macro.Env{
4959
module: OtherCallingModule,
50-
file: "other_calling_module.ex"
60+
file: Path.join(project_path, "other_calling_module.ex")
5161
}
5262
)
5363

5464
assert [
55-
{{CalledModule, :called, 1}, "calling_module.ex", 12, 2},
56-
{{CalledModule, :called, 1}, "other_calling_module.ex", 13, 3}
65+
{{CalledModule, :called, 1}, Path.join(project_path, "calling_module.ex"), 12, 2},
66+
{{CalledModule, :called, 1}, Path.join(project_path, "other_calling_module.ex"),
67+
13, 3}
5768
] == sorted_calls()
5869
end
5970

60-
test "registers calls same function in one file" do
71+
test "registers calls same function in one file", %{project_path: project_path} do
6172
Tracer.trace(
6273
{:remote_function, [line: 12, column: 2], CalledModule, :called, 1},
6374
%Macro.Env{
6475
module: CallingModule,
65-
file: "calling_module.ex"
76+
file: Path.join(project_path, "calling_module.ex")
6677
}
6778
)
6879

6980
Tracer.trace(
7081
{:remote_function, [line: 13, column: 3], CalledModule, :called, 1},
7182
%Macro.Env{
7283
module: CallingModule,
73-
file: "calling_module.ex"
84+
file: Path.join(project_path, "calling_module.ex")
7485
}
7586
)
7687

7788
assert [
78-
{{CalledModule, :called, 1}, "calling_module.ex", 12, 2},
79-
{{CalledModule, :called, 1}, "calling_module.ex", 13, 3}
89+
{{CalledModule, :called, 1}, Path.join(project_path, "calling_module.ex"), 12, 2},
90+
{{CalledModule, :called, 1}, Path.join(project_path, "calling_module.ex"), 13, 3}
8091
] == sorted_calls()
8192
end
8293

83-
test "registers calls different functions" do
94+
test "registers calls different functions", %{project_path: project_path} do
8495
Tracer.trace(
8596
{:remote_function, [line: 12, column: 2], CalledModule, :called, 1},
8697
%Macro.Env{
8798
module: CallingModule,
88-
file: "calling_module.ex"
99+
file: Path.join(project_path, "calling_module.ex")
89100
}
90101
)
91102

92103
Tracer.trace(
93104
{:remote_function, [line: 13, column: 3], CalledModule, :other_called, 1},
94105
%Macro.Env{
95106
module: OtherCallingModule,
96-
file: "other_calling_module.ex"
107+
file: Path.join(project_path, "other_calling_module.ex")
97108
}
98109
)
99110

100111
assert [
101-
{{CalledModule, :called, 1}, "calling_module.ex", 12, 2},
102-
{{CalledModule, :other_called, 1}, "other_calling_module.ex", 13, 3}
112+
{{CalledModule, :called, 1}, Path.join(project_path, "calling_module.ex"), 12, 2},
113+
{{CalledModule, :other_called, 1},
114+
Path.join(project_path, "other_calling_module.ex"), 13, 3}
103115
] == sorted_calls()
104116
end
105117

106-
test "deletes calls by file" do
118+
test "deletes calls by file", %{project_path: project_path} do
107119
Tracer.trace(
108120
{:remote_function, [line: 12, column: 2], CalledModule, :called, 1},
109121
%Macro.Env{
110122
module: CallingModule,
111-
file: "calling_module.ex"
123+
file: Path.join(project_path, "calling_module.ex")
112124
}
113125
)
114126

115127
Tracer.trace(
116128
{:remote_function, [line: 13, column: 3], CalledModule, :called, 1},
117129
%Macro.Env{
118130
module: OtherCallingModule,
119-
file: "other_calling_module.ex"
131+
file: Path.join(project_path, "other_calling_module.ex")
120132
}
121133
)
122134

123-
Tracer.delete_calls_by_file("other_calling_module.ex")
135+
Tracer.delete_calls_by_file(Path.join(project_path, "other_calling_module.ex"))
124136

125137
assert [
126-
{{CalledModule, :called, 1}, "calling_module.ex", 12, 2}
138+
{{CalledModule, :called, 1}, Path.join(project_path, "calling_module.ex"), 12, 2}
127139
] == sorted_calls()
128140

129-
Tracer.delete_calls_by_file("calling_module.ex")
141+
Tracer.delete_calls_by_file(Path.join(project_path, "calling_module.ex"))
130142

131143
assert [] == sorted_calls()
132144
end

0 commit comments

Comments
 (0)