Skip to content

Commit d5da7a3

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 d5da7a3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

main.rkt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
racket/file
3535
racket/match
3636
racket/sequence
37+
racket/string
3738
rebellion/base/comparator
3839
rebellion/base/option
3940
rebellion/base/range
@@ -142,11 +143,15 @@
142143
(git-commit! message)))
143144

144145

145-
(define (resyntax-analyze source
146+
(define/guard (resyntax-analyze source
146147
#:suite [suite default-recommendations]
147148
#:lines [lines (range-set (unbounded-range #:comparator natural<=>))])
148149
(define comments (with-input-from-source source read-comment-locations))
149150
(define full-source (source->string source))
151+
(guard (string-prefix? full-source "#lang racket") #:else
152+
(log-resyntax-warning "skipping ~a because it does not start with #lang racket"
153+
(or (source-path source) "string source"))
154+
(refactoring-result-set #:base-source source #:results '()))
150155
(log-resyntax-info "analyzing ~a" (or (source-path source) "string source"))
151156
(for ([comment (in-range-set comments)])
152157
(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)