Skip to content

Commit

Permalink
more emmy viewers, fix imported-from completions
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Aug 3, 2023
1 parent a4ab62c commit 20ae7a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
15 changes: 7 additions & 8 deletions editor2/src/main/maria/editor/code/completions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@
(when (and ns name)
(try
(let [sym-name (c/name name)
ns-name-str (or (when imported-from
;; omit imported-from name if equal to sym-name
(if (= (c/name imported-from) sym-name)
(namespace imported-from)
(str imported-from)))
(sci.ns/sci-ns-name ns))]
var-sym (or imported-from
(symbol (str ns) sym-name))
detail (if (= sym-name (c/name var-sym))
(namespace var-sym)
(str var-sym))]
#js{:label sym-name
:sym (symbol ns-name-str sym-name)
:detail ns-name-str
:sym var-sym
:detail detail
;; :type "y" ;; indicates icon
;; :detail ;; short string shown after label
;; :info ;; shown when completion is selected
Expand Down
17 changes: 13 additions & 4 deletions editor2/src/main/maria/editor/extensions/emmy.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
[emmy.value]
[emmy.expression]
[emmy.operator]
[emmy.abstract.function]
[emmy.series]
[emmy.modint]
[emmy.portal.css :refer [inject!] :rename {inject! inject-css!}]
[emmy.viewer.css :refer [css-map]]
[emmy.mafs]
[maria.editor.extensions.reagent :as ext.reagent]
[maria.editor.code.show-values :as show :refer [show]]
[sci.ctx-store :refer [get-ctx]]))
[sci.ctx-store :refer [get-ctx]]
[yawn.view :as v]))

(defn show-frozen [opts x]
(show opts (emmy.value/freeze x)))
Expand All @@ -21,16 +24,22 @@
(defn show-string [opts x]
(str x))

(defn show-number-string [opts x]
(v/x [:span.text-number (str x)]))

(def viewers-by-type
{emmy.expression/Literal show-expression-of
emmy.operator/Operator show-frozen
emmy.series/PowerSeries show-frozen
emmy.series/Series show-frozen
js/BigInt show-string})
emmy.series/Series (fn [opts x] (show opts (seq x)))
emmy.abstract.function/Function show-frozen
emmy.modint/ModInt show-frozen
emmy.quaternion/Quaternion show-frozen
js/BigInt show-number-string})

(defn show-emmy [opts x]
(if (instance? Fraction x)
(str x)
(show-number-string opts x)
(if-let [viewer (viewers-by-type (type x))]
(viewer opts x)
(when-let [m (meta x)]
Expand Down

0 comments on commit 20ae7a6

Please sign in to comment.