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
17 changes: 17 additions & 0 deletions src/lang/vim9/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,13 @@ pub(super) fn text_args(stmt: &[Tok], i: usize, heads: &[usize]) -> bool {
return false;
}

// A line of a lambda block opens a command of its own, so the
// text of a command ends with its line, where no bar ends it.
// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/155
if (at + 1..=i).any(|k| opens_block_line(stmt, k, heads)) {
return false;
}

if shell(stmt, at) {
return shell_text(stmt, at, i, heads);
}
Expand All @@ -2325,6 +2332,16 @@ pub(super) fn text_args(stmt: &[Tok], i: usize, heads: &[usize]) -> bool {
})
}

/// FUNCTION: Whether the token at `k` opens a line of a lambda block:
/// a head on a line that the token before it does not share, as
/// `block_lines` gives. A head that a backslash carries on to a line
/// of its own ends the text as well, which leaves a word counted and
/// drops none.
/// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/155
fn opens_block_line(stmt: &[Tok], k: usize, heads: &[usize]) -> bool {
k > 0 && stmt[k].line != stmt[k - 1].line && heads.contains(&k)
}

/// FUNCTION: A command word without the count that the lexer glues to
/// it, as the `2` of `:2Diag prev`.
/// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/111
Expand Down
23 changes: 23 additions & 0 deletions tests/vim9_excmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,26 @@ fn a_call_behind_the_bang_of_a_modifier_keeps_its_credit() {

assert!(!one(text, "Helper").owned);
}

/// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/155
#[test]
fn the_text_arguments_of_a_command_in_a_lambda_block_end_with_its_line() {
let text = "vim9script\nvar F = () => {\n edit foo\n Missing()\n highlight Foo guifg=red\n Missing()\n normal! gg\n Missing()\n}\n";
let missing: Vec<Reference> = refs(text)
.into_iter()
.filter(|r| r.name == "Missing")
.collect();

assert_eq!(missing.len(), 3, "{missing:?}");
assert!(missing.iter().all(|r| !r.owned), "{missing:?}");

for name in ["foo", "Foo", "guifg", "red", "gg"] {
assert!(
refs(text)
.iter()
.filter(|r| r.name == name)
.all(|r| r.owned),
"{name}"
);
}
}
Loading