Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add webview output experience #2481

Draft
wants to merge 101 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
17ad745
Add repl output ns
bpringe Aug 20, 2023
c9b5334
Merge branch 'dev' into node-library_target_inject_vscode
bpringe Sep 3, 2023
514f9df
Add dev code
bpringe Sep 3, 2023
5871dfa
Add cljs code to get project root uri
bpringe Sep 3, 2023
6ec215d
Add function for creating repl output file (markdown)
bpringe Sep 3, 2023
3af8dfd
Add more markdown experimentation code
bpringe Nov 19, 2023
81303d5
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Nov 19, 2023
84f45e5
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Nov 20, 2023
26c6dad
Create webview-output ns - WIP
bpringe Nov 21, 2023
a193bcc
Use html file for webview html
bpringe Nov 21, 2023
756d366
Add highlight.js
bpringe Nov 21, 2023
56087e9
Begin setup for using reagent in output webview - WIP
bpringe Nov 22, 2023
94d73dc
Add reagent UI for repl output - WIP
bpringe Nov 24, 2023
f97c478
Make reagent UI work
bpringe Nov 25, 2023
0ad4652
Make posting results as messages work
bpringe Nov 25, 2023
06953ce
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Dec 4, 2023
45a629a
Add build to watch-cljs script
bpringe Dec 4, 2023
695afde
Open webview output on activation and print 10 messages
bpringe Dec 4, 2023
65f4229
Fix comment typo
bpringe Feb 26, 2024
2f85dff
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Feb 26, 2024
e005870
Update package-lock.json
bpringe Feb 26, 2024
d50b123
Remove comment form
bpringe Feb 26, 2024
5386de6
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Mar 31, 2024
11dfb42
Remove markdown output file
bpringe Mar 31, 2024
202329f
Fix project-root-uri-key
bpringe Mar 31, 2024
abe1a17
Get rid of react warning about every element needing a key
bpringe Mar 31, 2024
53a3718
Use create-root so that react 18 is used
bpringe Mar 31, 2024
18803b4
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Apr 6, 2024
f71343f
WIP: Update webview CSP
bpringe Apr 6, 2024
3d00c9a
Move hightlightAll call to cljs
bpringe Apr 6, 2024
4eb3975
Add comment
bpringe Apr 6, 2024
23022f6
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Apr 20, 2024
2c60af5
Add replicant
bpringe Apr 20, 2024
5be9a7d
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe May 5, 2024
8f9eca9
Add replicant and set up a simple multimethod command system
bpringe May 5, 2024
77e87f8
Fix typo
bpringe May 5, 2024
af177c1
Update deps-clj-version and deps.clj.jar
bpringe May 19, 2024
45ea2d3
Remove react and reagent deps, move snitch dep to dev alias, refactor…
bpringe May 19, 2024
32c27e7
Add multimethod for getting hiccup for output element
bpringe May 19, 2024
818303d
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Jan 29, 2025
1149007
Update deps.clj and package-lock
bpringe Jan 29, 2025
d517650
Remove empty line
bpringe Jan 29, 2025
6a7e355
Merge pull request #2717 from BetterThanTomorrow/test_branch_ignore
bpringe Jan 29, 2025
a0ca735
Add comment
bpringe Jan 29, 2025
bad6237
Merge pull request #2718 from BetterThanTomorrow/test_branch_2_ignore
bpringe Jan 29, 2025
015d564
Add docstring
bpringe Jan 29, 2025
ae5b6f0
Add docstring
bpringe Jan 29, 2025
450fc7d
Merge pull request #2719 from BetterThanTomorrow/test_branch_3_ignore
bpringe Jan 29, 2025
b9cfea1
Add webview option to outputDestinations in config
bpringe Jan 30, 2025
c161b59
Merge remote-tracking branch 'origin/add_new_output_experience' into …
bpringe Jan 30, 2025
80cc022
WIP: Make show/open output destination command work with webview
bpringe Jan 31, 2025
249b491
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Feb 1, 2025
b5931c9
Fix error caused by accessing `document` on `undefined`
bpringe Feb 1, 2025
73c31c8
Send stdout messages from evaluations to webview
bpringe Feb 2, 2025
62abbca
Show eval results in webview
bpringe Feb 4, 2025
76d6f3c
Show stderr in webview.
bpringe Feb 4, 2025
53f1b6c
Show otherError output in webview
bpringe Feb 4, 2025
5780f1c
Make webview show on repl connect when it's hidden.
bpringe Feb 4, 2025
a1ad0da
Print stacktraces to webview when they occur
bpringe Feb 5, 2025
618a354
Update printLastStacktrace command title
bpringe Feb 5, 2025
5ed14a2
Update printLastStacktrace command title
bpringe Feb 5, 2025
f543523
Refactor
bpringe Feb 6, 2025
6afa6be
Update package.json scripts and .vscodeignore to handle repl-output-u…
bpringe Feb 6, 2025
ecb221d
Print stacktraces to output channel when print last stacktrace comman…
bpringe Feb 6, 2025
80faaf0
Update print last stacktrace command to print to terminal
bpringe Feb 6, 2025
9eb393e
WIP: Add command to clear repl output webview
bpringe Feb 6, 2025
bfbf9f0
Add command to clear webview
bpringe Feb 6, 2025
7a6d830
Refactor for better reloadability
bpringe Feb 8, 2025
bc3c3c4
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Feb 12, 2025
39114b3
Enable find widget in webview panel
bpringe Feb 12, 2025
be47f34
Update deps.clj
bpringe Feb 12, 2025
b988e66
Print output of category 'clojure' to output webview
bpringe Feb 12, 2025
cbaee84
Update test reporting for webview
bpringe Feb 12, 2025
5506ce5
WIP: Add content security policy to webview
bpringe Feb 12, 2025
ff7c0b7
Only add unsafe-eval and connect-src to webview CSP if in debug env
bpringe Feb 12, 2025
1621b54
Finish locking down content security policy of webview
bpringe Feb 13, 2025
b0b1bd3
Update comments in webview html
bpringe Feb 13, 2025
4bcbe93
WIP: Change webview code theme on vs code theme change
bpringe Feb 14, 2025
4befc96
Automatically switch code theme in webview when vs code theme is changed
bpringe Feb 14, 2025
52a74a8
Set code theme when webview is initialized
bpringe Feb 14, 2025
66fc0c3
Add command to show/open repl output webview
bpringe Feb 14, 2025
398c063
Add first webview output test
bpringe Feb 14, 2025
607183a
Make test pass
bpringe Feb 14, 2025
434aaa2
WIP: Refactor and add test for post-message-to-webview
bpringe Feb 17, 2025
e3cb5af
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Feb 20, 2025
eaa6cdf
Finish test for post-message-to-webview
bpringe Feb 26, 2025
399dc76
Add test for get-webview-html
bpringe Feb 26, 2025
be8927e
Refactor get-webview-html to accept context
bpringe Feb 26, 2025
952f5ee
Add test for get-js-source
bpringe Feb 26, 2025
6f72540
Add docstring for wrap-spy
bpringe Feb 26, 2025
4e58d2e
Add test for get-css-path
bpringe Feb 26, 2025
7c65ef2
WIP: Add test for set-webview-html!
bpringe Feb 26, 2025
85551f2
Pushing to test CI
bpringe Feb 27, 2025
148d5d1
Merge remote-tracking branch 'origin/dev' into add_new_output_experience
bpringe Mar 5, 2025
be4d518
Finish test for set-webview-html!
bpringe Mar 5, 2025
e7116b1
WIP: Add test for set-code-theme!
bpringe Mar 5, 2025
5555574
Finish tests for set-code-theme!
bpringe Mar 6, 2025
a5705ae
Update deps.clj
bpringe Mar 7, 2025
d97eb6c
Refactor webview command schema and serialize messages as strings ins…
bpringe Mar 7, 2025
eef05fe
WIP: Add test for create-color-theme-change-listener
bpringe Mar 7, 2025
b4459b4
Fix broken color theme changing
bpringe Mar 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/.clj-kondo
/site
/test-data
/repl-output-ui
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jspm_packages
lib/
cljs-out/
test-out/
repl-output-ui/js

