@@ -7,6 +7,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
7
7
8
8
defstruct [
9
9
:project_dir ,
10
+ :deps_path ,
10
11
:parent ,
11
12
:timestamp ,
12
13
:plt ,
@@ -112,7 +113,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
112
113
_from ,
113
114
state
114
115
) do
115
- diagnostics = to_diagnostics ( warnings , state . warn_opts , state . warning_format , state . project_dir )
116
+ diagnostics = to_diagnostics ( warnings , state . warn_opts , state . warning_format , state . project_dir , state . deps_path )
116
117
117
118
Server . dialyzer_finished ( state . parent , diagnostics , build_ref )
118
119
@@ -150,12 +151,16 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
150
151
def handle_cast ( { :analyze , build_ref , warn_opts , warning_format , project_dir } , state ) do
151
152
state =
152
153
ElixirLS.LanguageServer.Build . with_build_lock ( fn ->
154
+ # we can safely access Mix.Project under build lock
153
155
if Mix.Project . get ( ) do
154
156
Logger . info ( "[ElixirLS Dialyzer] Checking for stale beam files" )
157
+ deps_path = Mix.Project . deps_path ( )
158
+ build_path = Mix.Project . build_path ( )
159
+
155
160
new_timestamp = adjusted_timestamp ( )
156
161
157
162
{ removed_files , file_changes } =
158
- update_stale ( state . md5 , state . removed_files , state . file_changes , state . timestamp , project_dir )
163
+ update_stale ( state . md5 , state . removed_files , state . file_changes , state . timestamp , project_dir , build_path )
159
164
160
165
state = % {
161
166
state
@@ -165,7 +170,8 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
165
170
file_changes: file_changes ,
166
171
build_ref: build_ref ,
167
172
warning_format: warning_format ,
168
- project_dir: project_dir
173
+ project_dir: project_dir ,
174
+ deps_path: deps_path
169
175
}
170
176
171
177
trigger_analyze ( state )
@@ -215,12 +221,12 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
215
221
defp trigger_analyze ( % { analysis_pid: nil } = state ) , do: do_analyze ( state )
216
222
defp trigger_analyze ( state ) , do: state
217
223
218
- defp update_stale ( md5 , removed_files , file_changes , timestamp , project_dir ) do
224
+ defp update_stale ( md5 , removed_files , file_changes , timestamp , project_dir , build_path ) do
219
225
prev_paths = Map . keys ( md5 ) |> MapSet . new ( )
220
226
221
227
# FIXME: Private API
222
228
all_paths =
223
- for path <- Mix.Utils . extract_files ( [ Mix.Project . build_path ( ) ] , [ :beam ] ) ,
229
+ for path <- Mix.Utils . extract_files ( [ build_path ] , [ :beam ] ) ,
224
230
into: MapSet . new ( ) ,
225
231
do: Path . relative_to ( path , project_dir )
226
232
@@ -446,7 +452,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
446
452
# in, which breaks umbrella apps. We have to manually resolve the file
447
453
# from the module instead.
448
454
file = resolve_module_file ( module , file , project_dir ) ,
449
- in_project? ( file , project_dir ) do
455
+ in_project? ( Path . absname ( file ) , project_dir ) do
450
456
{ module , { file , line , warning } }
451
457
end
452
458
@@ -490,10 +496,8 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
490
496
end
491
497
492
498
defp in_project? ( path , project_dir ) do
493
- # TODO return false for deps Mix.Project.config()[:deps_path]
494
- # project_dir is absolute path with universal separators
495
- # Path.absname result likewise
496
- File . exists? ( path ) and SourceFile.Path . path_in_dir? ( Path . absname ( path ) , project_dir )
499
+ # path and project_dir is absolute path with universal separators
500
+ File . exists? ( path ) and SourceFile.Path . path_in_dir? ( path , project_dir )
497
501
end
498
502
499
503
defp module_md5 ( file ) do
@@ -511,17 +515,18 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
511
515
end
512
516
end
513
517
514
- defp to_diagnostics ( warnings_map , warn_opts , warning_format , project_dir ) do
518
+ defp to_diagnostics ( warnings_map , warn_opts , warning_format , project_dir , deps_path ) do
519
+ dbg ( deps_path )
520
+ dbg ( project_dir )
515
521
tags_enabled = Analyzer . matching_tags ( warn_opts )
516
- deps_path = Mix.Project . deps_path ( )
517
522
518
523
for { _beam_file , warnings } <- warnings_map ,
519
524
{ source_file , position , data } <- warnings ,
520
525
{ tag , _ , _ } = data ,
521
526
tag in tags_enabled ,
522
527
source_file = Path . absname ( to_string ( source_file ) ) ,
523
528
in_project? ( source_file , project_dir ) ,
524
- not String . starts_with ?( source_file , deps_path ) do
529
+ not SourceFile.Path . path_in_dir ?( source_file , deps_path ) do
525
530
% Mix.Task.Compiler.Diagnostic {
526
531
compiler_name: "ElixirLS Dialyzer" ,
527
532
file: source_file ,
0 commit comments