diff --git a/crates/squawk_ide/src/classify.rs b/crates/squawk_ide/src/classify.rs index 876396cc..75d135a9 100644 --- a/crates/squawk_ide/src/classify.rs +++ b/crates/squawk_ide/src/classify.rs @@ -500,6 +500,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option || ast::GeneratedConstraint::can_cast(ancestor.kind()) || ast::NotNullConstraint::can_cast(ancestor.kind()) { + if in_function_name { + return Some(NameRefClass::FunctionCall); + } return Some(NameRefClass::ConstraintColumn); } if in_column_list @@ -513,6 +516,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option || in_constraint_where_clause) && ast::ExcludeConstraint::can_cast(ancestor.kind()) { + if in_function_name { + return Some(NameRefClass::FunctionCall); + } return Some(NameRefClass::ConstraintColumn); } if ast::LikeClause::can_cast(ancestor.kind()) { @@ -541,6 +547,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option } if ast::CreateIndex::can_cast(ancestor.kind()) { if in_partition_item { + if in_function_name { + return Some(NameRefClass::FunctionCall); + } return Some(NameRefClass::CreateIndexColumn); } return Some(NameRefClass::Table); @@ -562,6 +571,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option return Some(NameRefClass::FunctionCall); } if in_partition_item && ast::CreateTableLike::can_cast(ancestor.kind()) { + if in_function_name { + return Some(NameRefClass::FunctionCall); + } return Some(NameRefClass::ConstraintColumn); } if is_special_fn(ancestor.kind()) { diff --git a/crates/squawk_ide/src/goto_definition.rs b/crates/squawk_ide/src/goto_definition.rs index 98a85e4e..1dd07035 100644 --- a/crates/squawk_ide/src/goto_definition.rs +++ b/crates/squawk_ide/src/goto_definition.rs @@ -1437,6 +1437,85 @@ create table t ( "); } + #[test] + fn goto_generated_column_function_call() { + assert_snapshot!(goto(" +create function pg_catalog.lower(text) returns text + language internal; + +create table articles ( + id serial primary key, + title text not null, + body text not null, + title_lower text generated always as ( + lower$0(title) + ) stored +); +"), @r" + ╭▸ + 2 │ create function pg_catalog.lower(text) returns text + │ ───── 2. destination + ‡ + 10 │ lower(title) + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_index_expr_function_call() { + assert_snapshot!(goto(" +create function lower(text) returns text language internal; +create table articles ( + id serial primary key, + title text not null +); +create index on articles (lower$0(title)); +"), @r" + ╭▸ + 2 │ create function lower(text) returns text language internal; + │ ───── 2. destination + ‡ + 7 │ create index on articles (lower(title)); + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_exclude_constraint_expr_function_call() { + assert_snapshot!(goto(" +create function lower(text) returns text language internal; +create table articles ( + title text not null, + exclude using btree (lower$0(title) with =) +); +"), @r" + ╭▸ + 2 │ create function lower(text) returns text language internal; + │ ───── 2. destination + ‡ + 5 │ exclude using btree (lower(title) with =) + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_partition_by_expr_function_call() { + assert_snapshot!(goto(" +create function lower(text) returns text language internal; +create table articles ( + id serial primary key, + title text not null +) partition by range (lower$0(title)); +"), @r" + ╭▸ + 2 │ create function lower(text) returns text language internal; + │ ───── 2. destination + ‡ + 6 │ ) partition by range (lower(title)); + ╰╴ ─ 1. source + "); + } + #[test] fn goto_table_check_constraint_column() { assert_snapshot!(goto("