|
4 | 4 | racket/contract |
5 | 5 | racket/logging |
6 | 6 | syntax/modread |
| 7 | + racket/path |
7 | 8 | racket/port |
8 | 9 | "editor.rkt" |
9 | 10 | "doc-trace.rkt" |
|
28 | 29 | [else #f])) |
29 | 30 |
|
30 | 31 | ;; TODO: cache the namespace with some strategy |
31 | | -(define (expand-source path in collector) |
| 32 | +(define (expand-source path in collector #:expand? [expand? #t]) |
32 | 33 | (define-values (src-dir _1 _2) (split-path path)) |
33 | 34 | (define ns (make-base-namespace)) |
34 | 35 | (define-values (add-syntax done) |
|
50 | 51 | (λ () |
51 | 52 | (with-handlers ([exn:fail? (λ (exn) exn)]) |
52 | 53 | (parameterize ([current-output-port (open-output-nowhere)]) |
53 | | - (if (syntax? stx) |
| 54 | + (if (and expand? (syntax? stx)) |
54 | 55 | (expand stx) |
55 | 56 | #f)))) |
56 | 57 | 'info)) |
|
71 | 72 | (define (check-syntax uri doc-text) |
72 | 73 | (define path (uri->path uri)) |
73 | 74 | (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))) |
75 | 78 | (define new-trace (new build-trace% [src path] [doc-text doc-text] [indenter indenter])) |
76 | 79 |
|
77 | 80 | (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?))) |
79 | 82 |
|
80 | 83 | (send new-trace walk-stx er) |
81 | 84 | (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)))) |
83 | 89 |
|
84 | 90 | (provide |
85 | 91 | (struct-out CSResult) |
86 | 92 | (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?)] |
88 | 96 | [check-syntax (-> string? (is-a?/c lsp-editor%) CSResult?)])) |
89 | 97 |
|
0 commit comments