Skip to content

Commit 678c5f5

Browse files
add filtering
1 parent 2f27bee commit 678c5f5

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

crates/pgt_completions/src/relevance/filtering.rs

+12-38
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl CompletionFilter<'_> {
1818
self.completable_context(ctx)?;
1919
self.check_clause(ctx)?;
2020
self.check_invocation(ctx)?;
21-
self.check_mentioned_schema(ctx)?;
21+
self.check_mentioned_schema_or_alias(ctx)?;
2222

2323
Some(())
2424
}
@@ -86,54 +86,28 @@ impl CompletionFilter<'_> {
8686
Some(())
8787
}
8888

89-
fn check_mentioned_schema(&self, ctx: &CompletionContext) -> Option<()> {
89+
fn check_mentioned_schema_or_alias(&self, ctx: &CompletionContext) -> Option<()> {
9090
if ctx.schema_or_alias_name.is_none() {
9191
return Some(());
9292
}
9393

94-
let name = ctx.schema_or_alias_name.as_ref().unwrap();
94+
let schema_or_alias = ctx.schema_or_alias_name.as_ref().unwrap();
9595

96-
let does_not_match = match self.data {
97-
CompletionRelevanceData::Table(table) => &table.schema != name,
98-
CompletionRelevanceData::Function(f) => &f.schema != name,
99-
CompletionRelevanceData::Column(_) => {
100-
// columns belong to tables, not schemas
101-
true
102-
}
103-
CompletionRelevanceData::Schema(_) => {
104-
// we should never allow schema suggestions if there already was one.
105-
true
106-
}
107-
};
96+
let matches = match self.data {
97+
CompletionRelevanceData::Table(table) => &table.schema == schema_or_alias,
98+
CompletionRelevanceData::Function(f) => &f.schema == schema_or_alias,
99+
CompletionRelevanceData::Column(col) => ctx
100+
.mentioned_table_aliases
101+
.get(schema_or_alias)
102+
.is_some_and(|t| t == &col.table_name),
108103

109-
if does_not_match {
110-
return None;
111-
}
112-
113-
Some(())
114-
}
115-
116-
fn check_mentioned_alias(&self, ctx: &CompletionContext) -> Option<()> {
117-
if ctx.schema_or_alias_name.is_none() {
118-
return Some(());
119-
}
120-
121-
let name = ctx.schema_or_alias_name.as_ref().unwrap();
122-
123-
let does_not_match = match self.data {
124-
CompletionRelevanceData::Table(table) => &table.schema != name,
125-
CompletionRelevanceData::Function(f) => &f.schema != name,
126-
CompletionRelevanceData::Column(_) => {
127-
// columns belong to tables, not schemas
128-
true
129-
}
130104
CompletionRelevanceData::Schema(_) => {
131105
// we should never allow schema suggestions if there already was one.
132-
true
106+
false
133107
}
134108
};
135109

136-
if does_not_match {
110+
if !matches {
137111
return None;
138112
}
139113

0 commit comments

Comments
 (0)