@@ -19,83 +19,14 @@ defmodule ElixirLS.LanguageServer.Build do
19
19
20
20
case reload_project ( mixfile , root_path ) do
21
21
{ :ok , mixfile_diagnostics } ->
22
- { deps_result , deps_raw_diagnostics } =
23
- with_diagnostics ( [ log: true ] , fn ->
24
- try do
25
- # this call can raise
26
- current_deps =
27
- if Version . match? ( System . version ( ) , "< 1.16.0-dev" ) do
28
- Mix.Dep . load_on_environment ( [ ] )
29
- else
30
- Mix.Dep.Converger . converge ( [ ] )
31
- end
32
-
33
- purge_changed_deps ( current_deps , cached_deps )
34
-
35
- if Keyword . get ( opts , :fetch_deps? ) and current_deps != cached_deps do
36
- fetch_deps ( current_deps )
37
- end
38
-
39
- state = % {
40
- get: Mix.Project . get ( ) ,
41
- # project_file: Mix.Project.project_file(),
42
- config: Mix.Project . config ( ) ,
43
- # config_files: Mix.Project.config_files(),
44
- config_mtime: Mix.Project . config_mtime ( ) ,
45
- umbrella?: Mix.Project . umbrella? ( ) ,
46
- apps_paths: Mix.Project . apps_paths ( ) ,
47
- # deps_path: Mix.Project.deps_path(),
48
- # deps_apps: Mix.Project.deps_apps(),
49
- # deps_scms: Mix.Project.deps_scms(),
50
- deps_paths: Mix.Project . deps_paths ( ) ,
51
- # build_path: Mix.Project.build_path(),
52
- manifest_path: Mix.Project . manifest_path ( )
53
- }
54
-
55
- ElixirLS.LanguageServer.MixProjectCache . store ( state )
56
-
57
- :ok
58
- catch
59
- kind , err ->
60
- { payload , stacktrace } = Exception . blame ( kind , err , __STACKTRACE__ )
61
- { :error , kind , payload , stacktrace }
62
- end
63
- end )
64
-
65
- deps_diagnostics =
66
- deps_raw_diagnostics
67
- |> Enum . map ( & Diagnostics . from_code_diagnostic ( & 1 , mixfile , root_path ) )
68
-
69
- case deps_result do
70
- :ok ->
71
- handle_compile_phase (
72
- parent ,
73
- mixfile ,
74
- root_path ,
75
- mixfile_diagnostics ,
76
- deps_diagnostics ,
77
- opts
78
- )
79
-
80
- { :error , kind , err , stacktrace } ->
81
- Server . build_finished (
82
- parent ,
83
- { :error ,
84
- mixfile_diagnostics ++
85
- deps_diagnostics ++
86
- [
87
- Diagnostics . from_error (
88
- kind ,
89
- err ,
90
- stacktrace ,
91
- mixfile ,
92
- root_path
93
- )
94
- ] }
95
- )
96
-
97
- :deps_error
98
- end
22
+ handle_reloaded_project (
23
+ parent ,
24
+ mixfile ,
25
+ root_path ,
26
+ mixfile_diagnostics ,
27
+ opts ,
28
+ cached_deps
29
+ )
99
30
100
31
{ :error , mixfile_diagnostics } ->
101
32
Server . build_finished ( parent , { :error , mixfile_diagnostics } )
@@ -155,6 +86,71 @@ defmodule ElixirLS.LanguageServer.Build do
155
86
:global . trans ( { __MODULE__ , self ( ) } , func )
156
87
end
157
88
89
+ # After reloading the project, update deps and (optionally) compile.
90
+ defp handle_reloaded_project ( parent , mixfile , root_path , mixfile_diagnostics , opts , cached_deps ) do
91
+ { deps_result , deps_raw_diagnostics } =
92
+ with_diagnostics ( [ log: true ] , fn ->
93
+ try do
94
+ current_deps =
95
+ if Version . match? ( System . version ( ) , "< 1.16.0-dev" ) do
96
+ Mix.Dep . load_on_environment ( [ ] )
97
+ else
98
+ Mix.Dep.Converger . converge ( [ ] )
99
+ end
100
+
101
+ purge_changed_deps ( current_deps , cached_deps )
102
+
103
+ if Keyword . get ( opts , :fetch_deps? ) and current_deps != cached_deps do
104
+ fetch_deps ( current_deps )
105
+ end
106
+
107
+ state = % {
108
+ get: Mix.Project . get ( ) ,
109
+ config: Mix.Project . config ( ) ,
110
+ config_mtime: Mix.Project . config_mtime ( ) ,
111
+ umbrella?: Mix.Project . umbrella? ( ) ,
112
+ apps_paths: Mix.Project . apps_paths ( ) ,
113
+ deps_paths: Mix.Project . deps_paths ( ) ,
114
+ manifest_path: Mix.Project . manifest_path ( )
115
+ }
116
+
117
+ ElixirLS.LanguageServer.MixProjectCache . store ( state )
118
+
119
+ :ok
120
+ catch
121
+ kind , err ->
122
+ { payload , stacktrace } = Exception . blame ( kind , err , __STACKTRACE__ )
123
+ { :error , kind , payload , stacktrace }
124
+ end
125
+ end )
126
+
127
+ deps_diagnostics =
128
+ Enum . map ( deps_raw_diagnostics , & Diagnostics . from_code_diagnostic ( & 1 , mixfile , root_path ) )
129
+
130
+ case deps_result do
131
+ :ok ->
132
+ handle_compile_phase (
133
+ parent ,
134
+ mixfile ,
135
+ root_path ,
136
+ mixfile_diagnostics ,
137
+ deps_diagnostics ,
138
+ opts
139
+ )
140
+
141
+ { :error , kind , err , stacktrace } ->
142
+ error_diag =
143
+ Diagnostics . from_error ( kind , err , stacktrace , mixfile , root_path )
144
+
145
+ Server . build_finished (
146
+ parent ,
147
+ { :error , mixfile_diagnostics ++ deps_diagnostics ++ [ error_diag ] }
148
+ )
149
+
150
+ :deps_error
151
+ end
152
+ end
153
+
158
154
# If compilation is enabled, run mix compile and report diagnostics;
159
155
# otherwise, simply report the project load diagnostics.
160
156
defp handle_compile_phase (
0 commit comments