@@ -12,46 +12,65 @@ defmodule ElixirLS.LanguageServer.Build do
12
12
13
13
# read cache before cleaning up mix state in reload_project
14
14
cached_deps = read_cached_deps ( )
15
+ mixfile = Path . absname ( MixfileHelpers . mix_exs ( ) )
15
16
16
- case reload_project ( ) do
17
+ case reload_project ( mixfile ) do
17
18
{ :ok , mixfile_diagnostics } ->
18
- ElixirLS.LanguageServer.MixProject . store ( )
19
- # FIXME: Private API
20
-
21
- try do
22
- # this call can raise
23
- current_deps = Mix.Dep . load_on_environment ( [ ] )
24
-
25
- purge_changed_deps ( current_deps , cached_deps )
26
-
27
- if Keyword . get ( opts , :fetch_deps? ) and current_deps != cached_deps do
28
- fetch_deps ( current_deps )
19
+ { deps_result , deps_raw_diagnostics } = with_diagnostics ( [ log: true ] , fn ->
20
+ try do
21
+ # this call can raise
22
+ current_deps = Mix.Dep . load_on_environment ( [ ] )
23
+
24
+ purge_changed_deps ( current_deps , cached_deps )
25
+
26
+ if Keyword . get ( opts , :fetch_deps? ) and current_deps != cached_deps do
27
+ fetch_deps ( current_deps )
28
+ end
29
+
30
+ state = % {
31
+ get: Mix.Project . get ( ) ,
32
+ # project_file: Mix.Project.project_file(),
33
+ config: Mix.Project . config ( ) ,
34
+ # config_files: Mix.Project.config_files(),
35
+ config_mtime: Mix.Project . config_mtime ( ) ,
36
+ umbrella?: Mix.Project . umbrella? ( ) ,
37
+ apps_paths: Mix.Project . apps_paths ( ) ,
38
+ # deps_path: Mix.Project.deps_path(),
39
+ # deps_apps: Mix.Project.deps_apps(),
40
+ # deps_scms: Mix.Project.deps_scms(),
41
+ deps_paths: Mix.Project . deps_paths ( ) ,
42
+ # build_path: Mix.Project.build_path(),
43
+ manifest_path: Mix.Project . manifest_path ( )
44
+ }
45
+ ElixirLS.LanguageServer.MixProject . store ( state )
46
+
47
+ :ok
48
+ catch
49
+ kind , err ->
50
+ { payload , stacktrace } = Exception . blame ( kind , err , __STACKTRACE__ )
51
+ { :error , kind , payload , stacktrace }
29
52
end
30
-
31
- if Keyword . get ( opts , :compile? ) do
32
- { status , diagnostics } = run_mix_compile ( )
33
-
34
- diagnostics = Diagnostics . normalize ( diagnostics , root_path )
35
- Server . build_finished ( parent , { status , mixfile_diagnostics ++ diagnostics } )
36
- :"mix_compile_#{ status } "
37
- else
38
- Server . build_finished ( parent , { :ok , mixfile_diagnostics } )
39
- :mix_compile_disabled
40
- end
41
- catch
42
- kind , payload ->
43
- { payload , stacktrace } = Exception . blame ( kind , payload , __STACKTRACE__ )
44
- message = Exception . format ( kind , payload , stacktrace )
45
- Logger . warning ( "Mix.Dep.load_on_environment([]) failed: #{ message } " )
46
-
47
- JsonRpc . telemetry (
48
- "build_error" ,
49
- % { "elixir_ls.build_error" => message } ,
50
- % { }
51
- )
52
-
53
- # TODO pass diagnostic
54
- Server . build_finished ( parent , { :error , [ ] } )
53
+ end )
54
+
55
+ deps_diagnostics =
56
+ deps_raw_diagnostics
57
+ |> Enum . map ( & Diagnostics . code_diagnostic / 1 )
58
+
59
+ case deps_result do
60
+ :ok ->
61
+ if Keyword . get ( opts , :compile? ) do
62
+ { status , compile_diagnostics } = run_mix_compile ( )
63
+
64
+ compile_diagnostics = Diagnostics . normalize ( compile_diagnostics , root_path )
65
+ Server . build_finished ( parent , { status , mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics } )
66
+ :"mix_compile_#{ status } "
67
+ else
68
+ Server . build_finished ( parent , { :ok , mixfile_diagnostics ++ deps_diagnostics } )
69
+ :mix_compile_disabled
70
+ end
71
+ { :error , kind , err , stacktrace } ->
72
+ # TODO get path from exception message
73
+ Server . build_finished ( parent , { :error , mixfile_diagnostics ++ deps_diagnostics ++ [ Diagnostics . error_to_diagnostic ( kind , err , stacktrace , mixfile ) ] } )
55
74
:deps_error
56
75
end
57
76
@@ -90,9 +109,7 @@ defmodule ElixirLS.LanguageServer.Build do
90
109
:global . trans ( { __MODULE__ , self ( ) } , func )
91
110
end
92
111
93
- def reload_project do
94
- mixfile = Path . absname ( MixfileHelpers . mix_exs ( ) )
95
-
112
+ def reload_project ( mixfile ) do
96
113
if File . exists? ( mixfile ) do
97
114
if module = Mix.Project . get ( ) do
98
115
build_path = Mix.Project . config ( ) [ :build_path ]
@@ -178,7 +195,7 @@ defmodule ElixirLS.LanguageServer.Build do
178
195
179
196
# We can get diagnostics if Mixfile fails to load
180
197
{ mixfile_status , mixfile_diagnostics } =
181
- case Kernel.ParallelCompiler . compile ( [ mixfile ] ) do
198
+ case Kernel.ParallelCompiler . compile ( [ mixfile ] ) |> dbg do
182
199
{ :ok , _ , warnings } ->
183
200
{ :ok , Enum . map ( warnings , & Diagnostics . mixfile_diagnostic ( & 1 , :warning ) ) }
184
201
0 commit comments