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 39 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 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
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/

# This and that
.nrepl-port
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
**/.shadow-cljs/
**/out/
clojure.tmLanguage.json
/repl-output-ui
2 changes: 1 addition & 1 deletion deps-clj-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.11.2.1446
v1.11.3.1463
Binary file modified deps.clj.jar
Binary file not shown.
6 changes: 5 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
org.clojars.liverm0r/dartclojure {:mvn/version "0.2.22-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"}
#_#_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"]}
84 changes: 80 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,7 @@
"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": "webpack --mode production",
Expand Down
14 changes: 12 additions & 2 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@
: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}
: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"}}}}
105 changes: 105 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,105 @@
(ns calva.repl.webview.core
(:require
[calva.util :as util]))

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

(defn dispose-repl-output-webview-panel []
(println "Disposing repl-output-webview-panel")
(reset! repl-output-webview-panel nil))

;; TODO: See if there's a way to not have to use ^js in so many places without shadow-cljs warnings
(defn create-or-get-repl-output-webview-panel []
(or @repl-output-webview-panel
(let [webview-panel (.. ^js @util/vscode -window
(createWebviewPanel "calva:repl-output"
"REPL Output"
(.. ^js @util/vscode -ViewColumn -Two)
#js {:enableScripts true}))]
(.. ^js webview-panel (onDidDispose dispose-repl-output-webview-panel))
(reset! repl-output-webview-panel webview-panel))))

(defn get-webview-html
[js-src]
(str "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\" />

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

<!-- TODO: Uncomment this and lock it down as much as possible. Remember to disable things that default-src does not. See bottom of this section: https://web.dev/articles/csp#resource-options -->
<!-- <meta http-equiv=\"Content-Security-Policy\"
content=\"default-src 'none';
style-src https://cdnjs.cloudflare.com;
script-src https://cdnjs.cloudflare.com;\"> -->

<title>REPL Output</title>

<link
rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css\"
/>

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

</head>
<body>
<!-- TODO: Disable inline scripts - see security section in webview docs -->
<div id=\"output\"></div>

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

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

(defn show-repl-output-webview-panel []
(let [^js repl-output-webview-panel (create-or-get-repl-output-webview-panel)
js-path (.. ^js @util/vscode
-Uri
(joinPath (.. ^js @util/context -extensionUri) "repl-output-ui" "js" "main.js"))
js-src (.. repl-output-webview-panel -webview (asWebviewUri js-path))
webview-html (get-webview-html js-src)]
(set! (.. ^js repl-output-webview-panel -webview -html) webview-html)
#_(let [interval-id (js/setInterval post-message-to-webview
1000
{:command-name "show-result"
:result "Hello world!!!"})]
(js/setTimeout #(js/clearInterval interval-id)
11000))))

;; 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

(comment
(show-repl-output-webview-panel)

;; TODO: Implement this interface for communicating with the webview
;; Message
{;; This message contains a command
:command {;; Command name
:name "show-result"
;; Command args
:args {:result "Hello world"}}
;; Message id
:id "1234"}

(post-message-to-webview {:command-name "show-result"
:result "send while hidden"})

(post-message-to-webview {:command "clear-output"})

@repl-output-webview-panel

;; TODO: Don't worry about scrolling yet. We know we can do that. Explore other important unknowns first.

:rcf)
Loading