Permalink
Browse files

Formatting of JSDocs

Add behavior to control formating of doc string arguments for JSDocs
returned by tern.
  • Loading branch information...
1 parent 8e9024d commit b5d0c0bfca57e297331d113e8a9d73b733183f7d @mortalapeman committed Apr 27, 2014
Showing with 24 additions and 7 deletions.
  1. +23 −6 src/lt/plugins/tern.cljs
  2. +1 −1 ternjs.behaviors
@@ -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]
@@ -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))))
View
@@ -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
]

0 comments on commit b5d0c0b

Please sign in to comment.