From 5cb43de5a6ea192127bd946501d8239aff5014e4 Mon Sep 17 00:00:00 2001 From: Galvarcus <117151435+Galvarcus@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:58:41 -0500 Subject: [PATCH] the text arguments of a command in a lambda block run onto later lines Problem: The text arguments of a command in a lambda block run onto later lines. Solution: End the text of a command at a head that opens a line of the block (Galvarcus). The lines of a lambda block stay in one statement. text_args read a word as an argument of every text command before it in the statement, up to a bar, and `:normal` past every bar. So after `edit foo`, `highlight Foo guifg=red` or `normal! gg`, a call `Missing()` on the next line of the block was marked as a word of Vim, and a call to a function that does not exist gave no unplaced name. opens_block_line now tells a head that opens a line of the block, and the text of a command before it ends there. 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. The four corpora and the survey report the same as before. fixes: #155 related: #140 related: #153 Assisted-by: Claude Opus 5 Signed-off-by: Galvarcus <117151435+Galvarcus@users.noreply.github.com> --- src/lang/vim9/parse.rs | 17 +++++++++++++++++ tests/vim9_excmds.rs | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/lang/vim9/parse.rs b/src/lang/vim9/parse.rs index 71e6ff9..5b93403 100644 --- a/src/lang/vim9/parse.rs +++ b/src/lang/vim9/parse.rs @@ -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); } @@ -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 diff --git a/tests/vim9_excmds.rs b/tests/vim9_excmds.rs index 1bb8e1b..7ac3963 100644 --- a/tests/vim9_excmds.rs +++ b/tests/vim9_excmds.rs @@ -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 = 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}" + ); + } +}