# This and that
.nrepl-port
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
**/.shadow-cljs/
**/out/
clojure.tmLanguage.json
*.md
/repl-output-ui
*.md
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!clojure.tmLanguage.json
!assets/**
!out/**
!repl-output-ui/**
!package.json
!README.md
!CHANGELOG.md
Expand Down
2 changes: 1 addition & 1 deletion deps-clj-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.12.0.1517
v1.12.0.1530
Binary file modified deps.clj.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
org.clojars.liverm0r/dartclojure {:mvn/version "0.2.23-SNAPSHOT"}
vvvvalvalval/supdate {:mvn/version "0.2.3"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
no.cjohansen/replicant {:git/url "https://github.com/cjohansen/replicant.git"
:git/sha "ef2fecbe301cafa8449b74a1e2cbe4fc3ddc18ac"}
org.clojars.abhinav/snitch {:mvn/version "0.1.14"}
tortue/spy {:mvn/version "2.15.0"}
#_#_org.clojars.liverm0r/dartclojure {:local/root "../DartClojure"}}
:aliases {:dev {:extra-deps {org.clojars.abhinav/snitch {:mvn/version "0.1.14"}}}}
:paths ["src/cljs-lib/src"
"src/cljs-lib/test"]}
"src/cljs-lib/test"]}
29 changes: 21 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
"enum": [
"repl-window",
"output-channel",
"terminal"
"terminal",
"webview"
],
"default": "repl-window",
"markdownDescription": "Destination for evaluation results. (Clojure data returned from an evaluation)."
Expand All @@ -188,7 +189,8 @@
"enum": [
"repl-window",
"output-channel",
"terminal"
"terminal",
"webview"
],
"default": "repl-window",
"markdownDescription": "Destination for evaluation output (stdout/stderr from an evaluation)."
Expand All @@ -198,7 +200,8 @@
"enum": [
"repl-window",
"output-channel",
"terminal"
"terminal",
"webview"
],
"default": "repl-window",
"markdownDescription": "Destination for other output (Calva messages, out-of-band stdout/stderr, etcetera)."
Expand Down Expand Up @@ -1356,6 +1359,11 @@
"category": "Calva",
"enablement": "editorLangId == clojure"
},
{
"command": "calva.clearReplOutputWebview",
"title": "Clear REPL Output Webview",
"category": "Calva"
},
{
"command": "calva.interruptAllEvaluations",
"title": "Interrupt Running Evaluations",
Expand Down Expand Up @@ -1428,7 +1436,7 @@
},
{
"command": "calva.printLastStacktrace",
"title": "Print Last Stacktrace to REPL Window",
"title": "Print last stacktrace to result output destination",
"enablement": "calva:connected",
"category": "Calva"
},
Expand Down Expand Up @@ -1955,6 +1963,11 @@
"command": "calva.showResultOutputDestination",
"title": "Show/Open the result output destination"
},
{
"category": "Calva",
"command": "calva.showReplOutputWebview",
"title": "Show/Open the REPL output webview"
},
{
"category": "Calva",
"command": "calva.showReplWindow",
Expand Down Expand Up @@ -3311,16 +3324,16 @@
},
"scripts": {
"watch-docs": "mkdocs serve",
"clean": "rimraf ./out && rimraf ./tsconfig.tsbuildinfo && rimraf ./cljs-out",
"clean": "rimraf ./out ./tsconfig.tsbuildinfo ./cljs-out ./repl-output-ui/js",
"update-grammar": "node ./src/calva-fmt/update-grammar.js ./src/calva-fmt/atom-language-clojure/grammars/clojure.cson clojure.tmLanguage.json",
"precompile": "npm i && npm run clean && npm run update-grammar",
"compile-cljs": "npx shadow-cljs compile :calva-lib :test",
"compile-cljs": "npx shadow-cljs compile :calva-lib :test :repl-output-ui",
"compile-ts": "npx tsc --project ./tsconfig.json",
"compile": "npm run compile-cljs && npm run compile-ts",
"watch-ts": "npx tsc --watch --project ./tsconfig.json",
"watch-cljs": "npx shadow-cljs -d cider/cider-nrepl:0.28.5 watch :calva-lib :test",
"watch-cljs": "npx shadow-cljs -d cider/cider-nrepl:0.28.5 watch :calva-lib :test :repl-output-ui",
"watch-ts-with-strict-nulls": "npx tsc --watch --project ./tsconfig.json --strictNullChecks",
"release-cljs": "npx shadow-cljs release :calva-lib :test",
"release-cljs": "npx shadow-cljs release :calva-lib :test :repl-output-ui",
"release": "webpack --mode production",
"prerelease": "npm run precompile && npm run release-cljs",
"compile-test": "tsc -p ./",
Expand Down
2 changes: 2 additions & 0 deletions repl-output-ui/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* This file is linked in the repl output webview. It's not currently used, but I'm leaving it so if we want
to add styles in the future it's easy to do so. */
17 changes: 15 additions & 2 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@
:js2cljs calva.js2cljs.converter/convert-bridge
:dart2clj calva.dartclojure/convert-bridge
:readConfigEdn calva.read-config/config-edn->js-bridge
:html2hiccup calva.html2hiccup/html->hiccup-convert-bridge}
:html2hiccup calva.html2hiccup/html->hiccup-convert-bridge
:initializeCljs calva.util/initialize-cljs
:showReplOutputWebviewPanel calva.repl.webview.core/show-repl-output-webview-panel
:appendToReplOutputWebview calva.repl.webview.core/append
:appendStackTraceToReplOutputWebview calva.repl.webview.core/append-stacktrace
:clearReplOutputWebview calva.repl.webview.core/clear-webview}
:output-to "out/cljs-lib/cljs-lib.js"}
:test
{:target :node-test
:output-to "out/cljs-lib/test/cljs-lib-tests.js"
:ns-regexp "-test$"
:autorun true}}}
:autorun true}
:repl-output-ui
{:target :browser
;; TODO: Do the asset-path and output-dir values make sense?
:asset-path "js"
:output-dir "repl-output-ui/js"
:modules {:main {:init-fn calva.repl.webview.ui/main}}
:devtools {:loader-mode :eval
:devtools-url "http://localhost:9630"}}}}
226 changes: 226 additions & 0 deletions src/cljs-lib/src/calva/repl/webview/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
(ns calva.repl.webview.core
(:require
[calva.util :as util]
[clojure.string :as str]))

