Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c0ed76c
ok?
juleswritescode Sep 19, 2025
fd0d198
ok?
juleswritescode Sep 26, 2025
d4ece2e
testie testie
juleswritescode Sep 26, 2025
dae4b9a
ok so far
juleswritescode Sep 26, 2025
c35c596
Merge branch 'main' of https://github.com/supabase-community/postgres…
juleswritescode Sep 26, 2025
2823ca0
ack
juleswritescode Sep 26, 2025
a2ae8f0
OKJ
juleswritescode Sep 26, 2025
802a0d2
install em toolz
juleswritescode Sep 26, 2025
934a44b
oke then
juleswritescode Sep 26, 2025
e3b5e30
amazing!
juleswritescode Sep 27, 2025
79cb776
Merge branch 'main' of https://github.com/supabase-community/postgres…
juleswritescode Sep 27, 2025
b472454
remove unneeded
juleswritescode Sep 27, 2025
48ade40
better api
juleswritescode Sep 27, 2025
38741b4
almost there…
juleswritescode Sep 27, 2025
7e63009
ok?
juleswritescode Sep 27, 2025
4e0ef81
ack ack
juleswritescode Sep 27, 2025
5f1d273
comment
juleswritescode Sep 27, 2025
d503333
Update crates/pgt_text_size/src/text_range_replacement.rs
juleswritescode Sep 27, 2025
bb9bfba
ok
juleswritescode Sep 27, 2025
3eb2f61
simple
juleswritescode Sep 27, 2025
79109a0
Merge branch 'main' into feat/longer-type-replacements
juleswritescode Oct 3, 2025
52cd007
intermediary
juleswritescode Oct 3, 2025
00fe8ef
resolve conflicts
juleswritescode Oct 3, 2025
e669094
ok then…
juleswritescode Oct 3, 2025
0cf105e
its not dead
juleswritescode Oct 3, 2025
7c7549c
no more spaces
juleswritescode Oct 10, 2025
53e2429
ok
juleswritescode Oct 10, 2025
41405a6
we got em tests
juleswritescode Oct 10, 2025
8cfef05
Update crates/pgt_typecheck/tests/diagnostics.rs
juleswritescode Oct 10, 2025
f653ea5
Merge branch 'main' into feat/shorter-type-replacements
juleswritescode Oct 10, 2025
6ec8115
better
juleswritescode Oct 10, 2025
1ddbc5e
Merge branch 'feat/shorter-type-replacements' of https://github.com/s…
juleswritescode Oct 10, 2025
36345c6
ack
juleswritescode Oct 10, 2025
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 so far
  • Loading branch information
juleswritescode committed Sep 26, 2025
commit dae4b9a01eb6c15f82d84d348d64629c01514b23
15 changes: 15 additions & 0 deletions crates/pgt_completions/src/providers/policies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ mod tests {

pool.execute(setup).await.unwrap();

assert_complete_results(
format!(
"alter policy \"{}",
QueryWithCursorPosition::cursor_marker()
)
.as_str(),
vec![
CompletionAssertion::Label("read for public users disallowed".into()),
CompletionAssertion::Label("write for public users allowed".into()),
],
None,
&pool,
)
.await;

assert_complete_results(
format!(
"alter policy \"{}\" on private.users;",
Expand Down
5 changes: 3 additions & 2 deletions crates/pgt_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ impl CompletionFilter<'_> {
matches!(
clause,
// not CREATE – there can't be existing policies.
WrappingClause::DropPolicy | WrappingClause::AlterPolicy
)
WrappingClause::AlterPolicy | WrappingClause::DropPolicy
) && ctx.before_cursor_matches_kind(&["keyword_policy", "keyword_exists"])
}

CompletionRelevanceData::Role(_) => match clause {
Expand All @@ -247,6 +247,7 @@ impl CompletionFilter<'_> {

WrappingClause::AlterPolicy | WrappingClause::CreatePolicy => {
ctx.before_cursor_matches_kind(&["keyword_to"])
&& ctx.matches_ancestor_history(&["policy_to_role"])
}

_ => false,
Expand Down
3 changes: 3 additions & 0 deletions crates/pgt_completions/src/relevance/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ impl CompletionScore<'_> {
WrappingClause::Join { .. } if !has_mentioned_schema => 15,
WrappingClause::Update if !has_mentioned_schema => 15,
WrappingClause::Delete if !has_mentioned_schema => 15,
WrappingClause::AlterPolicy if !has_mentioned_schema => 15,
WrappingClause::DropPolicy if !has_mentioned_schema => 15,
WrappingClause::CreatePolicy if !has_mentioned_schema => 15,
_ => -50,
},
CompletionRelevanceData::Policy(_) => match clause_type {
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_hover/src/hovered_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl HoveredNode {
)))
}
}
"identifier" if ctx.matches_ancestor_history(&["alter_role"]) => {
"identifier" if ctx.matches_one_of_ancestors(&["alter_role", "policy_to_role"]) => {
Some(HoveredNode::Role(NodeIdentification::Name(node_content)))
}

Expand Down
16 changes: 16 additions & 0 deletions crates/pgt_treesitter/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,22 @@ impl<'a> TreesitterContext<'a> {
})
}

