Skip to content

Commit 93928a1

Browse files
fix: do not complete right after asterisk
1 parent 6469ce3 commit 93928a1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

crates/pgt_completions/src/relevance/filtering.rs

+41
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ impl CompletionFilter<'_> {
4545
return None;
4646
}
4747

48+
// no completions if we're right after an asterisk:
49+
// `select * {}`
50+
if ctx.node_under_cursor.is_some_and(|n| {
51+
n.prev_sibling()
52+
.is_some_and(|p| (p.kind() == "all_fields") && n.kind() == "identifier")
53+
}) {
54+
return None;
55+
}
56+
4857
Some(())
4958
}
5059

@@ -130,3 +139,35 @@ impl CompletionFilter<'_> {
130139
Some(())
131140
}
132141
}
142+
143+
#[cfg(test)]
144+
mod tests {
145+
use crate::test_helper::{
146+
CURSOR_POS, CompletionAssertion, assert_complete_results, assert_no_complete_results,
147+
};
148+
149+
#[tokio::test]
150+
async fn completion_after_asterisk() {
151+
let setup = r#"
152+
create table users (
153+
id serial primary key,
154+
email text,
155+
address text
156+
);
157+
"#;
158+
159+
assert_no_complete_results(format!("select * {}", CURSOR_POS).as_str(), setup).await;
160+
161+
// if there s a COMMA after the asterisk, we're good
162+
assert_complete_results(
163+
format!("select *, {}", CURSOR_POS).as_str(),
164+
vec![
165+
CompletionAssertion::Label("address".into()),
166+
CompletionAssertion::Label("email".into()),
167+
CompletionAssertion::Label("id".into()),
168+
],
169+
setup,
170+
)
171+
.await;
172+
}
173+
}

0 commit comments

Comments
 (0)