Skip to content

Commit

Permalink
fix: remove unnecessary #lang diagnostic in drracket-created files
Browse files Browse the repository at this point in the history
Files created by DrRacket do not have `#lang` directives; they only
have `#reader` directives instead. (See e.g.
#86).
The "Missing `#lang`" diagnostic should not be reported in these files.

Fixes #86.
  • Loading branch information
virchau13 authored and jeapostrophe committed Sep 9, 2024
1 parent 140d94e commit 05dbc95
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions check-syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,21 @@
#:message msg))))))

(define (get-indenter doc-text)
(define text (send doc-text get-text))
(define lang-info
(with-handlers ([exn:fail:read? (lambda (e) 'missing)]
[exn:missing-module? (lambda (e) #f)])
(read-language (open-input-string (send doc-text get-text)) (lambda () 'missing))))
(read-language (open-input-string text) (lambda () 'missing))))
(cond
[(procedure? lang-info)
(lang-info 'drracket:indentation #f)]
[(eq? lang-info 'missing) lang-info]
[(eq? lang-info 'missing)
; check for a #reader directive at start of file, ignoring comments
; the ^ anchor here matches start-of-string, not start-of-line
(if (regexp-match #rx"^(;[^\n]*\n)*#reader" text)
#f ; most likely a drracket file, use default indentation
; (https://github.com/jeapostrophe/racket-langserver/issues/86)
'missing)]
[else #f]))

(define-syntax-rule (timeout time-sec body)
Expand Down

0 comments on commit 05dbc95

Please sign in to comment.