-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
source_location.cljs
56 lines (50 loc) · 1.45 KB
/
source_location.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(ns portal.ui.viewer.source-location
(:require [clojure.spec.alpha :as s]
[portal.colors :as c]
[portal.ui.inspector :as ins]
[portal.ui.rpc :as rpc]
[portal.ui.styled :as d]
[portal.ui.theme :as theme]))
;;; :spec
(s/def ::ns symbol?)
(s/def ::column int?)
(s/def ::line int?)
(s/def ::file string?)
(s/def ::source-location
(s/keys :req-un [::line ::column]
:opt-un [::ns ::file]))
;;;
(defn- source-location? [value]
(s/valid? ::source-location value))
(defn ->source-location [value]
(when (source-location? value)
(with-meta
(select-keys value [:ns :column :line :file :label])
(assoc (meta value)
:portal.viewer/default :portal.viewer/source-location))))
(defn inspect-source [value]
(let [theme (theme/use-theme)]
[d/div
{:on-click
(fn [e]
(.stopPropagation e)
(rpc/call 'portal.runtime.jvm.editor/goto-definition value))
:style/hover
{:opacity 1
:text-decoration :underline}
:style
{:opacity 0.75
:cursor :pointer
:color (::c/uri theme)}}
[ins/highlight-words
(str
(or (:label value)
(:ns value)
(:file value))
":"
(:line value))]]))
(def viewer
{:predicate source-location?
:component inspect-source
:name :portal.viewer/source-location
:doc "View a map as a source location, provides goto definition on click."})