/// Verifies whether the node_under_cursor has the passed in ancestors in the right order.
/// Note that you need to pass in the ancestors in the order as they would appear in the tree:
///
/// If the tree shows `relation > object_reference > identifier` and the "identifier" is a leaf node,
/// you need to pass `&["relation", "object_reference"]`.
pub fn matches_one_of_ancestors(&self, expected_ancestors: &[&'static str]) -> bool {
self.node_under_cursor
.as_ref()
.is_some_and(|under_cursor| match under_cursor {
NodeUnderCursor::TsNode(node) => node
.parent()
.is_some_and(|p| expected_ancestors.contains(&p.kind())),
NodeUnderCursor::CustomNode { .. } => false,
})
}

/// Checks whether the Node under the cursor is the nth child of the parent.
///
/// ```
Expand Down
79 changes: 38 additions & 41 deletions crates/pgt_treesitter_grammar/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,59 +1034,56 @@ module.exports = grammar({
)
)
),
optional(
seq(
$.keyword_to,
comma_list(
choice(
$.identifier,
$.keyword_public,
$.keyword_current_user,
$.keyword_current_role
),
true
)
)
),
optional($.policy_to_role),
optional($.check_or_using_clause)
),

alter_policy: ($) =>
seq(
$.keyword_alter,
$.keyword_policy,
$.identifier,
$.keyword_on,
$.object_reference,
choice(
seq($.keyword_rename, $.keyword_to, $.identifier),
seq($.keyword_alter, $.keyword_policy, $.identifier),
optional(
seq(
optional(
seq(
$.keyword_to,
choice(
$.identifier,
$.keyword_public,
$.keyword_current_role,
$.keyword_current_user,
$.keyword_session_user
)
)
),
optional($.check_or_using_clause)
$.keyword_on,
$.object_reference,
choice(
seq($.keyword_rename, $.keyword_to, $.identifier),
$.policy_to_role,
optional($.check_or_using_clause)
)
)
)
),

policy_to_role: ($) =>
seq(
$.keyword_to,
comma_list(
choice(
$.identifier,
$.keyword_public,
$.keyword_current_user,
$.keyword_current_role,
$.keyword_session_user
),
true
)
),

drop_policy: ($) =>
seq(
$.keyword_drop,
$.keyword_policy,
optional($._if_exists),
$.identifier,
$.keyword_on,
$.object_reference,
optional(choice($.keyword_cascade, $.keyword_restrict))
seq(
$.keyword_drop,
$.keyword_policy,
optional($._if_exists),
$.identifier
),
optional(
seq(
$.keyword_on,
$.object_reference,
optional(choice($.keyword_cascade, $.keyword_restrict))
)
)
),

check_or_using_clause: ($) =>
Expand Down
Loading
Loading