@@ -5,7 +5,7 @@ defmodule Mix.Server do
55 defrecord Config , tasks: :ordsets . new , projects: [ ] , mixfile: [ ] ,
66 shell: Mix.Shell.IO , scm: :ordsets . new , env: nil , post_config: [ ]
77
8- defrecord Project , name: nil , config: nil , rec_enabled?: true , io_done: false
8+ defrecord Project , name: nil , config: nil , rec_enabled?: true , io_done: false , file: nil
99
1010 def start_link ( env ) do
1111 :gen_server . start_link ( { :local , __MODULE__ } , __MODULE__ , env , [ ] )
@@ -55,8 +55,8 @@ defmodule Mix.Server do
5555
5656 def handle_call ( :pop_project , _from , config ) do
5757 case config . projects do
58- [ Project [ name : project ] | tail ] ->
59- { :reply , project , config . projects ( tail ) }
58+ [ Project [ name : name , file: file ] | tail ] ->
59+ { :reply , { name , file } , config . projects ( tail ) }
6060 _ ->
6161 { :reply , nil , config }
6262 end
@@ -87,10 +87,29 @@ defmodule Mix.Server do
8787 end
8888 end
8989
90+ def handle_call ( { :push_project , name , config , file } , _from , state ) do
91+ config = Keyword . merge ( config , state . post_config )
92+ project = Project [ name : name , config: config , file: file ]
93+
94+ cond do
95+ file = has_project_named ( name , state ) ->
96+ { :reply , { :error , file } , state }
97+ true ->
98+ { :reply , :ok , state . post_config ( [ ] ) . update_projects ( & [ project | & 1 ] ) }
99+ end
100+ end
101+
90102 def handle_call ( request , from , config ) do
91103 super ( request , from , config )
92104 end
93105
106+ defp has_project_named ( name , state ) do
107+ name && Enum . find_value ( state . projects , fn
108+ Project [ name : ^ name , file: file ] -> file
109+ Project [ ] -> nil
110+ end )
111+ end
112+
94113 def handle_cast ( { :shell , name } , config ) do
95114 { :noreply , config . shell ( name ) }
96115 end
@@ -111,14 +130,6 @@ defmodule Mix.Server do
111130 { :noreply , config . update_tasks & :ordsets . filter ( fn { t , _ } -> t != task end , & 1 ) }
112131 end
113132
114- def handle_cast ( { :push_project , name , conf } , config ) do
115- conf = Keyword . merge ( conf , config . post_config )
116- project = Project [ name : name , config: conf ]
117- config = config . post_config ( [ ] )
118- . update_projects ( & [ project | & 1 ] )
119- { :noreply , config }
120- end
121-
122133 def handle_cast ( { :post_config , value } , config ) do
123134 { :noreply , config . update_post_config ( & Keyword . merge ( & 1 , value ) ) }
124135 end
0 commit comments