Skip to content

fix: do not complete right after asterisk #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
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
41 changes: 41 additions & 0 deletions crates/pgt_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ impl CompletionFilter<'_> {
return None;
}

// no completions if we're right after an asterisk:
// `select * {}`
if ctx.node_under_cursor.is_some_and(|n| {
n.prev_sibling()
.is_some_and(|p| (p.kind() == "all_fields") && n.kind() == "identifier")
}) {
return None;
}

Some(())
}

Expand Down Expand Up @@ -130,3 +139,35 @@ impl CompletionFilter<'_> {
Some(())
}
}

#[cfg(test)]
mod tests {
use crate::test_helper::{
CURSOR_POS, CompletionAssertion, assert_complete_results, assert_no_complete_results,
};

#[tokio::test]
async fn completion_after_asterisk() {
let setup = r#"
create table users (
id serial primary key,
email text,
address text
);
"#;

assert_no_complete_results(format!("select * {}", CURSOR_POS).as_str(), setup).await;

// if there s a COMMA after the asterisk, we're good
assert_complete_results(
format!("select *, {}", CURSOR_POS).as_str(),
vec![
CompletionAssertion::Label("address".into()),
CompletionAssertion::Label("email".into()),
CompletionAssertion::Label("id".into()),
],
setup,
)
.await;
}
}