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); +}