(defonce repl-output-webview-panel (atom nil))

(defn dispose-repl-output-webview-panel
[webview-panel-atom]
(reset! webview-panel-atom nil))

(defn post-message-to-webview [^js webview-panel message]
(when webview-panel
(.. webview-panel
-webview
(postMessage (pr-str (merge
{:id (str (random-uuid))} ;; Provide an id if one wasn't provided by the caller
message))))))

;; The connect-src and unsafe-eval are only needed in development mode for the shadow-cljs
;; dev workflow to function properly
(defn get-webview-html
[{:env/keys [is-debug]} {:keys [js-source css-href csp-source]}]
(str "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\" />

<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />

<meta http-equiv=\"Content-Security-Policy\"
content=\"default-src 'none';
style-src https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github.min.css
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github-dark.min.css
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/base16/windows-high-contrast.min.css
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/base16/windows-high-contrast-light.min.css
" csp-source ";
script-src https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js
https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/languages/clojure.min.js
" (when is-debug " 'unsafe-eval' ") csp-source ";
" (when is-debug "connect-src ws://localhost:9630/api/remote-relay;") "
base-uri 'none';
form-action 'none';\">

<title>REPL Output</title>

<link rel=\"stylesheet\" href=\"" css-href "\" />

<!-- Should these stylesheets and scripts be saved and referenced locally so that if users are offline the webview still functions as expected? -->
<link
rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github-dark.min.css\"
data-code-theme=\"dark\"
disabled
/>
<link
rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github.min.css\"
data-code-theme=\"light\"
disabled
/>
<link
rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/base16/windows-high-contrast.min.css\"
data-code-theme=\"high-contrast\"
disabled
/>
<link
rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/base16/windows-high-contrast-light.min.css\"
data-code-theme=\"high-contrast-light\"
disabled
/>

<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/languages/clojure.min.js\"></script>

</head>
<body>
<div id=\"output\"></div>

<script src=\"" js-source "\"></script>
</body>
</html>"))

(defn get-js-source
[{:keys [vscode/vscode]
vscode-context :vscode/context}
{:keys [^js webview-panel]}]
(let [extension-uri (.. ^js vscode-context -extensionUri)
js-path (.. ^js vscode -Uri (joinPath extension-uri "repl-output-ui" "js" "main.js"))]
(.. ^js webview-panel -webview (asWebviewUri js-path))))

(defn get-css-path
[{:keys [vscode/vscode]
vscode-context :vscode/context}]
(let [extension-uri (.. ^js vscode-context -extensionUri)]
(.. ^js vscode -Uri (joinPath extension-uri "repl-output-ui" "css" "main.css"))))

(defn set-webview-html!
[context
{:keys [^js webview-panel]}]
(let [js-source (get-js-source context {:webview-panel webview-panel})
css-path (get-css-path context)
css-href (.. ^js webview-panel -webview (asWebviewUri css-path))
csp-source (.. ^js webview-panel -webview -cspSource)
webview-html (get-webview-html context {:js-source js-source :css-href css-href :csp-source csp-source})]
(set! (.. webview-panel -webview -html) webview-html)))

(defn set-code-theme!
"Takes a context, a webview panel and a vscode.ColorThemeKind enum value and sets the code theme in the webview based
on the given color theme kind."
[{:keys [vscode/vscode]} {:keys [color-theme-kind webview-panel]}]
(let [color-theme-kind-enum (.. ^js vscode -ColorThemeKind)
code-theme (condp = color-theme-kind
(.. color-theme-kind-enum -Dark) "dark"
(.. color-theme-kind-enum -Light) "light"
(.. color-theme-kind-enum -HighContrast) "high-contrast"
(.. color-theme-kind-enum -HighContrastLight) "high-contrast-light"
nil)]
(if code-theme
(post-message-to-webview webview-panel {:command/name "set-code-theme"
:content code-theme})
(util/log-to-console
:error
"Cannot set code theme in output webview. There is no code theme set for the ColorThemeKind enum value of"
color-theme-kind))))

(defn create-color-theme-change-listener
[{:keys [^js vscode/vscode] :as context}
{:keys [webview-panel]}]
(.. vscode -window
(onDidChangeActiveColorTheme
(fn [e]
(set-code-theme! context {:color-theme-kind (.. e -kind)
:webview-panel webview-panel})))))

(defn add-subscriptions []
(let [context {:vscode/vscode @util/vscode}
subscriptions [(create-color-theme-change-listener context {:webview-panel @repl-output-webview-panel})]]
(run! (fn [subscription]
(.. ^js @util/vscode-context -subscriptions (push subscription)))
subscriptions)))

(defn create-repl-output-webview-panel
[context]
(let [webview-panel (.. ^js @util/vscode -window
(createWebviewPanel
"calva:repl-output"
"REPL Output"
#js {:preserveFocus true
:viewColumn (.. ^js @util/vscode -ViewColumn -Beside)}
#js {:enableScripts true
;; If performance or memory consumption becomes a problem, we can use the setState
;; and getState to manually retain the context of the webview when it's hidden.
;; See https://code.visualstudio.com/api/extension-guides/webview#persistence
:retainContextWhenHidden true
:enableFindWidget true}))]
(.. ^js webview-panel (onDidDispose (fn [] (dispose-repl-output-webview-panel repl-output-webview-panel))))
(set-webview-html! context {:webview-panel webview-panel})
(reset! repl-output-webview-panel webview-panel)
(add-subscriptions)
webview-panel))

