Skip to content

Commit 5f9d0d2

Browse files
authored
ide: better goto def support for types (#811)
1 parent a06ec07 commit 5f9d0d2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

β€Žcrates/squawk_ide/src/classify.rsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
143143
if ast::PathType::can_cast(ancestor.kind()) || ast::ExprType::can_cast(ancestor.kind()) {
144144
in_type = true;
145145
}
146+
if in_type {
147+
return Some(NameRefClass::TypeReference);
148+
}
146149
if ast::DropTable::can_cast(ancestor.kind()) {
147150
return Some(NameRefClass::DropTable);
148151
}

β€Žcrates/squawk_ide/src/goto_definition.rsβ€Ž

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,62 @@ drop type person$0;
443443
");
444444
}
445445

446+
#[test]
447+
fn goto_create_table_type_reference() {
448+
assert_snapshot!(goto("
449+
create type person_info as (name text, email text);
450+
create table user(id int, member person_info$0);
451+
"), @r"
452+
β•­β–Έ
453+
2 β”‚ create type person_info as (name text, email text);
454+
β”‚ ─────────── 2. destination
455+
3 β”‚ create table user(id int, member person_info);
456+
β•°β•΄ ─ 1. source
457+
");
458+
}
459+
460+
#[test]
461+
fn goto_create_table_type_reference_enum() {
462+
assert_snapshot!(goto("
463+
create type mood as enum ('sad', 'ok', 'happy');
464+
create table users(id int, mood mood$0);
465+
"), @r"
466+
β•­β–Έ
467+
2 β”‚ create type mood as enum ('sad', 'ok', 'happy');
468+
β”‚ ──── 2. destination
469+
3 β”‚ create table users(id int, mood mood);
470+
β•°β•΄ ─ 1. source
471+
");
472+
}
473+
474+
#[test]
475+
fn goto_create_table_type_reference_range() {
476+
assert_snapshot!(goto("
477+
create type int4_range as range (subtype = int4);
478+
create table metrics(id int, span int4_range$0);
479+
"), @r"
480+
β•­β–Έ
481+
2 β”‚ create type int4_range as range (subtype = int4);
482+
β”‚ ────────── 2. destination
483+
3 β”‚ create table metrics(id int, span int4_range);
484+
β•°β•΄ ─ 1. source
485+
");
486+
}
487+
488+
#[test]
489+
fn goto_create_table_type_reference_input_output() {
490+
assert_snapshot!(goto("
491+
create type myint (input = myintin, output = myintout, like = int4);
492+
create table data(id int, value myint$0);
493+
"), @r"
494+
β•­β–Έ
495+
2 β”‚ create type myint (input = myintin, output = myintout, like = int4);
496+
β”‚ ───── 2. destination
497+
3 β”‚ create table data(id int, value myint);
498+
β•°β•΄ ─ 1. source
499+
");
500+
}
501+
446502
#[test]
447503
fn goto_composite_type_field() {
448504
assert_snapshot!(goto("

0 commit comments

Comments
Β (0)