racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
454 stars 93 forks source link

LSP Falsely Calls "unused require" #692

Open veqqq opened 1 day ago

veqqq commented 1 day ago

In this file (at this commit https://github.com/veqqq/verse-reader/commit/9d85176d956927f1423d5066b034ad9c882680fd#diff-03ff549a899d4177544a2571db77418a19e57495987c3bfc80d618d8a200ee48 ) the following code occurs:

(module verse-struct racket/base
  (require racket/string)

  ; Changed to prefab for compile-time support
  (struct bible-verse (
                      [abbrev #:mutable]
                      [chapter #:mutable]
                      [verse #:mutable]
                      [text #:mutable])
    #:prefab)

  ; Parse string to extract verse
  (define (parse-verse-line line)
    (define parts (string-split line "\t"))
    (if (= (length parts) 5)
        (bible-verse
         ;; note, no book
         (string-downcase (list-ref parts 1)) ; abbreviation
         (string->number (list-ref parts 2)) ; chapter
         (string->number (list-ref parts 3)) ; verse
         (list-ref parts 4))              ; text
        (begin
          (printf "Skipping non-verse line: ~a\n" line)
          #f)))

  (provide bible-verse bible-verse? parse-verse-line
           bible-verse-abbrev 
           bible-verse-chapter bible-verse-verse 
           bible-verse-text))

(require 'verse-struct
         (for-syntax 'verse-struct))

; Compile-time parse
(begin-for-syntax
  (define-runtime-path kjv-path "kjv.tsv")
  (define kjv-verses
    (filter values
            (for/list ([line (in-list (with-input-from-file kjv-path port->lines))])
              (parse-verse-line line)))))

If you remove the for-syntax require, the begin-for-syntax of course won't have the parse-verse-line function identifier...

rfindler commented 1 day ago

Here's a simplified, self-contained program that also has the same symptom:

#lang racket

(module verse-struct racket/base
  (define parse-verse-line 1)
  (provide parse-verse-line))

(require 'verse-struct
         (for-syntax 'verse-struct))

; Compile-time parse
(begin-for-syntax
  (require racket/runtime-path racket/port)
  (define-runtime-path kjv-path "kjv.tsv")
  parse-verse-line)