Skip to content

Commit ca1f3b5

Browse files
committed
Avoid error on analyzing non-racket files
When `resyntax-analyze` is called directly on a non-`#lang racket` file, it currently results in an error during macro expansion being raised and logged. This causes issues when the langserver tries to analyze the current file with Resyntax, see jeapostrophe/racket-langserver#153. This PR moves Resyntax's logic for handling such files out of the file group resolution code and into the core of `resyntax-analyze`.
1 parent 95eb1fd commit ca1f3b5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

main.rkt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@
142142
(git-commit! message)))
143143

144144

145-
(define (resyntax-analyze source
145+
(define/guard (resyntax-analyze source
146146
#:suite [suite default-recommendations]
147147
#:lines [lines (range-set (unbounded-range #:comparator natural<=>))])
148148
(define comments (with-input-from-source source read-comment-locations))
149149
(define full-source (source->string source))
150+
(guard (string-prefix? full-source "#lang racket") #:else
151+
(log-resyntax-warning "skipping ~a because it does not start with #lang racket"
152+
(or (source-path source) "string source"))
153+
(refactoring-result-set #:base-source source #:results '()))
150154
(log-resyntax-info "analyzing ~a" (or (source-path source) "string source"))
151155
(for ([comment (in-range-set comments)])
152156
(log-resyntax-debug "parsed comment: ~a: ~v" comment (substring-by-range full-source comment)))

private/file-group.rkt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@
116116

117117
(define/guard (rkt-file? portion)
118118
(define path (file-portion-path portion))
119-
(guard (path-has-extension? path #".rkt") #:else #false)
120-
(define content (file->string path))
121-
(string-prefix? content "#lang racket"))
119+
(guard (path-has-extension? path #".rkt") #:else #false)))
122120

123121

124122
;; GitHub allows pull request reviews to include comments only on modified lines, plus the 3 lines

0 commit comments

Comments
 (0)