Skip to content

Commit

Permalink
Show docs for macros in Sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorgirardi authored Oct 16, 2023
2 parents 3bdca20 + 683431c commit f43fbbe
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
3 changes: 3 additions & 0 deletions src/dev/clojure/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
(Reader/read "(]")
(catch Throwable e
(println (.getMessage (stacktrace/root-cause e)))))

(type (Reader/read "when-not"))
;; => convex.core.data.Symbol


;; --
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/convex_web/command.clj
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
result
(merge
#:convex-web.command
{:result (convex/result-data result)
{:result (convex/result-data (source command) result)
:status
(if result-error-code
:convex-web.command.status/error
Expand Down
86 changes: 48 additions & 38 deletions src/main/clojure/convex_web/convex.clj
Original file line number Diff line number Diff line change
Expand Up @@ -350,44 +350,54 @@
:else
x))

(defn result-data [^Result result]
(let [^ACell result-id (.getID result)
^ACell result-error-code (.getErrorCode result)
^ACell result-value (.getValue result)
^AVector result-trace (.getTrace result)]
(merge #:convex-web.result {:id (datafy result-id)
:type (or (some-> result-value .getType .toString) "Nil")
:value (or (some-> result-value $.write/string str) "nil")}

;; Interactive Syntax.
(when (instance? Syntax result-value)
(let [syntax-meta (datafy (.getMeta ^Syntax result-value))

{:keys [interact?]} syntax-meta]

(merge {:convex-web.result/metadata syntax-meta}
(when interact?
(let [element (datafy result-value)
element (coerce-element element)
element (if-not (s/valid? ::hiccup/element element)
[:v-box
[:text "Sorry. This syntax is not valid in the Interactive Sandbox:"]
[:code (str element)]]

;; Else; valid element.
element)]
{:convex-web.result/interactive (s/conform ::hiccup/element element)})))))

(when (instance? CoreFn result-value)
{:convex-web.result/metadata (datafy (metadata (.getSymbol ^CoreFn result-value)))})

(when (instance? convex.core.data.Symbol result-value)
(when-let [metadata (metadata result-value)]
{:convex-web.result/metadata (datafy metadata)}))

(when result-error-code
{:convex-web.result/error-code (datafy result-error-code)
:convex-web.result/trace (datafy result-trace)}))))
(defn result-data
([^Result result]
(result-data nil result))
([^String source ^Result result]
(let [^ACell result-id (.getID result)
^ACell result-error-code (.getErrorCode result)
^ACell result-value (.getValue result)
^AVector result-trace (.getTrace result)

source (try
(Reader/read source)
(catch Exception _
nil))

result-metadata (when (instance? convex.core.data.Symbol source)
(metadata source))]

(merge #:convex-web.result {:id (datafy result-id)
:type (or (some-> result-value .getType .toString) "Nil")
:value (or (some-> result-value $.write/string str) "nil")}

;; -- Interactive Syntax
(when (instance? Syntax result-value)
(let [syntax-meta (datafy (.getMeta ^Syntax result-value))

{:keys [interact?]} syntax-meta]

(merge {:convex-web.result/metadata syntax-meta}
(when interact?
(let [element (datafy result-value)
element (coerce-element element)
element (if-not (s/valid? ::hiccup/element element)
[:v-box
[:text "Sorry. This syntax is not valid in the Interactive Sandbox:"]
[:code (str element)]]

;; Else; valid element.
element)]
{:convex-web.result/interactive (s/conform ::hiccup/element element)})))))

;; -- Metadata
(when result-metadata
{:convex-web.result/metadata (datafy result-metadata)})

;; -- Error
(when result-error-code
{:convex-web.result/error-code (datafy result-error-code)
:convex-web.result/trace (datafy result-trace)})))))

(defn transaction-result-data [^ATransaction atransaction ^Result result]
(let [tx (cond
Expand Down
2 changes: 1 addition & 1 deletion src/test/clojure/convex_web/convex_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
:convex-web.result/type "Function",
:convex-web.result/value "map"}

(convex/result-data (Result/create (CVMLong/create 1) Core/MAP))))))
(convex/result-data "map" (Result/create (CVMLong/create 1) Core/MAP))))))

(deftest account-key-from-hex-test
(testing "Invalid Address"
Expand Down

0 comments on commit f43fbbe

Please sign in to comment.