Skip to content

Commit 250c47c

Browse files
jackfirthclaude
andcommitted
Add examples to the source-group grimoire docs
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8f76e08 commit 250c47c

1 file changed

Lines changed: 99 additions & 11 deletions

File tree

grimoire/source-group.scrbl

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
#lang scribble/manual
22

33

4-
@(require (for-label pkg/lib
4+
@(require scribble/example
5+
(for-label pkg/lib
56
racket/base
67
racket/contract/base
78
racket/path
89
racket/sequence
10+
rebellion/base/comparator
11+
rebellion/base/range
912
rebellion/collection/range-set
1013
resyntax/grimoire/source-group
11-
resyntax/grimoire/source))
14+
resyntax/grimoire/source)
15+
(submod resyntax/private/scribble-evaluator-factory doc))
16+
17+
18+
@(define make-evaluator
19+
(make-module-sharing-evaluator-factory
20+
#:public (list 'resyntax/grimoire/source-group
21+
'resyntax/grimoire/source
22+
'rebellion/base/comparator
23+
'rebellion/base/range
24+
'rebellion/collection/range-set)
25+
#:private (list 'racket/base)))
1226

1327

1428
@title[#:tag "source-group"]{Source Groups}
@@ -63,13 +77,24 @@ memory yet. That occurs at a later step, on a per-file basis, as Resyntax is ana
6377

6478

6579
@defproc[(source-group? [v any/c]) boolean?]{
66-
A predicate that recognizes @tech{source groups} of any kind.}
80+
A predicate that recognizes @tech{source groups} of any kind.
81+
82+
@(examples
83+
#:eval (make-evaluator) #:once
84+
(source-group? (directory-source-group "/tmp/my-project"))
85+
(source-group? empty-source-group)
86+
(source-group? "/tmp/my-project"))}
6787

6888

6989
@defthing[empty-source-group source-group?]{
7090
The empty @tech{source group}, which specifies no sources at all. Resolving it produces an empty
7191
hash, and unioning it with any other source group has no effect --- it is the identity element of
72-
@racket[source-group-union].}
92+
@racket[source-group-union].
93+
94+
@(examples
95+
#:eval (make-evaluator) #:once
96+
(source-group-resolve empty-source-group)
97+
(source-group-union empty-source-group (directory-source-group "/tmp/my-project")))}
7398

7499

75100
@defproc[(source-group-union [group source-group?] ...) source-group?]{
@@ -90,34 +115,75 @@ memory yet. That occurs at a later step, on a per-file basis, as Resyntax is ana
90115
@item{@racket[(source-group-union _g _g)] and @racket[(source-group-union _g empty-source-group)]
91116
are both always @racket[equal?] to @racket[_g].}]
92117

93-
This operation is a convenience wrapper around @racket[source-group-union-all].}
118+
This operation is a convenience wrapper around @racket[source-group-union-all].
119+
120+
@(examples
121+
#:eval (make-evaluator) #:once
122+
(define project (directory-source-group "/tmp/my-project"))
123+
(define pkg (package-source-group "my-package"))
124+
(define main
125+
(single-source-group "/tmp/other/main.rkt"
126+
(range-set (closed-open-range 1 20 #:comparator natural<=>))))
127+
(eval:check (equal? (source-group-union project pkg) (source-group-union pkg project)) #true)
128+
(eval:check (equal? (source-group-union (source-group-union project pkg) main)
129+
(source-group-union project (source-group-union pkg main)))
130+
#true)
131+
(eval:check (equal? (source-group-union project project) project) #true)
132+
(eval:check (equal? (source-group-union project empty-source-group) project) #true)
133+
(eval:check (equal? (source-group-union) empty-source-group) #true)
134+
(source-group-union project))}
94135

95136

96137
@defproc[(source-group-union-all [groups (sequence/c source-group?)]) source-group?]{
97138
Combines every source group in @racket[groups] into a single @tech{source group}, exactly as
98139
@racket[source-group-union] does for its arguments, but accepting the groups as a single sequence
99140
of any kind. An empty sequence produces @racket[empty-source-group]. This is how the
100-
@seclink["cli"]{command-line interface} combines its collection of target flags into one group.}
141+
@seclink["cli"]{command-line interface} combines its collection of target flags into one group.
142+
143+
@(examples
144+
#:eval (make-evaluator) #:once
145+
(define project (directory-source-group "/tmp/my-project"))
146+
(define pkg (package-source-group "my-package"))
147+
(eval:check (equal? (source-group-union-all (list project pkg))
148+
(source-group-union project pkg))
149+
#true)
150+
(eval:check (equal? (source-group-union-all (vector project pkg))
151+
(source-group-union project pkg))
152+
#true)
153+
(eval:check (equal? (source-group-union-all (list)) empty-source-group) #true))}
101154

102155

103156
@defproc[(single-source-group [path path-string?] [lines immutable-range-set?])
104157
source-group?]{
105158
Constructs a @tech{source group} containing only the file at @racket[path], with suggestions
106159
restricted to the line numbers in @racket[lines]. The path is normalized with
107-
@racket[simple-form-path] upon construction.}
160+
@racket[simple-form-path] upon construction.
161+
162+
@(examples
163+
#:eval (make-evaluator) #:once
164+
(single-source-group "/tmp/my-project/main.rkt"
165+
(range-set (closed-open-range 1 20 #:comparator natural<=>))))}
108166

109167

110168
@defproc[(directory-source-group [path path-string?]) source-group?]{
111169
Constructs a @tech{source group} containing every file within the directory at @racket[path],
112170
including files within subdirectories, with all lines of each file eligible for suggestions. The
113-
path is normalized with @racket[simple-form-path] upon construction.}
171+
path is normalized with @racket[simple-form-path] upon construction.
172+
173+
@(examples
174+
#:eval (make-evaluator) #:once
175+
(directory-source-group "/tmp/my-project"))}
114176

115177

116178
@defproc[(package-source-group [package-name string?]) source-group?]{
117179
Constructs a @tech{source group} containing every file of the installed Racket package named
118180
@racket[package-name], with all lines of each file eligible for suggestions. The package's
119181
installation directory is located with @racket[pkg-directory] during resolution, and resolution
120-
raises a user error if no such package is installed.}
182+
raises a user error if no such package is installed.
183+
184+
@(examples
185+
#:eval (make-evaluator) #:once
186+
(package-source-group "my-package"))}
121187

122188

123189
@defproc[(git-repository-source-group [repository-path path-string?] [base-ref string?])
@@ -133,7 +199,11 @@ memory yet. That occurs at a later step, on a per-file basis, as Resyntax is ana
133199
of context surrounding them, so suggestions within the margin can still be posted as review
134200
comments. More generally, a three-line margin is the default amount of extra context that many Unix
135201
tools choose when interoperating via the unified diff format, particularly the
136-
@hyperlink["https://en.wikipedia.org/wiki/Diff#Unified_format"]{diff} tool.}
202+
@hyperlink["https://en.wikipedia.org/wiki/Diff#Unified_format"]{diff} tool.
203+
204+
@(examples
205+
#:eval (make-evaluator) #:once
206+
(git-repository-source-group "/tmp/my-project" "main"))}
137207

138208

139209
@defproc[(source-group-resolve [group source-group?])
@@ -142,5 +212,23 @@ memory yet. That occurs at a later step, on a per-file basis, as Resyntax is ana
142212
values and whose values are the line numbers eligible for suggestions in each file. When the same
143213
file is included multiple times by a unioned group, its line sets are unioned.
144214

215+
@(examples
216+
#:eval (make-evaluator) #:once
217+
(source-group-resolve
218+
(single-source-group "/tmp/my-project/main.rkt"
219+
(range-set (closed-open-range 1 20 #:comparator natural<=>))))
220+
(source-group-resolve
221+
(source-group-union
222+
(single-source-group "/tmp/my-project/main.rkt"
223+
(range-set (closed-open-range 1 20 #:comparator natural<=>)))
224+
(single-source-group "/tmp/my-project/main.rkt"
225+
(range-set (closed-open-range 50 60 #:comparator natural<=>))))))
226+
145227
Resolution discards all files that don't have the @exec{.rkt} extension. This is where the
146-
@seclink["cli"]{command-line interface}'s restriction to @exec{.rkt} files is implemented.}
228+
@seclink["cli"]{command-line interface}'s restriction to @exec{.rkt} files is implemented.
229+
230+
@(examples
231+
#:eval (make-evaluator) #:once
232+
(source-group-resolve
233+
(single-source-group "/tmp/my-project/notes.txt"
234+
(range-set (closed-open-range 1 20 #:comparator natural<=>)))))}

0 commit comments

Comments
 (0)