Skip to content

Commit e9e5656

Browse files
committed
add syncheck:unused-binder and use it to rename (and, bonus, get the bright green highlight thingy) binders with no references
closes #629 closes #196
1 parent 8df705d commit e9e5656

File tree

8 files changed

+142
-63
lines changed

8 files changed

+142
-63
lines changed

drracket-tool-doc/scribblings/drracket-tools/drracket-tools.scrbl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,18 @@ in order to make the results be platform independent.
450450

451451
@history[#:added "1.2"]
452452
}
453-
453+
454+
@defmethod[(syncheck:unused-binder [source-obj (not/c #f)]
455+
[left exact-nonnegative-integer?]
456+
[right exact-nonnegative-integer?])
457+
void?]{
458+
Called to indicate that there is a binder with no
459+
references in @racket[source-obj] at the location spanned by
460+
@racket[left] and @racket[right].
461+
462+
@history[#:added "1.4"]
463+
}
464+
454465
@defmethod[(syncheck:color-range [source-obj (not/c #f)]
455466
[start exact-nonnegative-integer?]
456467
[end exact-nonnegative-integer?]
@@ -558,6 +569,7 @@ in order to make the results be platform independent.
558569
syncheck:add-jump-to-definition/phase-level+space
559570
syncheck:add-definition-target
560571
syncheck:add-definition-target/phase-level+space
572+
syncheck:unused-binder
561573
syncheck:add-id-set
562574
syncheck:color-range
563575
syncheck:add-prefixed-require-reference

drracket-tool-test/tests/check-syntax/syncheck-direct.rkt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@
767767
(and (equal? type 'unused-identifier)
768768
(list start end)))
769769

770+
(define-get-arrows unused-binder
771+
(syncheck:unused-binder _ start end)
772+
(list start end))
773+
770774
(check-equal?
771775
(get-text-type
772776
(string-append
@@ -794,7 +798,24 @@
794798
(set '(69 74) ;racket/match from multi-in
795799
'(77 87))) ;racket/set
796800

801+
(check-equal?
802+
(unused-binder
803+
(string-append
804+
"#lang racket/base\n"
805+
"(define unused 1)\n"))
806+
(set '(26 32)))
797807

808+
(check-equal?
809+
(unused-binder
810+
(string-append
811+
"#lang racket/base\n"
812+
"(define-syntax-rule (m f)\n"
813+
" (void\n"
814+
" (let ([f 1]) f)\n"
815+
" (let ([f 2]) f)))\n"
816+
"\n"
817+
"(m ffff)"))
818+
(set '(96 100)))
798819

799820

800821
;

drracket-tool-text-lib/drracket/check-syntax.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
syncheck:add-jump-to-definition/phase-level+space
5353
syncheck:add-definition-target
5454
syncheck:add-definition-target/phase-level+space
55+
syncheck:unused-binder
5556
syncheck:add-prefixed-require-reference
5657
syncheck:add-unused-require
5758
syncheck:color-range)

drracket-tool-text-lib/drracket/private/syncheck/syncheck-intf.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
syncheck:add-jump-to-definition/phase-level+space
2020
syncheck:add-definition-target
2121
syncheck:add-definition-target/phase-level+space
22+
syncheck:unused-binder
2223
syncheck:add-prefixed-require-reference
2324
syncheck:add-unused-require
2425
syncheck:color-range
@@ -74,6 +75,7 @@
7475
(define/public (syncheck:add-definition-target source pos-left pos-right id mods) (void))
7576
(define/public (syncheck:add-definition-target/phase-level+space source pos-left pos-right id mods phase-level+space)
7677
(syncheck:add-definition-target source pos-left pos-right id mods))
78+
(define/public (syncheck:unused-binder source pos-left pos-right) (void))
7779
(define/public (syncheck:color-range source start finish style-name) (void))
7880
(define/public (syncheck:add-prefixed-require-reference
7981
req-src req-pos-left req-pos-right

drracket-tool-text-lib/drracket/private/syncheck/syncheck-local-member-names.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
syncheck:add-jump-to-definition/phase-level+space
2121
syncheck:add-definition-target
2222
syncheck:add-definition-target/phase-level+space
23+
syncheck:unused-binder
2324
syncheck:add-prefixed-require-reference
2425
syncheck:add-unused-require)

drracket-tool-text-lib/drracket/private/syncheck/traversals.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@
11291129
(define end (second val))
11301130
(define color? (third val))
11311131
(define (show-starts)
1132+
(when (zero? start)
1133+
(define defs-text (current-annotations))
1134+
(when defs-text
1135+
(send defs-text syncheck:unused-binder
1136+
(list-ref key 0) (list-ref key 1) (list-ref key 2))))
11321137
(add-mouse-over/loc (list-ref key 0) (list-ref key 1) (list-ref key 2)
11331138
(cond
11341139
[(zero? start)
@@ -1624,6 +1629,7 @@
16241629
(log syncheck:add-prefixed-require-reference
16251630
_req-src req-pos-left req-pos-right
16261631
prefix _prefix-src prefix-start prefix-end)
1632+
(log syncheck:unused-binder _src left right)
16271633
(log syncheck:add-unused-require _req-src req-pos-left req-pos-right)
16281634

16291635
(define/public (get-trace) (reverse trace))

drracket-tool-text-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
(define pkg-authors '(robby))
1515

16-
(define version "1.3")
16+
(define version "1.4")
1717

1818
(define license
1919
'(Apache-2.0 OR MIT))

0 commit comments

Comments
 (0)