Skip to content

Commit

Permalink
Formatting of JSDocs
Browse files Browse the repository at this point in the history
Add behavior to control formating of doc string arguments for JSDocs
returned by tern.
  • Loading branch information
mortalapeman committed Apr 27, 2014
1 parent 8e9024d commit b5d0c0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/lt/plugins/tern.cljs
@@ -1,5 +1,6 @@
(ns lt.plugins.tern
(:require [lt.object :as object]
(:require [clojure.string :as string]
[lt.object :as object]
[lt.objs.plugins :as plugins]
[lt.objs.editor :as ed]
[lt.objs.thread :as thread]
Expand Down Expand Up @@ -538,17 +539,33 @@
;; Docs
;;****************************************************

(defn format-doc [s]
(->> (string/split (string/replace s "@" "\n@") "*")
(map string/trim)
(interpose "\n")
(apply str)
(string/triml)))


(behavior ::javascript-format-doc
:triggers #{:format+}
:exclusive true
:reaction (fn [editor m]
(update-in m [:doc] format-doc)))

(behavior ::javascript-doc
:triggers #{:editor.doc}
:reaction (fn [editor]
(let [req (ed->req editor :type {:docs true :types true})
loc (ed/->cursor editor)
cb (fn [_ result]
(let [doc {:doc (.-doc result)
:args (.-type result)
:loc loc
:file (.-origin result)
:name (.-name result)}]
(let [doc (merge (object/raise-reduce editor :format+
{:doc (.-doc result)
:args (when (not= (.-name result) (.-type result))
(.-type result))
:name (.-name result)})
{:loc loc
:file (.-origin result)})]
(object/raise editor :editor.javascript.doc doc)))]
(clients/send tern-client :request req :only cb))))

Expand Down
2 changes: 1 addition & 1 deletion ternjs.behaviors
Expand Up @@ -8,7 +8,7 @@
:lt.plugins.tern/print-javascript-doc
:lt.plugins.tern/jump-to-definition
(:lt.objs.editor/on-change :tern.send-current-document)
]
:lt.plugins.tern/javascript-format-doc]
:hinter [:lt.plugins.tern/clear-token
:lt.plugins.tern/line-change
]
Expand Down

0 comments on commit b5d0c0b

Please sign in to comment.