racket / racket/drracket

LSP Falsely Calls "unused require"

Open
#692 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
516
Forks
103
PR merge metrics
No merged PRs in 30d

Description

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...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced commit and inspect how the LSP analyzes the require and begin-for-syntax forms in the shown module. Reproduce the diagnostic with the for-syntax import present and absent. Done means the required binding is not reported as unused when parse-verse-line is referenced at compile time.

Written by the indexing model from the issue text.

Assessment

Domain
developer-experience, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.