Skip to content

Commit 2b2b637

Browse files
rename, add grant grammar
1 parent c34dd00 commit 2b2b637

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

crates/pgt_completions/src/relevance/filtering.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ impl CompletionFilter<'_> {
9999
CompletionRelevanceData::Table(_) => match clause {
100100
WrappingClause::From | WrappingClause::Update => true,
101101

102-
WrappingClause::RevokeStatement => {
103-
ctx.matches_ancestor_history(&["revoke_on_table", "object_reference"])
104-
}
102+
WrappingClause::RevokeStatement => ctx
103+
.matches_ancestor_history(&["grantable_on_table", "object_reference"]),
105104

106105
WrappingClause::Join { on_node: None } => true,
107106
WrappingClause::Join { on_node: Some(on) } => ctx
@@ -207,9 +206,11 @@ impl CompletionFilter<'_> {
207206
| WrappingClause::Delete => true,
208207

209208
WrappingClause::RevokeStatement => {
210-
(ctx.matches_ancestor_history(&["revoke_on_table", "object_reference"])
211-
&& ctx.schema_or_alias_name.is_none())
212-
|| ctx.matches_ancestor_history(&["revoke_on_all"])
209+
(ctx.matches_ancestor_history(&[
210+
"grantable_on_table",
211+
"object_reference",
212+
]) && ctx.schema_or_alias_name.is_none())
213+
|| ctx.matches_ancestor_history(&["grantable_on_all"])
213214
}
214215

215216
WrappingClause::Where => {

crates/pgt_hover/src/hovered_node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ impl HoveredNode {
3434
match under_cursor.kind() {
3535
"identifier"
3636
if ctx.matches_ancestor_history(&["relation", "object_reference"])
37-
|| ctx.matches_ancestor_history(&["revoke_on_table", "object_reference"]) =>
37+
|| ctx
38+
.matches_ancestor_history(&["grantable_on_table", "object_reference"]) =>
3839
{
3940
let num_sibs = ctx.num_siblings();
4041
if ctx.node_under_cursor_is_nth_child(1) && num_sibs > 0 {

crates/pgt_treesitter_grammar/grammar.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = grammar({
2727
[$.between_expression, $.binary_expression],
2828
[$.time],
2929
[$.timestamp],
30-
[$.revoke_on_function, $.revoke_on_table],
30+
[$.grantable_on_function, $.grantable_on_table],
3131
],
3232

3333
precedences: ($) => [
@@ -3118,6 +3118,16 @@ module.exports = grammar({
31183118

31193119
returning: ($) => seq($.keyword_returning, $.select_expression),
31203120

3121+
grant_statement: ($) =>
3122+
seq(
3123+
$.keyword_grant,
3124+
$._grantable_target_on,
3125+
$.keyword_to,
3126+
comma_list($.role_specification, true),
3127+
optional(seq($.keyword_with, $.keyword_grant, $.keyword_option)),
3128+
optional(seq($.keyword_granted, $.keyword_by, $.role_specification))
3129+
),
3130+
31213131
// todo: add support for various other revoke statements
31223132
revoke_statement: ($) =>
31233133
seq(
@@ -3134,26 +3144,33 @@ module.exports = grammar({
31343144
)
31353145
)
31363146
),
3137-
choice(
3138-
seq(
3139-
$.revoke_targets,
3140-
choice($.revoke_on_table, $.revoke_on_function, $.revoke_on_all)
3141-
),
3142-
$.identifier
3143-
),
3147+
$._grantable_target_on,
31443148
$.keyword_from,
31453149
comma_list($.role_specification, true),
31463150
optional(seq($.keyword_granted, $.keyword_by, $.role_specification)),
31473151
optional(choice($.keyword_cascade, $.keyword_restrict))
31483152
),
31493153

3150-
revoke_targets: ($) =>
3154+
_grantable_target_on: ($) =>
3155+
choice(
3156+
seq(
3157+
$.grantable_targets,
3158+
choice(
3159+
$.grantable_on_table,
3160+
$.grantable_on_function,
3161+
$.grantable_on_all
3162+
)
3163+
),
3164+
$.identifier
3165+
),
3166+
3167+
grantable_targets: ($) =>
31513168
choice(
3152-
seq($._revoke_keyword, comma_list($.identifier, false)),
3169+
seq($._grantable, comma_list($.identifier, false)),
31533170
comma_list($.identifier, true)
31543171
),
31553172

3156-
_revoke_keyword: ($) =>
3173+
_grantable: ($) =>
31573174
choice(
31583175
comma_list(
31593176
choice(
@@ -3165,14 +3182,15 @@ module.exports = grammar({
31653182
$.keyword_references,
31663183
$.keyword_trigger,
31673184
$.keyword_maintain,
3168-
$.keyword_execute
3185+
$.keyword_execute,
3186+
$.keyword_references
31693187
),
31703188
true
31713189
),
31723190
seq($.keyword_all, optional($.keyword_privileges))
31733191
),
31743192

3175-
revoke_on_function: ($) =>
3193+
grantable_on_function: ($) =>
31763194
seq(
31773195
$.keyword_on,
31783196
optional(
@@ -3184,7 +3202,7 @@ module.exports = grammar({
31843202
)
31853203
),
31863204

3187-
revoke_on_table: ($) =>
3205+
grantable_on_table: ($) =>
31883206
prec(
31893207
1,
31903208
seq(
@@ -3194,7 +3212,7 @@ module.exports = grammar({
31943212
)
31953213
),
31963214

3197-
revoke_on_all: ($) =>
3215+
grantable_on_all: ($) =>
31983216
seq(
31993217
$.keyword_on,
32003218
$.keyword_all,

0 commit comments

Comments
 (0)