-
-
Notifications
You must be signed in to change notification settings - Fork 865
Description
I've been doing some refactoring when I noticed that renaming a function argument using a rename LSP action produces invalid code.
Steps to reproduce
Initial code:
type Groups {
Groups(one: Int, two: Int, three: Int, four: Int, five: Int)
}
fn rebalance(grouping: Groups) -> Groups {
case grouping {
Groups(_, _, three, four, five) if five > three ->
Groups(..grouping, three: 0, four: four + three * 2, five: five - three)
Groups(_, _, three, four, five) ->
Groups(..grouping, three: three - five, four: four + five * 2, five: 0)
}
}
If I put my cursor on the grouping
argument of the function rebalance
and execute a rename
LSP action via vim.lsp.buf.rename
function with a new name set to groups
I get the following:
// type definition omitted
fn rebalance(groups: Groups) -> Groups {
case groups {
Groups(_, _, three, four, five) if five > three ->
Groups(..groupsthree: 0, four: four + three * 2, five: five - three)
Groups(_, _, three, four, five) ->
Groups(..groupsthree: three - five, four: four + five * 2, five: 0)
}
}
Notice how there's not comma between a spread with an updated name in a record update and the three
field.
Even weirder thing happens if I use the initial code and rename grouping
argument in the rebalance
function to a longer new name, e.g. not_grouping
:
// type definition omitted
fn rebalance(not_grouping: Groups) -> Groups {
case not_grouping {
Groups(_, _, three, four, five) if five > three ->
Groups(..not_groupingping, three: 0, four: four + three * 2, five: five - three)
Groups(_, _, three, four, five) ->
Groups(..not_groupingping, three: three - five, four: four + five * 2, five: 0)
}
}
Notice that this time comma is there but the name of the spreaded variable in the record update is wrong.
Versions
Gleam: 1.12.0
OS: macOS 15.5
Editor: Neovim v0.11.3 with neovim/nvim-lspconfig v2.3.0