@@ -52,7 +52,7 @@ defmodule Expert.EngineNode do
5252 IO.puts(\" ok\" )
5353 """
5454 | path_append_arguments ( paths )
55- ]
55+ ] |> dbg ( )
5656
5757 env =
5858 [
@@ -166,7 +166,7 @@ defmodule Expert.EngineNode do
166166 @ allowed_apps [ :engine | Mix.Project . deps_apps ( ) ] -- @ excluded_apps
167167
168168 defp app_globs do
169- app_globs = Enum . map ( @ allowed_apps , fn app_name -> "/ **/#{ app_name } */ebin" end )
169+ app_globs = Enum . map ( @ allowed_apps , fn app_name -> "**/#{ app_name } */ebin" end )
170170 [ "/**/priv" | app_globs ]
171171 end
172172
@@ -186,66 +186,86 @@ defmodule Expert.EngineNode do
186186 # Expert release, and we build it on the fly for the project elixir+opt
187187 # versions if it was not built yet.
188188 defp glob_paths ( % Project { } = project ) do
189- lsp = Expert . get_lsp ( )
190- project_name = Project . name ( project )
191-
192189 case Expert.Port . elixir_executable ( project ) do
193190 { :ok , elixir , env } ->
194- GenLSP . info ( lsp , "Found elixir for #{ project_name } at #{ elixir } " )
195-
196- expert_priv = :code . priv_dir ( :expert )
197- packaged_engine_source = Path . join ( [ expert_priv , "engine_source" , "apps" , "engine" ] )
198-
199- engine_source =
200- "EXPERT_ENGINE_PATH"
201- |> System . get_env ( packaged_engine_source )
202- |> Path . expand ( )
203-
204- build_engine_script = Path . join ( expert_priv , "build_engine.exs" )
205-
206- opts =
207- [
208- :stderr_to_stdout ,
209- args: [
210- elixir ,
211- build_engine_script ,
212- "--source-path" ,
213- engine_source ,
214- "--vsn" ,
215- Expert . vsn ( )
216- ] ,
217- env: Expert.Port . ensure_charlists ( env ) ,
218- cd: Project . root_path ( project )
219- ]
220-
221- launcher = Expert.Port . path ( )
222-
223- GenLSP . info ( lsp , "Finding or building engine for project #{ project_name } " )
224-
225- with_progress ( project , "Building engine for #{ project_name } " , fn ->
226- fn ->
227- Process . flag ( :trap_exit , true )
228-
229- { :spawn_executable , launcher }
230- |> Port . open ( opts )
231- |> wait_for_engine ( )
232- end
233- |> Task . async ( )
234- |> Task . await ( :infinity )
235- end )
191+ launch_engine_builder ( project , elixir , env )
236192
237193 { :error , :no_elixir , message } ->
238194 GenLSP . error ( Expert . get_lsp ( ) , message )
239195 Expert . terminate ( "Failed to find an elixir executable, shutting down" , 1 )
240196 end
241197 end
242198
199+ defp launch_engine_builder ( project , elixir , env ) do
200+ lsp = Expert . get_lsp ( )
201+
202+ project_name = Project . name ( project )
203+ Logger . info ( "Found elixir for #{ project_name } at #{ elixir } " )
204+ GenLSP . info ( lsp , "Found elixir for #{ project_name } at #{ elixir } " )
205+
206+ expert_priv = :code . priv_dir ( :expert )
207+ packaged_engine_source = Path . join ( [ expert_priv , "engine_source" , "apps" , "engine" ] )
208+
209+ engine_source =
210+ "EXPERT_ENGINE_PATH"
211+ |> System . get_env ( packaged_engine_source )
212+ |> Path . expand ( )
213+
214+ build_engine_script = Path . join ( expert_priv , "build_engine.exs" )
215+
216+ opts =
217+ [
218+ :stderr_to_stdout ,
219+ args: [
220+ build_engine_script ,
221+ "--source-path" ,
222+ engine_source ,
223+ "--vsn" ,
224+ Expert . vsn ( )
225+ ] ,
226+ env: Expert.Port . ensure_charlists ( env ) ,
227+ cd: Project . root_path ( project )
228+ ]
229+
230+ { launcher , opts } =
231+ case :os . type ( ) do
232+ { :win32 , _ } ->
233+ { elixir , opts }
234+
235+ { :unix , _ } ->
236+ launcher = Expert.Port . path ( )
237+
238+ opts =
239+ Keyword . update ( opts , :args , [ elixir ] , fn old_args ->
240+ [ elixir | Enum . map ( old_args , & to_string / 1 ) ]
241+ end )
242+
243+ { launcher , opts }
244+ end
245+
246+ GenLSP . info ( lsp , "Finding or building engine for project #{ project_name } " )
247+
248+ with_progress ( project , "Building engine for #{ project_name } " , fn ->
249+ fn ->
250+ Process . flag ( :trap_exit , true )
251+
252+ { :spawn_executable , launcher }
253+ |> Port . open ( opts )
254+ |> wait_for_engine ( )
255+ end
256+ |> Task . async ( )
257+ |> Task . await ( :infinity )
258+ end )
259+ end
260+
243261 defp wait_for_engine ( port , last_line \\ "" ) do
244262 receive do
245263 { ^ port , { :data , ~c" engine_path:" ++ engine_path } } ->
246264 engine_path = engine_path |> to_string ( ) |> String . trim ( )
247265 Logger . info ( "Engine build available at: #{ engine_path } " )
248266
267+ Logger . info ( "ebin paths:\n #{ inspect ( ebin_paths ( engine_path ) , pretty: true ) } " )
268+
249269 { :ok , ebin_paths ( engine_path ) }
250270
251271 { ^ port , { :data , data } } ->
@@ -374,6 +394,7 @@ defmodule Expert.EngineNode do
374394
375395 @ impl true
376396 def handle_info ( { _port , { :data , message } } , % State { } = state ) do
397+ dbg ( message )
377398 Logger . debug ( "Node port message: #{ to_string ( message ) } " )
378399 { :noreply , state }
379400 end
0 commit comments