From 23dda0aa0b78a3a6ce4bb610e52a2805b4ab94d1 Mon Sep 17 00:00:00 2001 From: Galvarcus <117151435+Galvarcus@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:23:17 -0500 Subject: [PATCH] a dot that ends a line of a lambda block reaches into the next line Problem: A dot that ends a line of a lambda block reaches into the next line. Solution: Read a word as a member only where the dot before it stands on its line (Galvarcus). The lines of a lambda block stay in one statement, so a dot that ended one line stood right before the first word of the next. The analyzer read that word as a member: after `:!ctags -R .` a call `Missing()` was `R.Missing`, a member that resolves to no function, so a call to a function that does not exist gave no unplaced name, and after `edit .` a call to a function of the project could leave the function a ghost. Vim9 allows no space behind the dot of a member, and the end of a line is one. behind_dot now asks that the dot and the word share a line, for the member flag and for the type of the receiver. A dot that opens a line still reaches into the line before it. The four corpora and the survey report the same as before. A word on the line below `edit .` is still read as an argument of `edit`, which is #155. fixes: #153 related: #140 related: #155 Assisted-by: Claude Opus 5 Signed-off-by: Galvarcus <117151435+Galvarcus@users.noreply.github.com> --- src/lang/vim9/parse.rs | 2 +- src/lang/vim9/types.rs | 11 ++++++++++- tests/vim9_syntax.rs | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lang/vim9/parse.rs b/src/lang/vim9/parse.rs index 05e2963..71e6ff9 100644 --- a/src/lang/vim9/parse.rs +++ b/src/lang/vim9/parse.rs @@ -1516,7 +1516,7 @@ impl Collect<'_> { return; } - let member = i > 0 && stmt[i - 1].text == DOT; + let member = types::behind_dot(stmt, i); let owned = vims || (member && word == NEW) diff --git a/src/lang/vim9/types.rs b/src/lang/vim9/types.rs index 217cb06..db3470e 100644 --- a/src/lang/vim9/types.rs +++ b/src/lang/vim9/types.rs @@ -640,6 +640,15 @@ fn idents(stmt: &[Tok]) -> Vec<&str> { .collect() } +/// FUNCTION: Whether the word at `at` stands behind the dot of a +/// member. Vim9 allows no space behind that dot, and the end of a +/// line is one, so a dot that ends a line reaches into nothing on the +/// next, as the `.` of `:!ctags -R .` on a line of a lambda block. +/// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/153 +pub fn behind_dot(stmt: &[Tok], at: usize) -> bool { + at > 0 && stmt[at - 1].text == "." && stmt[at - 1].line == stmt[at].line +} + /// FUNCTION: The type of the receiver of a member access at a /// position, or none when nothing in scope gives it one. /// @@ -652,7 +661,7 @@ pub fn recv_type( locals: &Locals, types: &Types, ) -> Option { - if at < 2 || stmt[at - 1].text != "." { + if at < 2 || !behind_dot(stmt, at) { return None; } diff --git a/tests/vim9_syntax.rs b/tests/vim9_syntax.rs index c3e033b..b82508c 100644 --- a/tests/vim9_syntax.rs +++ b/tests/vim9_syntax.rs @@ -264,3 +264,22 @@ fn a_project_function_in_a_call_string_is_still_a_name() { assert_eq!(marks, vec![false]); } + +/// Vim9 allows no space behind the dot of a member, and the end of a +/// line is one, so a dot that ends a line reaches into nothing. +/// REFERENCE: https://github.com/Galvarcus/GhostCode/issues/153 +#[test] +fn a_dot_that_ends_a_line_of_a_lambda_block_reaches_into_nothing() { + let text = "vim9script\nvar F = () => {\n :!ctags -R .\n Missing()\n}\n"; + let missing = one(text, "Missing"); + + assert!(!missing.member && missing.recv.is_none(), "{missing:?}"); +} + +#[test] +fn a_dot_that_opens_a_line_still_reaches_into_the_line_before() { + let text = + "vim9script\ndef Make(): dict\n return {}\nenddef\nvar x = Make()\n .Value()\n"; + + assert!(one(text, "Value").member); +}