Skip to content

Commit 038c7e4

Browse files
author
committed
[skip ci]
1 parent 20c0db4 commit 038c7e4

16 files changed

Lines changed: 351 additions & 137 deletions

File tree

api/index.html

Lines changed: 58 additions & 8 deletions
Large diffs are not rendered by default.

commands/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,12 @@ <h2 id="repl-commands">REPL commands<a class="headerlink" href="#repl-commands"
22752275
<td style="text-align: left;">A JSON object with stuff from <a href="https://github.com/clojure-emacs/cider-nrepl/blob/master/doc/modules/ROOT/pages/nrepl-api/ops.adoc#refresh-all">cider-nrepl ops/refresh-aa</a></td>
22762276
<td style="text-align: left;">Mostly meant for sending <code>:dirs</code>, <code>:after</code>, and <code>:before</code>. The print options may or may not work.</td>
22772277
</tr>
2278+
<tr>
2279+
<td style="text-align: left;"><code>calva.selectReplWindowSession</code></td>
2280+
<td style="text-align: left;">Select REPL Window Session</td>
2281+
<td style="text-align: left;"><code>sessionKey?: string</code></td>
2282+
<td style="text-align: left;">Sets the REPL window to use the specified session. If no argument is provided, shows a picker. Returns <code>void</code>.</td>
2283+
</tr>
22782284
</tbody>
22792285
</table>
22802286
<h2 id="wait-where-are-all-the-commands">Wait, where are all the commands?<a class="headerlink" href="#wait-where-are-all-the-commands" title="Permanent link">#</a></h2>

