diff --git a/css/jshint.css b/css/jshint.css new file mode 100644 index 0000000..cd72c17 --- /dev/null +++ b/css/jshint.css @@ -0,0 +1,21 @@ +.jshint-gutter-marker .hint-gutter-dot { + width: 8px; + height: 10px; + background: red; +} + +.jshint-gutter-marker .hints { + display: none; + width: 310px; + background:var(bg); + padding: 5px; + left: 10px; + top: -1px; + position: absolute; +} + +.jshint-gutter-marker .hints li { + padding-bottom: 3px; + display: block; +} + diff --git a/jshint.behaviors b/jshint.behaviors index 5b8da9e..d234cb0 100644 --- a/jshint.behaviors +++ b/jshint.behaviors @@ -1,2 +1,3 @@ -{:+ {:app [(:lt.objs.plugins/load-js "jshint_compiled.js")] +{:+ {:app [(:lt.objs.plugins/load-js "jshint_compiled.js") + (:lt.objs.plugins/load-css "css/jshint.css")] :editor.javascript [:lt.plugins.jshint/inline-hints]}} diff --git a/src/lt/plugins/jshint.cljs b/src/lt/plugins/jshint.cljs index c74b0aa..29c87a7 100644 --- a/src/lt/plugins/jshint.cljs +++ b/src/lt/plugins/jshint.cljs @@ -5,6 +5,7 @@ [lt.objs.command :as cmd] [lt.objs.editor :as editor] [lt.objs.editor.pool :as pool] + [lt.util.dom :as dom] [lt.objs.thread :as thread]) (:require-macros [lt.macros :refer [defui background]])) @@ -18,6 +19,22 @@ (->> (js->clj (.-errors jshint) :keywordize-keys true) (raise obj-id :hinted)))))) + +(defui gutter-marker [hints] + [:div.jshint-gutter-marker + [:div.hint-gutter-dot] + [:div.hints.cm-variable + [:ul + (map (fn [h] + [:li + (str "- " h)]) hints)]]] + :mouseover (fn [e] + (if-let [target (dom/next (.-target e))] + (dom/set-css target {:display :block}))) + :mouseout (fn [e] + (if-let [target (dom/next (.-target e))] + (dom/set-css target {:display :none})))) + (defui mark [errors spacing] [:div.hintwrapper [:span.spacer spacing] @@ -30,6 +47,20 @@ (-> (re-seq #"^\s+" text) (first)))) +(object/behavior* ::gutter-hints + :triggers #{:hinted} + :reaction (fn [this hints] + (editor/operation (editor/->cm-ed this) + (fn [] + (let [hints-by-line (group-by :line (filter identity hints)) + markers (map (fn [[line hs]] + {:line (dec line) :mark (gutter-marker (map #(:reason %) hs))}) hints-by-line)] + + (editor/add-gutter this "jshint-gutter" 8) + (.clearGutter (editor/->cm-ed this) "jshint-gutter") + (doall (map (fn [marker] + (.setGutterMarker (editor/->cm-ed this) (:line marker) "jshint-gutter" (:mark marker))) markers))))))) + (object/behavior* ::inline-hints :triggers #{:hinted} :reaction (fn [this hints]