1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
(in-package #:cl-markdown)
(eval-when (:compile-toplevel :load-toplevel :execute)
(export '(
symbols-exported-with-no-definition
symbols-that-should-be-documented
symbols-documented-by-document
symbols-documented-by-documents
symbols-not-documented-by-multi-document
)))
(defmethod documents ((document document)) (list document))
(defmethod documents ((document multi-document)) (children document))
(defun build-documentation-report (source target document packages
&key (format :html) excluded-symbols
docs-package search-locations)
(cl-markdown:markdown
source
:format format
:stream target
:additional-extensions '(unmentioned-symbols-report
unused-exported-symbols-report
markdown-warnings-report
documented-symbols-report)
:properties `((:documentation-document
. ,document)
(:documentation-documents
. ,(documents document))
(:documentation-packages
. ,(ensure-list packages))
(:documentation-excluded-symbols
. ,excluded-symbols)
,@(when docs-package
`((:docs-package . ,(find-package docs-package))))
(:search-locations
. ,(append
(list
(system-relative-pathname 'cl-markdown "resources/"))
(ensure-list search-locations)))
(:style-sheet . "markdown-report-styles.css"))))
(defun symbols-defined-by-packages (packages &key excluded-symbols)
(sort
(remove-duplicates
(loop for package in (ensure-list packages) append
(let ((package (find-package package)))
(loop for s being the symbols
of package when
(and (eql package (symbol-package s))
(or (fboundp s)
(boundp s)
(find-class s nil)
(get s 'prolog:functor)
(eq (system:variable-information s) :special)
(member s excluded-symbols)
#+allegro
(symbol-is-type-specifier-p s)
;; Could check deftypes if necessary.
))
collect s))))
'string< :key 'symbol-name))
(defun symbols-exported-with-no-definition (packages &key excluded-symbols)
(sort
(remove-duplicates
(loop for package in (ensure-list packages) append
(loop for s being the external-symbols
of package unless
(or (fboundp s)
(boundp s)
(find-class s nil)
(get s 'prolog:functor)
(eq (system:variable-information s) :special)
(member s excluded-symbols)
#+allegro
(symbol-is-type-specifier-p s)
;; Could check deftypes if necessary.
)
collect s)))
'string< :key 'symbol-name))
#+allegro
(defun symbol-is-type-specifier-p (x)
(or (excl:normalize-type
x :loud (lambda (&rest r)
(declare (ignore r))
(return-from symbol-is-type-specifier-p nil)))
t))
(defun symbols-that-should-be-documented
(packages &key
(excluded-packages (list :common-lisp
#+allegro :excl))
excluded-symbols)
(let ((excluded-packages (mapcar #'find-package excluded-packages)))
(sort
(remove-duplicates
(loop for package in (ensure-list packages) append
(loop for s being the external-symbols
of package unless
(or (member s excluded-symbols)
(member (symbol-package s) excluded-packages))
collect s)))
'string< :key 'symbol-name)))
#+(or)
(mapcar #'print
(symbols-that-should-be-documented
(list :db.agraph :db.agraph.parser
:db.agraph.serializer
:sparql
:net.cluster)))
(defun symbols-documented-by-document (document default-package)
(let ((*package* (or (let ((*current-document* document))
(document-property :docs-package))
(find-package default-package)))
(markdown-package (find-package :cl-markdown)))
(flet ((fix-symbol (symbol)
(if (eql (symbol-package symbol) markdown-package)
(intern (symbol-name symbol) *package*)
symbol)))
(mapcar
(lambda (thing)
(etypecase thing
(symbol (fix-symbol thing))
(cons (list (first thing) (fix-symbol (second thing))))))
(cl-containers:collect-keys
(first (cl-containers:item-at-1
(cl-markdown::properties document) :documentation-anchors))
:transform #'car)))))
(defun symbols-documented-by-documents (documents default-package)
(remove-duplicates
(loop for document in documents append
(symbols-documented-by-document document default-package))))
(defun symbols-not-documented-by-multi-document
(multi-doc packages default-package &key
(excluded-packages (list :common-lisp
#+allegro :excl))
(excluded-symbols nil))
(sort
(set-difference
(symbols-that-should-be-documented
packages :excluded-packages excluded-packages
:excluded-symbols excluded-symbols)
(symbols-documented-by-documents multi-doc default-package))
#'string-lessp))
#+ignore
(symbols-not-documented-by-multi-document
(second *last-multi-doc*)
(list :db.agraph :db.agraph.parser
:db.agraph.serializer
:sparql
:net.cluster)
:excluded-symbols (symbols-explicitly-undocumented-for-agraph))
(defextension (unused-exported-symbols-report)
(when (eq phase :render)
(let ((packages (document-property :documentation-packages))
(excluded (document-property :documentation-excluded-symbols))
(*package* (or (document-property :docs-package)
*package*))
(os *output-stream*))
(format os "~&<div id='symbols-exported-with-no-definition' class='markdown-report'>~%")
(format os "~&<h1>Exported Symbols with no apparent use</h1>~%")
(cond (packages
(let ((symbols (symbols-exported-with-no-definition
packages :excluded-symbols excluded)))
(format os "~&<div>~%")
(format os "~&<h2>From packages:</h2>~%")
(format os "~&~{~&<span>~a</span>~^ ~}"
(mapcar #'package-name packages))
(format os "~&</div>~%")
(cond ((> (length symbols) 0)
(format os "~&<h2>~:d Symbols</h2>~%"
(length symbols))
(loop for s in symbols do
(format os "~&<span>~s</span> ~%" s)))
(t
(format os "~&All exported symbols are accounted for~%"
(length symbols))))
(when excluded
(format os "~&<div class='excluded-symbols'>~%")
(format os "~&<h2>Ignoring the following ~:d symbols</h2>~%"
(length excluded))
(format os "~&~{<span class='excluded-symbol'>~s</span> ~^ ~%~}~%"
excluded)
(format os "~&</div>~%"))))
(t
(format os "~&<p>There are no packages specified by the
property :documentation-packages~%")))
(format os "~&</div>~%"))))
(defextension (unmentioned-symbols-report
:arguments ((packages :keyword)
(excluded-symbols :keyword)
(donot-display-excluded-symbols :keyword)))
(when (eq phase :render)
(let ((packages (or packages
(document-property :documentation-packages)))
(excluded (or excluded-symbols
(document-property :documentation-excluded-symbols)))
(documents (document-property :documentation-documents))
(*package* (or (document-property :docs-package)
*package*))
(os *output-stream*))
(format os "~&<div id='symbols-not-documented' class='markdown-report'>~%")
(format os "~&<h1>Exported Symbols not mentioned in the documentation</h1>~%")
(cond (packages
(let ((symbols (symbols-not-documented-by-multi-document
documents
packages
*package*
:excluded-symbols excluded)))
(format os "~&<div>~%")
(format os "~&<h2>From packages:</h2>~%")
(format os "~&~{~&<span>~a</span> ~^ ~}"
(mapcar #'package-name packages))
(format os "~&</div>~%")
(cond ((> (length symbols) 0)
(format os "~&<h2>~:d Undocumented Symbols</h2>~%"
(length symbols))
(loop for s in symbols
do (format os "~&<span>~s</span> ~%" s)))
(t
(format os "~&All exported symbols are documented.~%")))
(when excluded
(format os "~&<div class='excluded-symbols'>~%")
(format os "~&<h2>Ignoring ~d symbols</h2>~%"
(length excluded))
(unless donot-display-excluded-symbols
(format
os "~&~{<span class='excluded-symbol'>~s</span> ~^ ~%~}~%"
excluded))
(format os "~&</div>~%"))))
(t
(format os "~&<p>There are no packages specified by the
propoerty :documentation-packages~%")))
(format os "~&</div>~%"))))
;; FIXME -- this is wrong (it's the same as unmentioned right now)
(defextension (undocumented-symbols-report
:arguments ((packages :keyword)
(excluded-symbols :keyword)
(donot-display-excluded-symbols :keyword)))
(when (eq phase :render)
(let ((packages (or packages
(document-property :documentation-packages)))
(excluded (or excluded-symbols
(document-property :documentation-excluded-symbols)))
(documents (document-property :documentation-documents))
(*package* (or (document-property :docs-package)
*package*))
(os *output-stream*))
(format os "~&<div id='symbols-not-documented' class='markdown-report'>~%")
(format os "~&<h1>Exported Symbols not mentioned in the documentation</h1>~%")
(cond (packages
(let ((symbols (symbols-not-documented-by-multi-document
documents
packages
*package*
:excluded-symbols excluded)))
(format os "~&<div>~%")
(format os "~&<h2>From packages:</h2>~%")
(format os "~&~{~&<span>~a</span> ~^ ~}"
(mapcar #'package-name packages))
(format os "~&</div>~%")
(cond ((> (length symbols) 0)
(format os "~&<h2>~:d Undocumented Symbols</h2>~%"
(length symbols))
(loop for s in symbols
do (format os "~&<span>~s</span> ~%" s)))
(t
(format os "~&All exported symbols are documented.~%")))
(when excluded
(format os "~&<div class='excluded-symbols'>~%")
(format os "~&<h2>Ignoring ~d symbols</h2>~%"
(length excluded))
(unless donot-display-excluded-symbols
(format
os "~&~{<span class='excluded-symbol'>~s</span> ~^ ~%~}~%"
excluded))
(format os "~&</div>~%"))))
(t
(format os "~&<p>There are no packages specified by the
propoerty :documentation-packages~%")))
(format os "~&</div>~%"))))
(defextension (documented-symbols-report)
(when (eq phase :render)
(let* ((documents (document-property :documentation-documents))
(*package* (or (document-property :docs-package)
*package*))
(os *output-stream*)
(symbols (symbols-documented-by-document
documents *package*)))
(format os "~&<div id='documented-symbols-report' class='markdown-report'>~%")
(format os "~&<h1>Documented symbols</h1>~%")
(cond ((> (length symbols) 0)
(format os "~&<h2>~:d Documented Symbols</h2>~%"
(length symbols))
(loop for s in symbols
do (format os "~&<span>~s</span> ~%" s)))
(t
(format os "~&All exported symbols are documented.~%")))
(format os "~&</div>~%"))))
(defextension (markdown-warnings-report
:arguments ())
(when (eq phase :render)
(bind ((os *output-stream*)
(document (document-property :documentation-document))
(documents (merge-elements
(warnings document)
(lambda (old new)
(push new old))
(lambda (new)
(list new))
:key 'first :argument 'cdr
:filter (lambda (pair)
(typep (first pair) 'document #+(or) 'child-document))))
(warnings? nil))
(format os "~&<div id='markdown-warnings' class='markdown-report'>~%")
(format os "~&<h1>Markdown Warnings</h1>~%")
(setf documents (sort documents #'string-lessp
:key (compose 'ensure-string 'source 'first)))
(loop for (document warnings) in documents do
(when warnings
(setf warnings? t)
(format os "~&<div>~%")
(format os "~&<h2>~a</h2>~%"
(short-source (source document)))
(format os "~&<ul>~%")
(loop for warning in (merge-elements
warnings
(lambda (old new)
(declare (ignore new))
(incf (second old))
old)
(lambda (new) (list new 1))
:test 'equal
:return :values) do
(format os "~&<li>~a</li>~%" warning))
(format os "~&</ul>~%")
(format os "~&</div>~%")))
(unless warnings?
(format os "~%No warnings found.~%"))
(format os "~&</div>~%"))))
|