Skip to content

Commit 2f6190d

Browse files
authored
stop require #lang line for data files (#213)
related to #207
1 parent 71ed499 commit 2f6190d

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

doclib/check-syntax.rkt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
racket/contract
55
racket/logging
66
syntax/modread
7+
racket/path
78
racket/port
89
"editor.rkt"
910
"doc-trace.rkt"
@@ -28,7 +29,7 @@
2829
[else #f]))
2930

3031
;; TODO: cache the namespace with some strategy
31-
(define (expand-source path in collector)
32+
(define (expand-source path in collector #:expand? [expand? #t])
3233
(define-values (src-dir _1 _2) (split-path path))
3334
(define ns (make-base-namespace))
3435
(define-values (add-syntax done)
@@ -50,7 +51,7 @@
5051
(λ ()
5152
(with-handlers ([exn:fail? (λ (exn) exn)])
5253
(parameterize ([current-output-port (open-output-nowhere)])
53-
(if (syntax? stx)
54+
(if (and expand? (syntax? stx))
5455
(expand stx)
5556
#f))))
5657
'info))
@@ -71,19 +72,26 @@
7172
(define (check-syntax uri doc-text)
7273
(define path (uri->path uri))
7374
(define text (send doc-text get-text))
74-
(define indenter (get-indenter text))
75+
; rktd <-> rkt is just like JSON <-> js
76+
(define data-file? (equal? (path-get-extension path) #".rktd"))
77+
(define indenter (if data-file? #f (get-indenter text)))
7578
(define new-trace (new build-trace% [src path] [doc-text doc-text] [indenter indenter]))
7679

7780
(define in (open-input-string text))
78-
(define er (expand-source path in new-trace))
81+
(define er (expand-source path in new-trace #:expand? (not data-file?)))
7982

8083
(send new-trace walk-stx er)
8184
(send new-trace walk-log (ExpandResult-logs er))
82-
(CSResult new-trace text (ExpandResult-all-succeed? er)))
85+
(CSResult new-trace text
86+
(if data-file?
87+
(and (ExpandResult-pre-syntax er) #t)
88+
(ExpandResult-all-succeed? er))))
8389

8490
(provide
8591
(struct-out CSResult)
8692
(contract-out
87-
[expand-source (-> path? input-port? (is-a?/c syncheck-annotations<%>) ExpandResult?)]
93+
[expand-source (->* (path? input-port? (is-a?/c syncheck-annotations<%>))
94+
(#:expand? boolean?)
95+
ExpandResult?)]
8896
[check-syntax (-> string? (is-a?/c lsp-editor%) CSResult?)]))
8997

tests/lib/doc-test.rkt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@
312312
;; "x" usage: line 2, char 0, abs pos 26..27
313313
;; "define": line 1, char 1..7, abs pos 14..20
314314

315+
(test-case
316+
"rktd data file: no missing #lang or expansion diagnostics"
317+
(define d (make-doc "file:///tmp/doc-test-data.rktd" "((a . 1) (b . 2))"))
318+
(check-true (doc-expand! d))
319+
(check-equal? (doc-diagnostics d) '()))
320+
321+
(test-case
322+
"rktd data file: read errors are still reported"
323+
(define d (make-doc "file:///tmp/doc-test-data.rktd" "((a . 1)"))
324+
(check-false (doc-expand! d)))
325+
326+
(test-case
327+
"rkt file without #lang still reports missing #lang"
328+
(define d (make-doc "file:///tmp/doc-test-nolang.rkt" "1234"))
329+
(check-true (doc-expand! d))
330+
(check-true (for/or ([diag (in-list (doc-diagnostics d))])
331+
(regexp-match? #rx"#lang" (Diagnostic-message diag)))))
332+
315333
(define (make-expanded-doc)
316334
(define text
317335
#<<END

0 commit comments

Comments
 (0)