Skip to content

Commit

Permalink
fix: Adjust outputs with trailing slashes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kenji committed Sep 6, 2024
1 parent b37a078 commit 81795b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,20 @@ impl<'a> Walker {
if let OutputChange::Add(ref add) = change {
let token_count = output.children_with_tokens().count();
let count = output.children().count();
let addition = Root::parse(&format!(", {add}")).syntax();
let last_node = token_count - 2;

// Adjust the addition for trailing slasheks
let addition = if let Some(SyntaxKind::TOKEN_COMMA) = output
.children()
.last()
.and_then(|last| last.next_sibling_or_token())
.and_then(|last_token| Some(last_token.kind()))
{
Root::parse(&format!("{add},")).syntax()
} else {
Root::parse(&format!(", {add}")).syntax()
};

let mut green = output
.green()
.insert_child(last_node, addition.green().into());
Expand Down Expand Up @@ -222,6 +234,7 @@ impl<'a> Walker {
);
return Some(Root::parse(&result.to_string()).syntax());
}

for child in output.children() {
if child.kind() == SyntaxKind::NODE_PAT_ENTRY {
if let OutputChange::Remove(ref id) = change {
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/edit__changes.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ info:
utils,
naersk,
flake-compat,
, vmsh
vmsh,
}:
{ };
}

0 comments on commit 81795b9

Please sign in to comment.