Skip to content

Commit 37a7370

Browse files
column definition does not include known columns
1 parent 3f610c1 commit 37a7370

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

crates/pgt_completions/src/relevance/filtering.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ impl<'a> From<CompletionRelevanceData<'a>> for CompletionFilter<'a> {
1717
impl CompletionFilter<'_> {
1818
pub fn is_relevant(&self, ctx: &TreesitterContext) -> Option<()> {
1919
self.completable_context(ctx)?;
20-
self.check_clause(ctx)?;
20+
21+
self.check_node_type(ctx)
22+
// we want to rely on treesitter more, so checking the clause is a fallback
23+
.or_else(|| self.check_clause(ctx))?;
24+
2125
self.check_invocation(ctx)?;
2226
self.check_mentioned_schema_or_alias(ctx)?;
2327

@@ -88,6 +92,17 @@ impl CompletionFilter<'_> {
8892
Some(())
8993
}
9094

95+
fn check_node_type(&self, ctx: &TreesitterContext) -> Option<()> {
96+
let kind = ctx.node_under_cursor.as_ref().map(|n| n.kind())?;
97+
98+
let is_allowed = match kind {
99+
"column_identifier" => matches!(self.data, CompletionRelevanceData::Column(_)),
100+
_ => false,
101+
};
102+
103+
if is_allowed { Some(()) } else { None }
104+
}
105+
91106
fn check_clause(&self, ctx: &TreesitterContext) -> Option<()> {
92107
ctx.wrapping_clause_type
93108
.as_ref()

crates/pgt_treesitter_grammar/grammar.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,6 @@ module.exports = grammar({
17391739
$.add_constraint,
17401740
$.drop_constraint,
17411741
$.alter_column,
1742-
$.modify_column,
1743-
$.change_column,
17441742
$.drop_column,
17451743
$.rename_object,
17461744
$.rename_column,
@@ -1819,25 +1817,6 @@ module.exports = grammar({
18191817
)
18201818
),
18211819

1822-
modify_column: ($) =>
1823-
seq(
1824-
$.keyword_modify,
1825-
optional($.keyword_column),
1826-
optional($._if_exists),
1827-
$.column_definition,
1828-
optional($.column_position)
1829-
),
1830-
1831-
change_column: ($) =>
1832-
seq(
1833-
$.keyword_change,
1834-
optional($.keyword_column),
1835-
optional($._if_exists),
1836-
$.column_identifier,
1837-
$.column_definition,
1838-
optional($.column_position)
1839-
),
1840-
18411820
column_position: ($) =>
18421821
choice($.keyword_first, seq($.keyword_after, $.column_identifier)),
18431822

@@ -2640,7 +2619,7 @@ module.exports = grammar({
26402619

26412620
column_definition: ($) =>
26422621
seq(
2643-
field("name", $._column),
2622+
$.any_identifier,
26442623
field("type", $.type),
26452624
repeat($._column_constraint)
26462625
),

0 commit comments

Comments
 (0)