Skip to content

Commit 28eb847

Browse files
committed
Detect .shadow-cljs/nrepl.port and .shadow-cljs/socket-repl.port
1 parent 78fcf9e commit 28eb847

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Other changes:
1919
- Removed separate EDN syntax, merged with main Clojure (Sublimed)
2020
- Settings can now be specified in main `Preferences.sublime-settings` as well. Just prepend `clojure_sublimed_` to each setting’s name.
2121
- REPL can detect namespaces with meta on ns form
22+
- Detect `.shadow-cljs/nrepl.port` and `.shadow-cljs/socket-repl.port`
2223

2324
### 3.8.0 - Aug 8, 2024
2425

cs_conn.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def set_status(self, phase, message, *args):
147147
cs_common.set_status(self.window, status_key, status)
148148

149149
class AddressInputHandler(sublime_plugin.TextInputHandler):
150-
def __init__(self, port_file = None, next_input = None):
151-
self.port_file = port_file
150+
def __init__(self, port_files = [], next_input = None):
151+
self.port_files = port_files
152152
self.next = next_input
153153

154154
"""
@@ -159,13 +159,14 @@ def placeholder(self):
159159

160160
def initial_text(self):
161161
# .nrepl-port file present
162-
if self.port_file and (window := sublime.active_window()):
162+
if self.port_files and (window := sublime.active_window()):
163163
for folder in window.folders():
164-
if os.path.exists(folder + "/" + self.port_file):
165-
with open(folder + "/" + self.port_file, "rt") as f:
166-
content = f.read(10).strip()
167-
if re.fullmatch(r'[1-9][0-9]*', content):
168-
return f'localhost:{content}'
164+
for port_file in self.port_files:
165+
if os.path.exists(folder + "/" + port_file):
166+
with open(folder + "/" + port_file, "rt") as f:
167+
content = f.read(10).strip()
168+
if re.fullmatch(r'[1-9][0-9]*', content):
169+
return f'localhost:{content}'
169170
state = cs_common.get_state()
170171
return state.last_conn[1]['address'] if state.last_conn else 'localhost:'
171172

cs_conn_nrepl_jvm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ def run(self, address):
140140
state = cs_common.get_state(self.window)
141141
state.last_conn = ('clojure_sublimed_connect_nrepl_jvm', {'address': address})
142142
if address == 'auto':
143-
address = cs_conn.AddressInputHandler(port_file = '.nrepl-port').initial_text()
143+
address = self.input({}).initial_text()
144144
ConnectionNreplJvm(address).connect()
145145

146146
def input(self, args):
147-
return cs_conn.AddressInputHandler(port_file = '.nrepl-port')
147+
if 'address' not in args:
148+
return cs_conn.AddressInputHandler(port_files = ['.nrepl-port', '.shadow-cljs/nrepl.port'])
148149

149150
def is_enabled(self):
150151
state = cs_common.get_state(self.window)

cs_conn_nrepl_raw.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ def run(self, address):
164164
state = cs_common.get_state(self.window)
165165
state.last_conn = ('clojure_sublimed_connect_nrepl_raw', {'address': address})
166166
if address == 'auto':
167-
address = cs_conn.AddressInputHandler(port_file = '.nrepl-port').initial_text()
167+
address = self.input({}).initial_text()
168168
ConnectionNreplRaw(address).connect()
169169

170170
def input(self, args):
171-
return cs_conn.AddressInputHandler(port_file = '.nrepl-port')
171+
if 'address' not in args:
172+
return cs_conn.AddressInputHandler(port_files = ['.nrepl-port', '.shadow-cljs/nrepl.port'])
172173

173174
def is_enabled(self):
174175
state = cs_common.get_state(self.window)

cs_conn_shadow_cljs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ def run(self, address, build):
9191
ConnectionShadowCljs(address, build).connect()
9292

9393
def input(self, args):
94-
if 'build' not in args:
95-
return cs_conn.AddressInputHandler(next_input = BuildInputHandler())
94+
if 'address' in args and 'build' in args:
95+
pass
96+
elif 'address' in args:
97+
return BuildInputHandler()
98+
elif 'build' in args:
99+
return cs_conn.AddressInputHandler(port_files = ['.nrepl-port', '.shadow-cljs/nrepl.port'])
96100
else:
97-
return cs_conn.AddressInputHandler()
101+
return cs_conn.AddressInputHandler(port_files = ['.nrepl-port', '.shadow-cljs/nrepl.port'], next_input = BuildInputHandler())
98102

99103
def is_enabled(self):
100104
state = cs_common.get_state(self.window)

cs_conn_socket_repl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ def run(self, address):
200200
state = cs_common.get_state(self.window)
201201
state.last_conn = ('clojure_sublimed_connect_socket_repl', {'address': address})
202202
if address == 'auto':
203-
address = cs_conn.AddressInputHandler(port_file = '.repl-port').initial_text()
203+
address = self.input({}).initial_text()
204204
ConnectionSocketRepl(address).connect()
205205

206206
def input(self, args):
207-
return cs_conn.AddressInputHandler(port_file = '.repl-port')
207+
if 'address' not in args:
208+
return cs_conn.AddressInputHandler(port_files = ['.repl-port', '.shadow-cljs/socket-repl.port'])
208209

209210
def is_enabled(self):
210211
state = cs_common.get_state(self.window)

0 commit comments

Comments
 (0)