Skip to content
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;
}
}