|
189 | 189 |
|
190 | 190 | (defn should-start-nrepl?
|
191 | 191 | "Determine if we should auto-start an nREPL server based on conditions:
|
| 192 | + Providing a :port with :start-nrepl-cmd works |
| 193 | + Providing a :parse-nrepl-port with :start-nrepl-cmd works |
| 194 | + Providing a :port AND :parse-nrepl-port with an :start-nrepl-cmd does not work |
192 | 195 | 1. CLI: Both :start-nrepl-cmd AND :project-dir provided in args
|
193 | 196 | 2. Config: .clojure-mcp/config.edn exists with :start-nrepl-cmd"
|
194 | 197 | [nrepl-args]
|
195 |
| - (let [{:keys [start-nrepl-cmd project-dir port]} nrepl-args] |
| 198 | + (let [{:keys [start-nrepl-cmd project-dir parse-nrepl-port port]} nrepl-args] |
196 | 199 | (cond
|
197 | 200 | ;; Don't start if port provided but no start command (existing behavior)
|
198 | 201 | (and port (not start-nrepl-cmd))
|
199 | 202 | (do
|
200 | 203 | (log/debug "Port already provided without start command, skipping auto-start")
|
201 | 204 | false)
|
202 | 205 |
|
| 206 | + (and port start-nrepl-cmd parse-nrepl-port) ;; makes no sense to provide this on the command line |
| 207 | + (do |
| 208 | + (log/debug ":port and :parse-nrepl-port both provided with nrepl start command, skipping auto-start") |
| 209 | + false) |
| 210 | + |
203 | 211 | ;; CLI condition: start-nrepl-cmd AND project-dir provided (regardless of port)
|
204 | 212 | (and start-nrepl-cmd project-dir)
|
205 | 213 | (do
|
|
209 | 217 | ;; Config file condition
|
210 | 218 | :else
|
211 | 219 | (if-let [config (load-config-if-exists project-dir)]
|
212 |
| - (if (:start-nrepl-cmd config) |
| 220 | + (cond |
| 221 | + ;; To me providing a port along with parse-nrepl-port indicates that command line args are overriding the config.edn |
| 222 | + ;; this way you can have startup commands in config.edn and yet |
| 223 | + ;; still easily override them on the cli... This is overly complex of course. |
| 224 | + (and port (:start-nrepl-cmd config) (:parse-nrepl-port config)) |
| 225 | + (do |
| 226 | + (log/debug ":port and :parse-nrepl-port both provided with nrepl start command, skipping auto-start") |
| 227 | + false) |
| 228 | + |
| 229 | + (:start-nrepl-cmd config) |
213 | 230 | (do
|
214 | 231 | (log/info "Auto-start condition met: config file with :start-nrepl-cmd")
|
215 | 232 | true)
|
216 |
| - false) |
| 233 | + |
| 234 | + :else false) |
217 | 235 | false))))
|
218 | 236 |
|
219 |
| -(defn add-project-dir [nrepl-args] |
220 |
| - (if (and (:start-nrepl-cmd nrepl-args) (not (:project-dir nrepl-args))) |
| 237 | +(defn add-project-dir [{:keys [start-nrepl-cmd project-dir parse-nrepl-port port] :as nrepl-args}] |
| 238 | + (cond |
| 239 | + ;; if a port is provided the intent is not clear here |
| 240 | + (and parse-nrepl-port start-nrepl-cmd port) nrepl-args |
| 241 | + (and start-nrepl-cmd (not project-dir)) |
221 | 242 | (assoc nrepl-args :project-dir (System/getProperty "user.dir"))
|
222 |
| - nrepl-args)) |
| 243 | + :else nrepl-args)) |
223 | 244 |
|
224 | 245 | (defn maybe-start-nrepl-process
|
225 | 246 | "Main wrapper that conditionally starts an nREPL process.
|
|
0 commit comments