Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ok
  • Loading branch information
juleswritescode committed Jun 5, 2025
commit 3d5c1c60c99ec03a5562169790821b2a0da202af
12 changes: 6 additions & 6 deletions crates/pgt_completions/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum WrappingClause<'a> {
DropTable,
DropColumn,
AlterColumn,
RenameColumn,
PolicyName,
ToRoleAssignment,
}
Expand Down Expand Up @@ -196,11 +197,6 @@ impl<'a> CompletionContext<'a> {
ctx.gather_info_from_ts_queries();
}

if cfg!(test) {
println!("{:#?}", ctx.text);
println!("{:#?}", ctx.wrapping_clause_type);
}

ctx
}

Expand Down Expand Up @@ -431,7 +427,7 @@ impl<'a> CompletionContext<'a> {
}

"where" | "update" | "select" | "delete" | "from" | "join" | "column_definitions"
| "drop_table" | "alter_table" | "drop_column" | "alter_column" => {
| "drop_table" | "alter_table" | "drop_column" | "alter_column" | "rename_column" => {
self.wrapping_clause_type =
self.get_wrapping_clause_from_current_node(current_node, &mut cursor);
}
Expand Down Expand Up @@ -522,6 +518,8 @@ impl<'a> CompletionContext<'a> {
(WrappingClause::From, &["from"]),
(WrappingClause::Join { on_node: None }, &["join"]),
(WrappingClause::AlterTable, &["alter", "table"]),
(WrappingClause::AlterColumn, &["alter", "table", "alter"]),
(WrappingClause::RenameColumn, &["alter", "table", "rename"]),
(
WrappingClause::AlterTable,
&["alter", "table", "if", "exists"],
Expand Down Expand Up @@ -598,6 +596,7 @@ impl<'a> CompletionContext<'a> {
.or_insert(HashSet::from([table]));
}
}

"column" => {
if let Some(NodeText::Original(txt)) = self.get_ts_node_content(&sib) {
let entry = MentionedColumn {
Expand Down Expand Up @@ -637,6 +636,7 @@ impl<'a> CompletionContext<'a> {
"drop_table" => Some(WrappingClause::DropTable),
"drop_column" => Some(WrappingClause::DropColumn),
"alter_column" => Some(WrappingClause::AlterColumn),
"rename_column" => Some(WrappingClause::RenameColumn),
"alter_table" => Some(WrappingClause::AlterTable),
"column_definitions" => Some(WrappingClause::ColumnDefinitions),
"insert" => Some(WrappingClause::Insert),
Expand Down
25 changes: 13 additions & 12 deletions crates/pgt_completions/src/providers/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,22 +777,23 @@ mod tests {
pool.execute(setup).await.unwrap();

let queries = vec![
// format!("alter table instruments drop column {}", CURSOR_POS),
// format!(
// "alter table instruments drop column if exists {}",
// CURSOR_POS
// ),
format!("alter table instruments drop column {}", CURSOR_POS),
format!(
"alter table instruments drop column if exists {}",
CURSOR_POS
),
format!(
"alter table instruments alter column {} set default",
CURSOR_POS
),
// format!("alter table instruments alter {} set default", CURSOR_POS),
// format!("alter table instruments alter column {}", CURSOR_POS),
// format!("alter table instruments rename {} to new_col", CURSOR_POS),
// format!(
// "alter table instruments rename column {} to new_col",
// CURSOR_POS
// ),
format!("alter table instruments alter {} set default", CURSOR_POS),
format!("alter table instruments alter column {}", CURSOR_POS),
format!("alter table instruments alter {}", CURSOR_POS),
format!("alter table instruments rename {} to new_col", CURSOR_POS),
format!(
"alter table instruments rename column {} to new_col",
CURSOR_POS
),
];

for query in queries {
Expand Down
10 changes: 8 additions & 2 deletions crates/pgt_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ impl CompletionFilter<'_> {
WrappingClause::Select
| WrappingClause::Update
| WrappingClause::Delete
| WrappingClause::DropColumn
| WrappingClause::AlterColumn => true,
| WrappingClause::DropColumn => true,

WrappingClause::RenameColumn => ctx
.before_cursor_matches_kind(&["keyword_rename", "keyword_column"]),

WrappingClause::AlterColumn => {
ctx.before_cursor_matches_kind(&["keyword_alter", "keyword_column"])
}

// We can complete columns in JOIN cluases, but only if we are after the
// ON node in the "ON u.id = posts.user_id" part.
Expand Down