Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions default-recommendations/match-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,29 @@ no-change-test: "list element variable definitions not refactorable when referen
(define z (list-ref (first pt-list) 2))
(+ x y z))
------------------------------


test: "refactoring list element variable definitions to match-define doesn't reformat surroundings"
------------------------------
(require racket/list)
(define (f pt)

( void )

(define x (list-ref pt 0))
(define y (list-ref pt 1))
(define z (list-ref pt 2))

; comment
( + x y z ))
==============================
(require racket/list)
(define (f pt)

( void )

(match-define (list x y z) pt)

; comment
( + x y z ))
------------------------------
6 changes: 4 additions & 2 deletions default-recommendations/match-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
`match-define`. Note that the suggested replacement raises an error if the list contains more \
elements than expected."
#:literals (define)
(~seq body-before ... (define v:id ref-expr:list-ref-expr) ...+ body-after ...)
(~seq body-before ... (~and definition (define v:id ref-expr:list-ref-expr)) ...+ body-after ...+)
#:do [(define num-vars (length (attribute v)))]
#:with first-list-id (first (attribute ref-expr.list-id))
#:when (for/and ([list-id (in-list (rest (attribute ref-expr.list-id)))])
Expand All @@ -257,7 +257,9 @@ elements than expected."
id:id
#:when (free-identifier=? (attribute id) (attribute first-list-id))
#:when (not (equal? (syntax-property (attribute id) 'usage-count) num-vars))))
(body-before ... (match-define (list v ...) first-list-id) body-after ...))
#:with match-definition
#'(~replacement (match-define (list v ...) first-list-id) #:original-splice (definition ...))
(body-before ... (~focus-replacement-on match-definition) body-after ...))


(define-refactoring-suite match-shortcuts
Expand Down