1- import os , re , sublime , sublime_plugin , threading , time
1+ import os , re , stat , sublime , sublime_plugin , threading , time
22from . import cs_common , cs_eval , cs_eval_status , cs_parser , cs_warn
33
44status_key = 'clojure-sublimed-conn'
@@ -174,6 +174,9 @@ def set_status(self, phase, message, *args):
174174 self .status = status
175175 cs_common .set_status (self .window , status_key , status )
176176
177+ def is_socket (path ):
178+ return stat .S_ISSOCK (os .stat (path ).st_mode )
179+
177180class AddressInputHandler (sublime_plugin .TextInputHandler ):
178181 def __init__ (self , port_files = [], next_input = None ):
179182 self .port_files = port_files
@@ -187,14 +190,15 @@ def placeholder(self):
187190
188191 def initial_text (self ):
189192 # .nrepl-port file present
190- if self .port_files and (window := sublime .active_window ()):
191- for folder in window .folders ():
192- for port_file in self .port_files :
193- if os .path .exists (folder + "/" + port_file ):
194- with open (folder + "/" + port_file , "rt" ) as f :
195- content = f .read (10 ).strip ()
196- if re .fullmatch (r'[1-9][0-9]*' , content ):
197- return f'localhost:{ content } '
193+ if self .port_files :
194+ for port_file in self .port_files :
195+ if path := cs_common .find_in_folders (name = port_file ):
196+ with open (path , "rt" ) as f :
197+ content = f .read (10 ).strip ()
198+ if re .fullmatch (r'[1-9][0-9]*' , content ):
199+ return f'localhost:{ content } '
200+ if path := cs_common .find_in_folders (pred = is_socket ):
201+ return path
198202 state = cs_common .get_state ()
199203 return state .last_conn [1 ]['address' ] if state .last_conn else 'localhost:'
200204
@@ -212,14 +216,17 @@ def preview(self, text):
212216
213217 def validate (self , text ):
214218 text = text .strip ()
215- if 'auto' == text :
219+ if not text :
220+ return False
221+ elif 'auto' == text :
216222 return True
217223 elif match := re .fullmatch (r'([a-zA-Z0-9\.]+):(\d{1,5})' , text ):
218224 _ , port = match .groups ()
219225 return 1 <= int (port ) and int (port ) < 65536
220226 else :
221- return os .path .isfile (text )
222-
227+ path = cs_common .find_in_folders (name = text )
228+ return bool (path and is_socket (path ))
229+
223230 def next_input (self , args ):
224231 return self .next
225232
0 commit comments