Skip to content

Commit

Permalink
Rename source file; improve a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Nov 15, 2024
1 parent f52917f commit 94e531d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
8 changes: 5 additions & 3 deletions racket/lib-classify.rkt → racket/lib-pkg.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[(get-base-documentation-packages) '("racket-doc")]
[(get-distribution-documentation-packages) '("main-distribution") ])

(provide classify-lib)
(provide lib-pkg)

;; This code for classifying packages as "base" or "main-dist" is
;; borrowed from racket-index/scribblings/main/private/pkg.rkt
Expand Down Expand Up @@ -72,7 +72,9 @@
;; doesn't make it into the xref index.
;;
;; So instead: When a doc index item has an "exported from lib", we
;; use resolve-module-path and path->pkg.
;; use resolve-module-path and path->pkg. However this is moderately
;; expensive, and should be done lazily (definitely not eagerly for
;; all 32K+ xref-index items) and cached.

(define pkg-cache-for-path->pkg (make-hash))
(define (pkg-name mp)
Expand All @@ -84,7 +86,7 @@
[_ #f]))

(define cache (make-hash))
(define (classify-lib maybe-mod-path) ;=> (list pkg-name, sort)
(define (lib-pkg maybe-mod-path) ;=> (list pkg-name, sort)
(hash-ref!
cache
maybe-mod-path
Expand Down
22 changes: 11 additions & 11 deletions racket/scribble.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
setup/main-doc
version/utils
"define-fallbacks.rkt"
"lib-classify.rkt"
"lib-pkg.rkt"
"util.rkt"
"xref.rkt")

Expand Down Expand Up @@ -115,12 +115,12 @@
(with-time/log "build-doc-search-trie"
(build-doc-search-trie)))))

(define (doc-search prefix)
(define (doc-search prefix [limit 256])
(unless doc-index-trie-root
(refresh-doc-index!))
(trie-find doc-index-trie-root prefix))
(trie-find doc-index-trie-root prefix limit))

(define (trie-find root prefix [stop-after 256])
(define (trie-find root prefix limit)
(match (string->list prefix)
[(list)
null]
Expand All @@ -135,7 +135,7 @@
(define (report! n)
(for ([v (in-set (node-values n))])
(set-add! results (force v)))
(when (< (set-count results) stop-after)
(when (< (set-count results) limit)
(for ([n (in-hash-values (node-kids n))])
(report! n))))
(report! sub)]
Expand Down Expand Up @@ -217,7 +217,7 @@
(define fams (match (hash-ref ht 'language-family #f)
[(? list? fams) (string-join (map ~a fams) ", ")]
[#f "Racket"]))
(define pkg (classify-lib
(define pkg (lib-pkg
(match (exported-index-desc-from-libs desc)
[(cons lib _) lib]
[_ #f])))
Expand All @@ -239,7 +239,7 @@
(define fams (match (hash-ref ht 'language-family #f)
[(? list? fams) (string-join (map ~a fams) ", ")]
[#f "Racket"]))
(define pkg (classify-lib
(define pkg (lib-pkg
(match (hash-ref ht 'module-kind #f)
['lib (string->symbol term)]
[_ #f])))
Expand All @@ -261,22 +261,22 @@
[(? method-index-desc?) (method-what)]
[_ ""]))
(define from (string-join (map ~s (exported-index-desc-from-libs desc)) ", "))
(define pkg (classify-lib
(define pkg (lib-pkg
(match (exported-index-desc-from-libs desc)
[(cons lib _) lib]
[_ #f])))
(values what from "" pkg 0)]
[(module-path-index-desc? desc)
(define pkg (classify-lib (string->symbol term)))
(define pkg (lib-pkg (string->symbol term)))
(values "module" "" "" pkg 0)]
[else
(define pkg (classify-lib #f))
(define pkg (lib-pkg #f))
(values "documentation" (doc-from) "" pkg 0)]))
(list term sort-order what from fams pkg path anchor))

;; This is for package-details
(define (module-doc-path mod-path-str lang?)
(for/or ([v (in-list (doc-search mod-path-str))])
(for/or ([v (in-list (doc-search mod-path-str 0))])
(match-define (list term _sort what _from _fams _pkg path anchor) v)
(and (equal? term mod-path-str)
(equal? what (if lang? "language" "module"))
Expand Down

0 comments on commit 94e531d

Please sign in to comment.