Permalink
Browse files

Merge pull request #6 from seancaffery/add-gutter-support

Add hint gutter behaviour
  • Loading branch information...
2 parents 48f69ac + 73d529c commit 08f287553fdc8ce33ef87cf4985b35ff207bda85 @ibdknox ibdknox committed Jul 16, 2014
Showing with 54 additions and 1 deletion.
  1. +21 −0 css/jshint.css
  2. +2 −1 jshint.behaviors
  3. +31 −0 src/lt/plugins/jshint.cljs
View
21 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;
+}
+
View
3 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]}}
View
31 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]

0 comments on commit 08f2875

Please sign in to comment.