Skip to content

Commit

Permalink
Unused requires: Annotate mod path; fixes racket#110
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Mar 26, 2020
1 parent f6f5c1a commit 8bdbc69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drracket-tool-lib/drracket/private/syncheck/traversals.rkt
Expand Up @@ -801,18 +801,22 @@
(unless (hash-ref module-lang-requires (list (syntax-source stx)
(syntax-position stx)
(syntax-span stx)) #f)
;; Use module path portion of syntax: Its more-specific
;; location matters for e.g. combine-in and things that expand
;; to it. See issue #110.
(define mod-stx (phaseless-spec->raw-module-path stx))
(define defs-text (current-annotations))
(define source-editor (find-source-editor stx))
(define source-editor (find-source-editor mod-stx))
(when (and defs-text source-editor)
(define pos (syntax-position stx))
(define span (syntax-span stx))
(define pos (syntax-position mod-stx))
(define span (syntax-span mod-stx))
(when (and pos span)
(define start (- pos 1))
(define fin (+ start span))
(send defs-text syncheck:add-unused-require source-editor start fin)
(send defs-text syncheck:add-text-type
source-editor start fin 'unused-identifier)))
(color stx unused-require-style-name)))))
(color mod-stx unused-require-style-name)))))

;; color-unused-binder : source integer integer -> void
(define (color-unused-binder source start end)
Expand Down
37 changes: 37 additions & 0 deletions drracket-tool-test/tests/check-syntax/syncheck-direct.rkt
Expand Up @@ -419,3 +419,40 @@
(check-pred file-exists? path)))

(delete-directory/files tmp-dir))

;;; Issue #110
(let ([src (format "~s"
'(module m racket/base
(require racket/require
(multi-in racket (list match))
racket/set
(rename-in racket/list [first 1st]))
first
1st))])
;; Check that change doesn't break arrows
(check-equal? (apply set (get-binding-arrows/pxpy src))
(set '((31 45 0.5 0.5) (47 55 0.5 0.5))
'((10 21 0.5 0.5) (89 98 0.5 0.5))
'((10 21 0.5 0.5) (23 30 0.5 0.5))
'((64 68 0.5 0.5) (125 130 0.5 0.5))
'((99 110 0.5 0.5) (131 134 0.5 0.5))))
;; Check unused requires
(define unused-requires '())
(define annotations
(new (class (annotations-mixin object%)
(super-new)
(define/override (syncheck:add-unused-require src beg end)
(set! unused-requires
(cons (list src beg end) unused-requires))))))
(define-values (add-syntax done)
(make-traversal (make-base-namespace)
(current-directory)))
(parameterize ([current-annotations annotations]
[current-namespace (make-base-namespace)])
(add-syntax (expand
(read-syntax
'the-source
(open-input-string src))))
(done))
(check-equal? unused-requires
'()))

0 comments on commit 8bdbc69

Please sign in to comment.