;; TODO: Write spec/schema for context
(defn ^:export show-repl-output-webview-panel []
(let [context {:env/is-debug (if (= js/process.env.IS_DEBUG "true") true false)
:vscode/vscode @util/vscode
:vscode/context @util/vscode-context}
^js webview-panel (or @repl-output-webview-panel (create-repl-output-webview-panel context))
active-code-theme-kind (.. ^js @util/vscode -window -activeColorTheme -kind)]
(.. webview-panel (reveal nil true))
(set-code-theme! context {:color-theme-kind active-code-theme-kind
:webview-panel webview-panel})))

;; TODO: Add tests
;; TODO: Refactor this to use a mapping of output category -> command name
(defn ^:export append
[^js options message]
(let [output-category (.-outputCategory options)]
(case output-category
"otherOut" (post-message-to-webview @repl-output-webview-panel {:command/name "show-stdout"
:content message})
"evalOut" (post-message-to-webview @repl-output-webview-panel {:command/name "show-stdout"
:content message})
"evalResults" (post-message-to-webview @repl-output-webview-panel {:command/name "show-result"
:content message})
;; TODO: Make this show differently?
"evalErr" (post-message-to-webview @repl-output-webview-panel {:command/name "show-stdout"
:content message})
"otherErr" (post-message-to-webview @repl-output-webview-panel {:command/name "show-stdout"
:content message})
"clojure" (post-message-to-webview @repl-output-webview-panel {:command/name "show-result"
:content message})
(util/log-to-console
:error
(str "Cannot append content to output webview. No outputCategory matches \"" output-category "\"")))))

(def stacktrace-classes-to-ignore
#{"clojure.lang.RestFn"
"clojure.lang.AFn"})

(defn stacktrace-entry->string
[{:keys [var name file line]}]
(let [name (or var name)]
(str name " (" file ":" line ")")))

(defn ^:export append-stacktrace
[^js stacktrace]
(let [stacktrace (js->clj stacktrace :keywordize-keys true)
stacktrace-message (->> stacktrace
(filter (fn [{:keys [flags class]}]
(and (not (some #{"dup"} flags))
(not (contains? stacktrace-classes-to-ignore class)))))
(map stacktrace-entry->string)
(str/join "\n"))]
(post-message-to-webview @repl-output-webview-panel {:command/name "show-stdout"
:content stacktrace-message})))

(defn ^:export clear-webview []
(post-message-to-webview @repl-output-webview-panel {:command/name "clear-webview"}))

;; TODO: See if can send repl output to webview when it's hidden and see it once unhidden
;; "You cannot send messages to a hidden webview, even when retainContextWhenHidden is enabled."
;; https://code.visualstudio.com/api/extension-guides/webview#theming-webview-content
Loading