Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from seancaffery/add-gutter-support
Browse files Browse the repository at this point in the history
Add hint gutter behaviour
  • Loading branch information
ibdknox committed Jul 16, 2014
2 parents 48f69ac + 73d529c commit 08f2875
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
21 changes: 21 additions & 0 deletions 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;
}

3 changes: 2 additions & 1 deletion 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]}} :editor.javascript [:lt.plugins.jshint/inline-hints]}}
31 changes: 31 additions & 0 deletions src/lt/plugins/jshint.cljs
Expand Up @@ -5,6 +5,7 @@
[lt.objs.command :as cmd] [lt.objs.command :as cmd]
[lt.objs.editor :as editor] [lt.objs.editor :as editor]
[lt.objs.editor.pool :as pool] [lt.objs.editor.pool :as pool]
[lt.util.dom :as dom]
[lt.objs.thread :as thread]) [lt.objs.thread :as thread])
(:require-macros [lt.macros :refer [defui background]])) (:require-macros [lt.macros :refer [defui background]]))


Expand All @@ -18,6 +19,22 @@
(->> (js->clj (.-errors jshint) :keywordize-keys true) (->> (js->clj (.-errors jshint) :keywordize-keys true)
(raise obj-id :hinted)))))) (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] (defui mark [errors spacing]
[:div.hintwrapper [:div.hintwrapper
[:span.spacer spacing] [:span.spacer spacing]
Expand All @@ -30,6 +47,20 @@
(-> (re-seq #"^\s+" text) (-> (re-seq #"^\s+" text)
(first)))) (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 (object/behavior* ::inline-hints
:triggers #{:hinted} :triggers #{:hinted}
:reaction (fn [this hints] :reaction (fn [this hints]
Expand Down

0 comments on commit 08f2875

Please sign in to comment.