Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP Falsely Calls "unused require" #692

Open
veqqq opened this issue Nov 4, 2024 · 1 comment
Open

LSP Falsely Calls "unused require" #692

veqqq opened this issue Nov 4, 2024 · 1 comment

Comments

@veqqq
Copy link

veqqq commented Nov 4, 2024

In this file (at this commit veqqq/verse-reader@9d85176#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
Copy link
Member

rfindler commented Nov 4, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants