Skip to content

Commit

Permalink
Move entries within function literals as if in a list (clojure-lsp#792)
Browse files Browse the repository at this point in the history
rewrite-clj has a special node for function literals #(,,,). For the
purposes of moving entries, these nodes are the same as list nodes.
  • Loading branch information
mainej authored Mar 3, 2022
1 parent a3164f3 commit 317fda3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Binary file modified docs/images/features/move-coll-entry.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions lib/src/clojure_lsp/feature/move_coll_entry.clj
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@
(let [parent-zloc (z-up zloc)
child-count (count-children parent-zloc)
strat (case (some-> parent-zloc z/tag)
:map {:breadth 2, :rind no-rind}
:set {:breadth 1, :rind no-rind}
:vector (vector-strategy parent-zloc uri db)
:list (list-strategy parent-zloc child-count)
:map {:breadth 2, :rind no-rind}
:set {:breadth 1, :rind no-rind}
:vector (vector-strategy parent-zloc uri db)
(:list :fn) (list-strategy parent-zloc child-count)
nil)]
(when strat
(let [strat (assoc strat
Expand Down
2 changes: 2 additions & 0 deletions lib/test/clojure_lsp/feature/move_coll_entry_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@
(h/code "(assoc x :a 2 |:b 1)"))
(assert-move-up (h/code "(assoc x |:b 1 :a 2)")
(h/code "(assoc x :a 2 :b |1)"))
(assert-move-up (h/code "#(assoc % |:b 2 :a 1)")
(h/code "#(assoc % :a 1 |:b 2)"))
(assert-move-up (h/code "(-> {}"
" (assoc |:b 1 :a 2))")
(h/code "(-> {}"
Expand Down

0 comments on commit 317fda3

Please sign in to comment.