Skip to content

Commit

Permalink
Re-implement module-doc-path using doc-search trie
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Nov 15, 2024
1 parent 890c054 commit f52917f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
4 changes: 2 additions & 2 deletions racket/package.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
net/url
(only-in "scribble.rkt"
module-doc-path
refresh-module-doc-path-index!))
refresh-doc-index!))

(provide package-list
package-details
Expand Down Expand Up @@ -312,7 +312,7 @@
(act!))
(flush-output out)
(close-output-port out)
(refresh-module-doc-path-index!)))
(refresh-doc-index!)))

(module+ example
(define (pump)
Expand Down
61 changes: 16 additions & 45 deletions racket/scribble.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
bluebox-command
doc-search
module-doc-path
refresh-module-doc-path-index!)
refresh-doc-index!)

(module+ test
(require rackunit))
Expand Down Expand Up @@ -107,15 +107,18 @@
;; values: (set/c (promise/c doc-trie-value))
(define (empty-node) (node (make-hasheq) (set)))

(define root #f)
(define doc-index-trie-root #f)

(define (refresh-doc-index!)
(set! doc-index-trie-root
(with-memory-use/log "build-doc-search-trie"
(with-time/log "build-doc-search-trie"
(build-doc-search-trie)))))

(define (doc-search prefix)
(unless root
(set! root
(with-memory-use/log "build-doc-search-trie"
(with-time/log "build-doc-search-trie"
(build-doc-search-trie)))))
(trie-find root prefix))
(unless doc-index-trie-root
(refresh-doc-index!))
(trie-find doc-index-trie-root prefix))

(define (trie-find root prefix [stop-after 256])
(match (string->list prefix)
Expand Down Expand Up @@ -271,42 +274,10 @@
(values "documentation" (doc-from) "" pkg 0)]))
(list term sort-order what from fams pkg path anchor))


;; This is for package-details

(define (build-module-doc-path-index)
(define (is-module? desc)
(or (module-path-index-desc? desc)
(and (index-desc? desc)
(eq? 'lib (hash-ref (index-desc-extras desc) 'module-kind #f)))))
(define (is-lang? desc)
(or (language-index-desc? desc)
(and (index-desc? desc)
(eq? 'lang (hash-ref (index-desc-extras desc) 'module-kind #f)))))
(for*/hash ([entry (in-list (xref-index xref))]
[desc (in-value (entry-desc entry))]
[module? (in-value (is-module? desc))]
[lang? (in-value (is-lang? desc))]
#:when (or module? lang?))
(define k (cons (car (entry-words entry))
lang?))
(define v (let-values ([(p a) (xref-tag->path+anchor xref (entry-tag entry))])
(let ([p (path->string p)]
[a a])
(cons p a))))
(values k v)))

(define module-doc-path-index #f)

(define (refresh-module-doc-path-index!)
(set! module-doc-path-index
(with-memory-use/log "build-module-doc-path-index"
(with-time/log "build-module-doc-path-index"
(build-module-doc-path-index)))))

(define (module-doc-path mod-path-str lang?)
(unless module-doc-path-index
(refresh-module-doc-path-index!))
(hash-ref module-doc-path-index
(cons mod-path-str lang?)
#f))
(for/or ([v (in-list (doc-search mod-path-str))])
(match-define (list term _sort what _from _fams _pkg path anchor) v)
(and (equal? term mod-path-str)
(equal? what (if lang? "language" "module"))
(cons path anchor))))

0 comments on commit f52917f

Please sign in to comment.