diff --git a/crates/squawk_ide/src/classify.rs b/crates/squawk_ide/src/classify.rs index e19b480a..c37b9bb7 100644 --- a/crates/squawk_ide/src/classify.rs +++ b/crates/squawk_ide/src/classify.rs @@ -143,6 +143,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option if ast::PathType::can_cast(ancestor.kind()) || ast::ExprType::can_cast(ancestor.kind()) { in_type = true; } + if in_type { + return Some(NameRefClass::TypeReference); + } if ast::DropTable::can_cast(ancestor.kind()) { return Some(NameRefClass::DropTable); } diff --git a/crates/squawk_ide/src/goto_definition.rs b/crates/squawk_ide/src/goto_definition.rs index 12164dd9..417d1081 100644 --- a/crates/squawk_ide/src/goto_definition.rs +++ b/crates/squawk_ide/src/goto_definition.rs @@ -443,6 +443,62 @@ drop type person$0; "); } + #[test] + fn goto_create_table_type_reference() { + assert_snapshot!(goto(" +create type person_info as (name text, email text); +create table user(id int, member person_info$0); +"), @r" + ╭▸ + 2 │ create type person_info as (name text, email text); + │ ─────────── 2. destination + 3 │ create table user(id int, member person_info); + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_create_table_type_reference_enum() { + assert_snapshot!(goto(" +create type mood as enum ('sad', 'ok', 'happy'); +create table users(id int, mood mood$0); +"), @r" + ╭▸ + 2 │ create type mood as enum ('sad', 'ok', 'happy'); + │ ──── 2. destination + 3 │ create table users(id int, mood mood); + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_create_table_type_reference_range() { + assert_snapshot!(goto(" +create type int4_range as range (subtype = int4); +create table metrics(id int, span int4_range$0); +"), @r" + ╭▸ + 2 │ create type int4_range as range (subtype = int4); + │ ────────── 2. destination + 3 │ create table metrics(id int, span int4_range); + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_create_table_type_reference_input_output() { + assert_snapshot!(goto(" +create type myint (input = myintin, output = myintout, like = int4); +create table data(id int, value myint$0); +"), @r" + ╭▸ + 2 │ create type myint (input = myintin, output = myintout, like = int4); + │ ───── 2. destination + 3 │ create table data(id int, value myint); + ╰╴ ─ 1. source + "); + } + #[test] fn goto_composite_type_field() { assert_snapshot!(goto("