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
2 changes: 1 addition & 1 deletion src/lang/vim9/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/lang/vim9/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -652,7 +661,7 @@ pub fn recv_type(
locals: &Locals,
types: &Types,
) -> Option<String> {
if at < 2 || stmt[at - 1].text != "." {
if at < 2 || !behind_dot(stmt, at) {
return None;
}

Expand Down
19 changes: 19 additions & 0 deletions tests/vim9_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>\n return {}\nenddef\nvar x = Make()\n .Value()\n";

assert!(one(text, "Value").member);
}
Loading