connect-sequences/index.html

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,12 +2430,13 @@ <h2 id="settings-for-adding-custom-sequences">Settings for adding Custom Sequenc
24302430
<p>A connect sequence configures the following:</p>
24312431
<ul>
24322432
<li><code>name</code>: (required) This will show up in the Jack-in quick-pick menu when you start Jack-in (see above). This will be set the <a href="../when-clauses/">When Clause context</a> <code>calva:connectSequence</code>, so you can e.g. bind keyboard shortcuts depending on which sequence is selected.</li>
2433-
<li><code>projectType</code>: (required) This is either "Leiningen, "deps.edn", "shadow-cljs", "lein-shadow", "Gradle", "babashka", "nbb", "basilisp", "joyride", generic, "custom", or "cljs-only".</li>
2433+
<li><code>projectType</code>: (required) This is either "Leiningen", "deps.edn", "shadow-cljs", "lein-shadow", "Gradle", "babashka", "nbb", "basilisp", "joyride", "scittle", "generic", "clj-projectless", "custom", or "cljs-only".</li>
24342434
<li><code>autoSelectForJackIn</code>: A boolean. If true, this sequence will be automatically selected at <strong>Jack-in</strong>, suppressing the Project Type. Use together with <code>projectRootPath</code> to also suppress the Project Root menu. Add usage of <code>menuSelections</code> to go for a prompt-less REPL Jack-in. If you have more than one sequence with <code>autoSelectForJackIn</code> set to true, Calva will use the sequence with its <code>projectRootPath</code> closest to the currently active editor file. And if there is no such closest file, the first sequence will be used.</li>
24352435
<li><code>autoSelectForConnect</code>: A boolean. If true, this sequence will be automatically selected at <strong>Connect</strong>, suppressing the Project Type menu. Use together with <code>projectRootPath</code> to also suppress the Project Root menu. If you have more than one sequence with <code>autoSelectForConnect</code> set to true, Calva will use the sequence with its <code>projectRootPath</code> closest to the currently active editor file. And if there is no such closest file, the first sequence will be used.</li>
24362436
<li><code>projectRootPath</code>: An array of path segments leading to the root of the project to which this connect sequence corresponds. Use together with <code>autoSelectForJackIn</code>/<code>autoSelectForConnect</code> to suppress the Project Root menu. The path can be absolute or relative to the workspace root. If there are several Workspace Folders, the workspace root is the path of the first folder, so relative paths will only work for this first folder.</li>
24372437
<li><code>nReplPortFile</code>: An array of path segments with the project root-relative path to the nREPL port file for this connect sequence. E.g. For shadow-cljs this would be <code>[".shadow-cljs", "nrepl.port"]</code>.</li>
2438-
<li><code>afterCLJReplJackInCode</code>: Code to evaluate in the CLJ REPL once it has been created. You can use either a string or an array of strings. If you use an array, the strings will be joined with a newline character to form the resulting code.</li>
2438+
<li><code>defaultPort</code>: A fallback port number to use when the <code>nReplPortFile</code> is missing (for example the built-in Babashka sequence uses <code>1667</code>, and the Scittle sequence uses <code>1339</code>). This lets Calva attempt an immediate connection instead of prompting for host/port when the port file is not present.</li>
2439+
<li><code>afterPrimaryReplConnectedCode</code>: Code to evaluate in the primary REPL once it has been created. You can use either a string or an array of strings. If you use an array, the strings will be joined with a newline character to form the resulting code.</li>
24392440
<li><code>customJackInCommandLine</code>: A string with a command line that should be used to launch the REPL. See <a href="#custom-command-line">Custom Command Line</a>, below.</li>
24402441
<li><code>cljsType</code>: This can be either "Figwheel Main", "shadow-cljs", "ClojureScript built-in for browser", "ClojureScript built-in for node", "lein-figwheel", "none", or a dictionary configuring a custom type. If set to "none", Calva will skip connecting a ClojureScript repl. A custom type has the following fields:<ul>
24412442
<li><code>dependsOn</code>: (required) Calva will use this to determine which dependencies it will add when starting the project (Jacking in). This can be either "Figwheel Main", "shadow-cljs", "ClojureScript built-in for browser", "ClojureScript built-in for node", "lein-figwheel", or ”User provided”. If it is "User provided", then you need to provide the dependencies in the project or launch with an alias (deps.edn), profile (Leiningen), or build (shadow-cljs) that provides the dependencies needed.</li>
@@ -2460,7 +2461,36 @@ <h2 id="settings-for-adding-custom-sequences">Settings for adding Custom Sequenc
24602461
</li>
24612462
<li><code>jackInEnv</code>: An object with environment variables that will be merged with the global <code>calva.jackInEnv</code> and then applied to the Jack-in process. The merge is very similar to how Clojure's <code>merge</code> works. So for any common keys between the global setting and this one, the ones from this setting will win.</li>
24622463
<li><code>extraNReplMiddleware</code>: Array of strings of the fully qualified names of extra middleware that should be applied to the nREPL server when started.</li>
2464+
<li><code>replSessionNames</code>: Override the default repl session names that Calva registers for the primary and the secondary (if any) REPL sessions. Use this to enable connecting more than one connect sequence in the same VS Code window.<ul>
2465+
<li><code>primary</code>: the name of the primary repl session. Defaults to <code>clj</code></li>
2466+
<li><code>secondary</code>: the name of the secondary repl session in the sequence. Defaults to <code>cljs</code>.</li>
24632467
</ul>
2468+
</li>
2469+
<li><code>replSessionFilePatterns</code>: Map REPL session roles to the file patterns they should handle. Use <code>primary</code> and <code>secondary</code> as keys. Values can be a single pattern string, an array of patterns, or an object specifying <code>always-claim</code> and/or <code>is-fallback-for</code> patterns. Patterns are automatically scoped to the connect sequence's project root unless they start with <code>**/</code>, which makes them workspace-wide. Multi-root workspaces are supported. Defaults are <code>*.clj</code> for the primary session and <code>*.cljs</code> for the secondary session.</li>
2470+
</ul>
2471+
<details class="note">
2472+
<summary>Session routing pattern competition resolution</summary>
2473+
<p>When there are many repls connected at once, Calva lets you pin a repl to be used for evaluations. We've tried to make the auto-routing flexible so that you shouldn't need to resort to session pinning too often; this is why the <code>replSessionFilePatterns</code> setting is a bit elaborate.</p>
2474+
<p>Your first line of defence is pattern "specificity". The routing will take a simple specificity into account in cases of routing conflict. More specific patterns will take precedence over less specific ones.</p>
2475+
<p>When you want to stay unspecific with the pattern targeting, you can signal that a particular session is fallback using the object form for <code>replSessionFilePatterns</code>. Specifying that some patterns are <code>is-fallback-for</code> gives other repl sessions the chance to handle the evaluation with their <code>always-claim</code> patterns. The built-in <strong>Babashka</strong> project type uses patterns like so:</p>
2476+
<div class="highlight"><pre><span></span><code>{
2477+
...
2478+
&quot;replSessionNames&quot;: { &quot;primary&quot;: &quot;bb&quot; },
2479+
&quot;replSessionFilePatterns&quot;: {
2480+
&quot;primary&quot;: {
2481+
&quot;always-claim&quot;: [&quot;*.bb&quot;, &quot;bb.edn&quot;],
2482+
&quot;is-fallback-for&quot;: [&quot;**/*.clj&quot;, &quot;**/*.bb&quot;, &quot;**/bb.edn&quot;]
2483+
}
2484+
}
2485+
...
2486+
}
2487+
</code></pre></div>
2488+
<p>This will make the Babashka repl (if connected) get all evaluations from <code>.bb</code> files in its project, and if no other repl session is handling <code>.clj</code> files, the Babashka repl will handle those too. But if some other connected repl is specifying <code>*.clj</code> as an <code>always-claim</code> pattern, the Babashka repl will not compete for those files. Additionally, the <code>**/*.clj</code>, <code>**/*.bb</code>. and <code>**/bb.edn</code> patterns in the fallback tier will match <code>.bb</code> files <em>anywhere</em> in the workspace (not just within the project root), making the Babashka repl a workspace-wide fallback for orphan Babashka files (and Clojure files, to make another repl fallback for Clojure files, connect it before connecting the Babashka repl).</p>
2489+
<p>NB: When a sequence is not using the object form of the specification all patterns are considered <code>always-claim</code>.</p>
2490+
<p><strong>Workspace-wide patterns</strong>: By default, patterns are scoped to the connect sequence's project root. To match files anywhere in the workspace, prefix patterns with <code>**/</code>.</p>
2491+
<p>Inside each tier, Calva scores patterns by specificity: literal path segments earn more points than wildcard-heavy ones, and <code>**</code> incurs a penalty. This keeps patterns such as <code>src/app/*.cljs</code> ahead of a broad <code>*.cljs</code> even if both live in the same tier.</p>
2492+
<p>If tiering and specificity still leave more than one repl session competing, Calva falls back to connection order, so the first connected session wins. The same fallback applies when no session matches.</p>
2493+
</details>
24642494
<p>The <a href="https://github.com/BetterThanTomorrow/calva/blob/published/src/nrepl/connectSequence.ts">Calva built-in sequences</a> also use this format, check them out to get a clearer picture of how these settings work.</p>
24652495
<div class="admonition note">
24662496
<p class="admonition-title">How sequence configurations are merged</p>
@@ -2584,7 +2614,7 @@ <h3 id="polylith">Polylith<a class="headerlink" href="#polylith" title="Permanen
25842614
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nt">&quot;calva.replConnectSequences&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span>
25852615
<span class="w"> </span><span class="p">{</span>
25862616
<span class="w"> </span><span class="nt">&quot;projectType&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;deps.edn&quot;</span><span class="p">,</span>
2587-
<span class="w"> </span><span class="nt">&quot;afterCLJReplJackInCode&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(require &#39;[dev.server] :reload) (in-ns &#39;dev.server) (start! 6003)&quot;</span><span class="p">,</span>
2617+
<span class="w"> </span><span class="nt">&quot;afterPrimaryReplConnectedCode&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(require &#39;[dev.server] :reload) (in-ns &#39;dev.server) (start! 6003)&quot;</span><span class="p">,</span>
25882618
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Polylith RealWorld Server REPL (start)&quot;</span><span class="p">,</span>
25892619
<span class="w"> </span><span class="nt">&quot;autoSelectForJackIn&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span>
25902620
<span class="w"> </span><span class="nt">&quot;projectRootPath&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;.&quot;</span><span class="p">],</span>
@@ -2611,7 +2641,7 @@ <h3 id="minimal-menus-with-full-stack-depsedn-and-figwheel-main-repls">Minimal m
26112641
<span class="w"> </span><span class="p">{</span>
26122642
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Example Sequence&quot;</span><span class="p">,</span>
26132643
<span class="w"> </span><span class="nt">&quot;projectType&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Clojure-CLI&quot;</span><span class="p">,</span>
2614-
<span class="w"> </span><span class="nt">&quot;afterCLJReplJackInCode&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(go)&quot;</span><span class="p">,</span>
2644+
<span class="w"> </span><span class="nt">&quot;afterPrimaryReplConnectedCode&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(go)&quot;</span><span class="p">,</span>
26152645
<span class="w"> </span><span class="nt">&quot;cljsType&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">{</span>
26162646
<span class="w"> </span><span class="nt">&quot;startCode&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(do (require &#39;[cljs-test.main :refer :all])(start-nrepl+fig))&quot;</span><span class="p">,</span>
26172647
<span class="w"> </span><span class="nt">&quot;isReadyToStartRegExp&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Prompt will show&quot;</span><span class="p">,</span>

connect/index.html

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,39 @@
461461
</span>
462462
</a>
463463

464+
</li>
465+
466+
<li class="md-nav__item">
467+
<a href="#multiple-repl-connections" class="md-nav__link">
468+
<span class="md-ellipsis">
469+
Multiple REPL Connections
470+
</span>
471+
</a>
472+
473+
<nav class="md-nav" aria-label="Multiple REPL Connections">
474+
<ul class="md-nav__list">
475+
476+
<li class="md-nav__item">
477+
<a href="#how-concurrent-connections-are-organized" class="md-nav__link">
478+
<span class="md-ellipsis">
479+
How concurrent connections are organized
480+
</span>
481+
</a>
482+
483+
</li>
484+
485+
<li class="md-nav__item">
486+
<a href="#picking-which-connection-to-keep" class="md-nav__link">
487+
<span class="md-ellipsis">
488+
Picking which connection to keep
489+
</span>
490+
</a>
491+
492+
</li>
493+
494+
</ul>
495+
</nav>
496+
464497
</li>
465498

466499
<li class="md-nav__item">
@@ -2364,6 +2397,39 @@
23642397
</span>
23652398
</a>
23662399

2400+
</li>
2401+
2402+
<li class="md-nav__item">
2403+
<a href="#multiple-repl-connections" class="md-nav__link">
2404+
<span class="md-ellipsis">
2405+
Multiple REPL Connections
2406+
</span>
2407+
</a>
2408+
2409+
<nav class="md-nav" aria-label="Multiple REPL Connections">
2410+
<ul class="md-nav__list">
2411+
2412+
<li class="md-nav__item">
2413+
<a href="#how-concurrent-connections-are-organized" class="md-nav__link">
2414+
<span class="md-ellipsis">
2415+
How concurrent connections are organized
2416+
</span>
2417+
</a>
2418+
2419+
</li>
2420+
2421+
<li class="md-nav__item">
2422+
<a href="#picking-which-connection-to-keep" class="md-nav__link">
2423+
<span class="md-ellipsis">
2424+
Picking which connection to keep
2425+
</span>
2426+
</a>
2427+
2428+
</li>
2429+
2430+
</ul>
2431+
</nav>
2432+
23672433
</li>
23682434

23692435
<li class="md-nav__item">
@@ -2484,7 +2550,7 @@ <h2 id="connecting-without-jack-in">Connecting Without Jack-in<a class="headerli
24842550
<p>All this said, I still recommend you challenge the conclusion that you can't use Jack-in.</p>
24852551
<div class="admonition note">
24862552
<p class="admonition-title">Copy the Jack-in command line</p>
2487-
<p>There is a Calva command for copying the Jack-in command line to the clipboard. It will copy the command line including commands to change to the current REPL project root, avoiding hard-to-detect errors when starting the REPL in the wrong directory.</p>
2553+
<p>There is a Calva command for copying the Jack-in command line to the clipboard. It will copy the command line including commands to change to the current REPL project root, avoiding hard-to-detect errors when starting the REPL in the wrong directory. The command also accepts an optional connect sequence argument (by name or object) so automations and keybindings can copy the exact command for a particular sequence without prompts.</p>
24882554
</div>
24892555
<div class="admonition note">
24902556
<p class="admonition-title">The Generic Project Type</p>
@@ -2498,6 +2564,12 @@ <h2 id="auto-select-project-type-and-project-root">Auto-select Project Type and
24982564
<h2 id="monorepos-multiple-clojure-projects-in-one-workspace">Monorepos / multiple Clojure projects in one workspace<a class="headerlink" href="#monorepos-multiple-clojure-projects-in-one-workspace" title="Permanent link">#</a></h2>
24992565
<p>If the workspace is a monorepo, Polylith repo or just a repository with more than one Clojure project, Calva will start the connect sequence with prompting for which project to start/connect to.</p>
25002566
<p><img alt="The project roots menu" src="../images/calva-monorepo-project-roots-menu.png" /></p>
2567+
<h2 id="multiple-repl-connections">Multiple REPL Connections<a class="headerlink" href="#multiple-repl-connections" title="Permanent link">#</a></h2>
2568+
<p>Calva can keep several REPL connections alive at the same time. This is useful when you want to run a backend and frontend REPL concurrently, keep an nREPL connected to a remote server while also working locally, or maintain a scratch REPL that should not be restarted when another project reconnects.</p>
2569+
<h3 id="how-concurrent-connections-are-organized">How concurrent connections are organized<a class="headerlink" href="#how-concurrent-connections-are-organized" title="Permanent link">#</a></h3>
2570+
<p>Every connection registers one or two session names (for example the default <code>clj</code>/<code>cljs</code> pair or the custom names you define in a <a href="../connect-sequences/#settings-for-adding-custom-sequences">connect sequence</a>). Calva routes evaluations to the session whose glob matches the active file so you can keep coding without rewiring buffers manually. Run jack-in or connect again at any point to add another repl session.</p>
2571+
<h3 id="picking-which-connection-to-keep">Picking which connection to keep<a class="headerlink" href="#picking-which-connection-to-keep" title="Permanent link">#</a></h3>
2572+
<p>Use <strong>Calva: Disconnect from the REPL</strong> whenever you need to tear down one connection without touching the others. The command opens a quick pick that lists every connection along with its session names, host/port, and project root. When more than one connection is active the picker also offers <strong>Close all REPL connections</strong> as a fast way to clean the slate.</p>
25012573
<h2 id="shadow-cljs">shadow-cljs<a class="headerlink" href="#shadow-cljs" title="Permanent link">#</a></h2>
25022574
<p>Please see the <a href="../shadow-cljs/">shadow-cljs</a> page.</p>
25032575
<h2 id="troubleshooting">Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permanent link">#</a></h2>

0 commit comments

Comments
 (0)