Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion crates/pgt_completions/src/providers/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {
QueryWithCursorPosition::cursor_marker()
),
format!(
"revoke all on table userse from owner, {}",
"revoke all on table users from owner, {}",
QueryWithCursorPosition::cursor_marker()
),
];
Expand Down
27 changes: 24 additions & 3 deletions crates/pgt_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ impl CompletionFilter<'_> {
CompletionRelevanceData::Table(_) => match clause {
WrappingClause::From | WrappingClause::Update => true,

WrappingClause::RevokeStatement | WrappingClause::GrantStatement => ctx
.matches_ancestor_history(&["grantable_on_table", "object_reference"]),

WrappingClause::Join { on_node: None } => true,
WrappingClause::Join { on_node: Some(on) } => ctx
.node_under_cursor
Expand Down Expand Up @@ -202,6 +205,14 @@ impl CompletionFilter<'_> {
| WrappingClause::Update
| WrappingClause::Delete => true,

WrappingClause::RevokeStatement | WrappingClause::GrantStatement => {
(ctx.matches_ancestor_history(&[
"grantable_on_table",
"object_reference",
]) && ctx.schema_or_alias_name.is_none())
|| ctx.matches_ancestor_history(&["grantable_on_all"])
}

WrappingClause::Where => {
ctx.before_cursor_matches_kind(&["keyword_and", "keyword_where"])
}
Expand Down Expand Up @@ -238,13 +249,23 @@ impl CompletionFilter<'_> {
}

CompletionRelevanceData::Role(_) => match clause {
WrappingClause::DropRole
| WrappingClause::AlterRole
| WrappingClause::ToRoleAssignment => true,
WrappingClause::DropRole | WrappingClause::AlterRole => true,

WrappingClause::SetStatement => ctx
.before_cursor_matches_kind(&["keyword_role", "keyword_authorization"]),

WrappingClause::RevokeStatement | WrappingClause::GrantStatement => {
ctx.matches_ancestor_history(&["role_specification"])
|| ctx.node_under_cursor.as_ref().is_some_and(|k| {
k.kind() == "identifier"
&& ctx.before_cursor_matches_kind(&[
"keyword_grant",
"keyword_revoke",
"keyword_for",
])
})
}

WrappingClause::AlterPolicy | WrappingClause::CreatePolicy => {
ctx.before_cursor_matches_kind(&["keyword_to"])
&& ctx.matches_ancestor_history(&["policy_to_role"])
Expand Down
23 changes: 16 additions & 7 deletions crates/pgt_hover/src/hovered_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ impl HoveredNode {
let under_cursor = ctx.node_under_cursor.as_ref()?;

match under_cursor.kind() {
"identifier" if ctx.matches_ancestor_history(&["relation", "object_reference"]) => {
"identifier"
if ctx.matches_ancestor_history(&["relation", "object_reference"])
|| ctx
.matches_ancestor_history(&["grantable_on_table", "object_reference"]) =>
{
let num_sibs = ctx.num_siblings();
if ctx.node_under_cursor_is_nth_child(1) && num_sibs > 0 {
return Some(HoveredNode::Schema(NodeIdentification::Name(node_content)));
Expand Down Expand Up @@ -93,7 +97,16 @@ impl HoveredNode {
}
}

"identifier" if ctx.matches_one_of_ancestors(&["alter_role", "policy_to_role"]) => {
"identifier"
if ctx.matches_one_of_ancestors(&[
"alter_role",
"policy_to_role",
"role_specification",
]) || ctx.before_cursor_matches_kind(&["keyword_revoke"]) =>
{
Some(HoveredNode::Role(NodeIdentification::Name(node_content)))
}
"grant_role" | "policy_role" => {
Some(HoveredNode::Role(NodeIdentification::Name(node_content)))
}

Expand Down Expand Up @@ -127,16 +140,12 @@ impl HoveredNode {
}
}

"revoke_role" | "grant_role" | "policy_role" => {
Some(HoveredNode::Role(NodeIdentification::Name(node_content)))
}

// quoted columns
"literal" if ctx.matches_ancestor_history(&["select_expression", "term"]) => {
Some(HoveredNode::Column(NodeIdentification::Name(node_content)))
}

"revoke_table" | "grant_table" => {
"grant_table" => {
if let Some(schema) = ctx.schema_or_alias_name.as_ref() {
Some(HoveredNode::Table(NodeIdentification::SchemaAndName((
schema.clone(),
Expand Down
6 changes: 0 additions & 6 deletions crates/pgt_treesitter/src/context/base_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ impl TokenNavigator {
.is_some_and(|c| options.contains(&c.get_word_without_quotes().as_str()))
}

pub(crate) fn prev_matches(&self, options: &[&str]) -> bool {
self.previous_token
.as_ref()
.is_some_and(|t| options.contains(&t.get_word_without_quotes().as_str()))
}

pub(crate) fn advance(&mut self) -> Option<WordWithIndex> {
// we can't peek back n an iterator, so we'll have to keep track manually.
self.previous_token = self.current_token.take();
Expand Down
Loading