Skip to content

Commit f182546

Browse files
authored
Merge pull request #262 from BetterThanTomorrow:218-evaluate-selection-stack-overflow
218-evaluate-selection-stack-overflow * Fixes #218
2 parents 78723d2 + 8ecd6b1 commit f182546

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes to Joyride
44

55
## [Unreleased]
66

7+
- Fix: [Hitting maximum stack size error when Evaluating Selection](https://github.com/BetterThanTomorrow/joyride/pull/218) (Works around a yet unfigured-out Promesa issue.)
8+
79
## [0.0.70] - 2025-11-02
810

911
- **BREAKING CHANGE** - Fix: [Namespaces of namespaced keys don't survive flare/post-message!+](https://github.com/BetterThanTomorrow/joyride/pull/260)

src/joyride/extension.cljs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,19 @@
5151
(defn evaluate-selection+
5252
"Evaluates the selection by first copying it to the clipboard and reading it from there.
5353
Restores the original clipboard content after reading it from the clipboard.
54-
The reason to do it like this is that it will work regardless of where text i selected.
54+
The reason to do it like this is that it will work regardless of where text is selected.
5555
Also in Markdown previews or terminal, or QuickPick prompts, or anywhere."
5656
[]
57-
; Delay needed when run from the command palette
58-
; lest the command palette is active when the copy is performed
5957
(p/do
60-
(p/create
61-
(fn [resolve _reject]
62-
(js/setTimeout resolve 200)))
63-
(p/let [original-clipboard-text (vscode/env.clipboard.readText)
58+
(p/delay 200)
59+
; We use native JS promises for clipboard reading to avoid stack overflow issues
60+
; https://github.com/BetterThanTomorrow/joyride/issues/218
61+
(p/let [before-clipboard (.then (vscode/env.clipboard.readText) identity)
6462
_ (vscode/commands.executeCommand "editor.action.clipboardCopyAction")
65-
selected-text (vscode/env.clipboard.readText)
66-
_ (vscode/env.clipboard.writeText original-clipboard-text)]
67-
(when (not-empty selected-text)
68-
(run-code+ selected-text)))))
63+
selection (.then (vscode/env.clipboard.readText) identity)
64+
_ (vscode/env.clipboard.writeText before-clipboard)]
65+
(when (not= selection before-clipboard)
66+
(run-code+ selection)))))
6967

7068
(defn reveal-output-terminal
7169
"Reveal the Joyride output terminal without taking focus."
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(ns integration-test.commands-test
2+
(:require
3+
[cljs.test :refer [is testing]]
4+
[integration-test.macros :refer [deftest-async]]
5+
[promesa.core :as p]
6+
["vscode" :as vscode]))
7+
8+
(deftest-async evaluate-selection-without-crash
9+
(testing "Evaluate selection command completes without stack overflow"
10+
(p/let [doc (vscode/workspace.openTextDocument #js {:content "(+ 1 2)"
11+
:language "clojure"})
12+
editor (vscode/window.showTextDocument doc)
13+
_ (set! (.-selection editor)
14+
(vscode/Selection. 0 0 0 7))
15+
_ (vscode/env.clipboard.writeText "original-clipboard-content")
16+
_ (vscode/commands.executeCommand "joyride.evaluateSelection")
17+
_ (p/delay 500)
18+
clipboard-after (.then (vscode/env.clipboard.readText) identity)]
19+
(is (= "original-clipboard-content" clipboard-after)
20+
"Clipboard content is restored after evaluation"))))
21+
22+
(deftest-async evaluate-selection-with-empty-selection
23+
(testing "Evaluate selection handles empty selection gracefully"
24+
(p/let [doc (vscode/workspace.openTextDocument #js {:content "(+ 1 2)"
25+
:language "clojure"})
26+
editor (vscode/window.showTextDocument doc)
27+
_ (set! (.-selection editor)
28+
(vscode/Selection. 0 0 0 0))
29+
_ (vscode/commands.executeCommand "joyride.evaluateSelection")
30+
_ (p/delay 300)]
31+
(is true "Command handles empty selection without error"))))
32+
33+
(deftest-async evaluate-selection-preserves-different-clipboard
34+
(testing "Evaluate selection preserves clipboard when selection differs from clipboard"
35+
(p/let [doc (vscode/workspace.openTextDocument #js {:content "(println \"test\")"
36+
:language "clojure"})
37+
editor (vscode/window.showTextDocument doc)
38+
_ (set! (.-selection editor)
39+
(vscode/Selection. 0 0 0 17))
40+
_ (vscode/env.clipboard.writeText "different-content")
41+
_ (vscode/commands.executeCommand "joyride.evaluateSelection")
42+
_ (p/delay 500)
43+
clipboard-after (.then (vscode/env.clipboard.readText) identity)]
44+
(is (= "different-content" clipboard-after)
45+
"Clipboard is restored even when different from selection"))))

vscode-test-runner/workspace-1/.joyride/src/integration_test/flare_test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
:message-handler message-handler})
3232
_ ready?
3333
;; We need to wait a tiny bit to be be ready for realz
34-
_ (p/delay 32)
34+
_ (p/delay 200)
3535
_ (flare/post-message!+ :test/namespaced-keywords message)
3636
;; We need to wait a tick before closing the flare
3737
_ (p/delay 0)

vscode-test-runner/workspace-1/.joyride/src/integration_test/runner.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
'integration-test.joyride-core-test
6464
'integration-test.rewrite-clj-test
6565
'integration-test.reader-conditionals
66-
'integration-test.flare-test]]
66+
'integration-test.flare-test
67+
'integration-test.commands-test]]
6768
(println "Runner: Workspace activated, running tests...")
6869
(try
6970
(doseq [test-ns test-nss]

0 commit comments

Comments
 (0)