33from . import json_helpers
44from .node_client import CommClient
55from .text_helpers import Location
6+ from .editor_client import cli
67
78
89class ServiceProxy :
@@ -26,6 +27,8 @@ def configure(self, host_info="Sublime Text", file=None, format_options=None):
2627 req_dict = self .create_req_dict ("configure" , args )
2728 json_str = json_helpers .encode (req_dict )
2829 response_dict = self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
30+ if self .__comm .workerStarted ():
31+ self .__comm .sendCmdToWorkerSync (json_str , req_dict ["seq" ])
2932 return response_dict
3033
3134 def change (self , path , begin_location = Location (1 , 1 ), end_location = Location (1 , 1 ), insertString = "" ):
@@ -40,7 +43,8 @@ def change(self, path, begin_location=Location(1, 1), end_location=Location(1, 1
4043 req_dict = self .create_req_dict ("change" , args )
4144 json_str = json_helpers .encode (req_dict )
4245 self .__comm .postCmd (json_str )
43- self .__comm .postCmdToWorker (json_str )
46+ if self .__comm .workerStarted ():
47+ self .__comm .postCmdToWorker (json_str )
4448
4549 def completions (self , path , location = Location (1 , 1 ), prefix = "" , on_completed = None ):
4650 args = {"file" : path , "line" : location .line , "offset" : location .offset , "prefix" : prefix }
@@ -92,28 +96,34 @@ def format(self, path, begin_location=Location(1, 1), end_location=Location(1, 1
9296 req_dict = self .create_req_dict ("format" , args )
9397 json_str = json_helpers .encode (req_dict )
9498 response_dict = self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
99+ if self .__comm .workerStarted ():
100+ self .__comm .sendCmdToWorkerSync (json_str , req_dict ["seq" ])
95101 return response_dict
96102
97103 def format_on_key (self , path , location = Location (1 , 1 ), key = "" ):
98104 args = {"file" : path , "line" : location .line , "offset" : location .offset , "key" : key }
99105 req_dict = self .create_req_dict ("formatonkey" , args )
100106 json_str = json_helpers .encode (req_dict )
101107 response_dict = self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
108+ if self .__comm .workerStarted ():
109+ self .__comm .sendCmdToWorkerSync (json_str , req_dict ["seq" ])
102110 return response_dict
103111
104112 def open (self , path ):
105113 args = {"file" : path }
106114 req_dict = self .create_req_dict ("open" , args )
107115 json_str = json_helpers .encode (req_dict )
108116 self .__comm .postCmd (json_str )
109- self .__comm .postCmdToWorker (json_str )
117+ if self .__comm .workerStarted ():
118+ self .__comm .postCmdToWorker (json_str )
110119
111120 def close (self , path ):
112121 args = {"file" : path }
113122 req_dict = self .create_req_dict ("close" , args )
114123 json_str = json_helpers .encode (req_dict )
115124 self .__comm .postCmd (json_str )
116- self .__comm .postCmdToWorker (json_str )
125+ if self .__comm .workerStarted ():
126+ self .__comm .postCmdToWorker (json_str )
117127
118128 def references (self , path , location = Location (1 , 1 )):
119129 args = {"file" : path , "line" : location .line , "offset" : location .offset }
@@ -126,28 +136,40 @@ def reload(self, path, alternate_path):
126136 args = {"file" : path , "tmpfile" : alternate_path }
127137 req_dict = self .create_req_dict ("reload" , args )
128138 json_str = json_helpers .encode (req_dict )
129- self .__comm .postCmd (json_str )
130- self .__comm .postCmdToWorker (json_str )
139+ response_dict = self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
140+ if self .__comm .workerStarted ():
141+ self .__comm .sendCmdToWorkerSync (json_str , req_dict ["seq" ])
142+ return response_dict
131143
132144 def reload_async (self , path , alternate_path , on_completed ):
133145 args = {"file" : path , "tmpfile" : alternate_path }
134146 req_dict = self .create_req_dict ("reload" , args )
135147 json_str = json_helpers .encode (req_dict )
136148 self .__comm .sendCmdAsync (json_str , req_dict ["seq" ], on_completed )
137- self .__comm .postCmdToWorker (json_str )
149+ if self .__comm .workerStarted ():
150+ self .__comm .sendCmdToWorkerAsync (json_str , req_dict ["seq" ], None )
138151
139152 def rename (self , path , location = Location (1 , 1 )):
140153 args = {"file" : path , "line" : location .line , "offset" : location .offset }
141154 req_dict = self .create_req_dict ("rename" , args )
142155 json_str = json_helpers .encode (req_dict )
143156 response_dict = self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
157+ if self .__comm .workerStarted ():
158+ self .__comm .sendCmdSync (json_str , req_dict ["seq" ])
144159 return response_dict
145160
146161 def request_get_err (self , delay = 0 , pathList = []):
147162 args = {"files" : pathList , "delay" : delay }
148163 req_dict = self .create_req_dict ("geterr" , args )
149164 json_str = json_helpers .encode (req_dict )
150- self .__comm .postCmdToWorker (json_str )
165+ self .__comm .postCmd (json_str )
166+
167+ def request_get_err_for_project (self , delay = 0 , path = "" ):
168+ args = {"file" : path , "delay" : delay }
169+ req_dict = self .create_req_dict ("geterrForProject" , args )
170+ json_str = json_helpers .encode (req_dict )
171+ if self .__comm .workerStarted ():
172+ self .__comm .postCmdToWorker (json_str )
151173
152174 def type (self , path , location = Location (1 , 1 )):
153175 args = {"file" : path , "line" : location .line , "offset" : location .offset }
@@ -170,6 +192,10 @@ def get_event(self):
170192 event_json_str = self .__comm .getEvent ()
171193 return json_helpers .decode (event_json_str ) if event_json_str is not None else None
172194
195+ def get_event_from_worker (self ):
196+ event_json_str = self .__comm .getEventFromWorker ()
197+ return json_helpers .decode (event_json_str ) if event_json_str is not None else None
198+
173199 def save_to (self , path , alternatePath ):
174200 args = {"file" : path , "tmpfile" : alternatePath }
175201 req_dict = self .create_req_dict ("saveto" , args )
0 commit comments