Skip to content

Commit 75b1a6d

Browse files
authored
Capture printed output when analyzing code (#430)
This should keep it out of Autofixer pull request descriptions, as observed in racket/typed-racket#1417.
1 parent 046ad6d commit 75b1a6d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

private/source.rkt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
[source-code-analysis? (-> any/c boolean?)]
2828
[source-code-analysis-code (-> source-code-analysis? source?)]
2929
[source-code-analysis-visited-forms (-> source-code-analysis? (listof syntax?))]
30+
[source-code-analysis-expansion-time-output (-> source-code-analysis? immutable-string?)]
3031
[syntax-source-location (-> syntax? source-location?)]
3132
[with-input-from-source (-> source? (-> any) any)]))
3233

@@ -78,7 +79,7 @@
7879
#:guard (λ (original contents _) (values original (string->immutable-string contents))))
7980

8081

81-
(define-record-type source-code-analysis (code visited-forms))
82+
(define-record-type source-code-analysis (code visited-forms expansion-time-output))
8283
(define-record-type source-location (source line column position span))
8384

8485

@@ -177,9 +178,13 @@
177178
(add-all-original-subforms! visited))]
178179
[(_ _) (void)])
179180

181+
(define output-port (open-output-string))
180182
(define expanded
181-
(parameterize ([current-expand-observe observe-event!])
183+
(parameterize ([current-expand-observe observe-event!]
184+
[current-output-port output-port])
182185
(expand program-stx)))
186+
187+
(define output (get-output-string output-port))
183188
(define binding-table (fully-expanded-syntax-binding-table expanded))
184189
(define original-binding-table-by-position
185190
(for*/fold ([table (hash)])
@@ -221,7 +226,7 @@
221226
(sorting syntax-source-location<=> #:key syntax-source-location)
222227
#:into into-list))
223228

224-
(source-code-analysis #:code code #:visited-forms visited)))
229+
(source-code-analysis #:code code #:visited-forms visited #:expansion-time-output output)))
225230

226231

227232
(define (syntax-source-location stx)

0 commit comments

Comments
 (0)