Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 20 additions & 1 deletion crates/pgt_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ impl<'a> From<CompletionRelevanceData<'a>> for CompletionFilter<'a> {
impl CompletionFilter<'_> {
pub fn is_relevant(&self, ctx: &TreesitterContext) -> Option<()> {
self.completable_context(ctx)?;
self.check_clause(ctx)?;

self.check_node_type(ctx)
// we want to rely on treesitter more, so checking the clause is a fallback
.or_else(|| self.check_clause(ctx))?;

self.check_invocation(ctx)?;
self.check_mentioned_schema_or_alias(ctx)?;

Expand Down Expand Up @@ -88,6 +92,21 @@ impl CompletionFilter<'_> {
Some(())
}

fn check_node_type(&self, ctx: &TreesitterContext) -> Option<()> {
let kind = ctx.node_under_cursor.as_ref().map(|n| n.kind())?;

let is_allowed = match kind {
"column_identifier" => {
matches!(self.data, CompletionRelevanceData::Column(_))
&& !ctx.matches_ancestor_history(&["insert_values", "field"])
&& !ctx.node_under_cursor_is_within_field_name("binary_expr_right")
}
_ => false,
};

if is_allowed { Some(()) } else { None }
}

fn check_clause(&self, ctx: &TreesitterContext) -> Option<()> {
ctx.wrapping_clause_type
.as_ref()
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 @@ -73,7 +73,7 @@ impl HoveredNode {
}
}

"any_identifier" if ctx.matches_ancestor_history(&["field"]) => {
"column_identifier" => {
if let Some(table_or_alias) = ctx.schema_or_alias_name.as_ref() {
Some(HoveredNode::Column(NodeIdentification::SchemaAndName((
table_or_alias.clone(),
Expand Down
3 changes: 1 addition & 2 deletions crates/pgt_treesitter/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,7 @@ impl<'a> TreesitterContext<'a> {
// `node.child_by_field_id(..)` does not work as expected
let mut on_node = None;
for child in node.children(cursor) {
// 28 is the id for "keyword_on"
if child.kind_id() == 28 {
if child.kind() == "keyword_on" {
on_node = Some(child);
}
}
Expand Down
10 changes: 2 additions & 8 deletions crates/pgt_treesitter/src/queries/insert_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ use super::QueryTryFrom;

static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
static QUERY_STR: &str = r#"
(insert
(object_reference)
(list
"("?
(column) @column
","?
")"?
)
(insert_columns
(column_identifier) @column
)
"#;
tree_sitter::Query::new(&pgt_treesitter_grammar::LANGUAGE.into(), QUERY_STR)
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_treesitter/src/queries/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
[
(field
(field_qualifier)?
(any_identifier)
(column_identifier)
) @reference

(parameter) @parameter
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_treesitter/src/queries/select_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
(object_reference) @alias
"."
)?
(any_identifier) @column
(column_identifier) @column
)
)
","?
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_treesitter/src/queries/where_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
(object_reference) @alias
"."
)?
(any_identifier) @column
(column_identifier) @column
)
)
)
Expand Down
Loading