Skip to content

Commit cf0c98d

Browse files
this is gret
1 parent 4cf53b4 commit cf0c98d

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

crates/pgls_completions/src/providers/columns.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ fn get_completion_text(ctx: &TreesitterContext, col: &Column) -> CompletionText
5050

5151
#[cfg(test)]
5252
mod tests {
53+
use pgls_test_utils::QueryWithCursorPosition;
5354
use sqlx::PgPool;
5455

55-
use crate::test_helper::{TestCompletionsCase, TestCompletionsSuite};
56+
use crate::test_helper::{TestCompletionsCase, TestCompletionsSuite, assert_complete_results};
5657

5758
#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]
5859
async fn handles_nested_queries(pool: PgPool) {

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ b - public.others.b (Column)
267267
--------------
268268

269269
insert into instruments (i|, name) values ('my_bass');
270+
271+
Results:
272+
id - public.instruments.id (Column)
273+
ident - pg_catalog.pg_backend_memory_contexts.ident (Column)
274+
identity_cycle - information_schema.columns.identity_cycle (Column)
275+
identity_generation - information_schema.columns.identity_generation (Column)
276+
identity_increment - information_schema.columns.identity_increment (Column)
277+
278+
--------------
279+
270280
insert into instruments (id, |, name) values ('my_bass');
271281
**`name` is already written, so z should be suggested.**
272282

crates/pgls_treesitter/src/context/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ impl<'a> TreesitterContext<'a> {
153153
ctx.gather_tree_context();
154154
ctx.gather_info_from_ts_queries();
155155

156-
println!("{} {:#?}", ctx.text, ctx.get_node_under_cursor_content(),);
156+
println!("TreesitterContext: {:#?}", ctx);
157+
println!(
158+
"NodeUnderCursor: {:#?}",
159+
ctx.get_node_under_cursor_content()
160+
);
157161

158162
ctx
159163
}
@@ -359,6 +363,10 @@ impl<'a> TreesitterContext<'a> {
359363
}
360364
}
361365

366+
"insert_columns" => {
367+
self.wrapping_node_kind = Some(WrappingNode::List);
368+
}
369+
362370
_ => {
363371
if let Some(clause_type) =
364372
self.get_wrapping_clause_from_current_node(current_node, &mut cursor)
@@ -372,6 +380,17 @@ impl<'a> TreesitterContext<'a> {
372380
if current_node.child_count() == 0
373381
|| current_node.first_child_for_byte(self.position).is_none()
374382
{
383+
// if the cursor is exactly at the start of a punctuation node,
384+
// prefer the previous sibling (e.g., when cursor is at "i|," prefer "i" over ",")
385+
let is_punctuation = matches!(current_node.kind(), "," | ")" | ";");
386+
if is_punctuation && current_node.start_byte() == self.position {
387+
if let Some(prev) = current_node.prev_sibling() {
388+
if prev.end_byte() == self.position {
389+
self.node_under_cursor = prev;
390+
return;
391+
}
392+
}
393+
}
375394
self.node_under_cursor = current_node;
376395
return;
377396
}

0 commit comments

Comments
 (0)