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
156 changes: 156 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,162 @@ select x::public.baz$0;
");
}

#[test]
fn goto_cast_bigint_falls_back_to_int8() {
assert_snapshot!(goto("
create type pg_catalog.int8;
select 1::bigint$0;
"), @r"
╭▸
2 │ create type pg_catalog.int8;
│ ──── 2. destination
3 │ select 1::bigint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_bigint_prefers_user_type() {
assert_snapshot!(goto("
create type bigint;
create type pg_catalog.int8;
select 1::bigint$0;
"), @r"
╭▸
2 │ create type bigint;
│ ────── 2. destination
3 │ create type pg_catalog.int8;
4 │ select 1::bigint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_smallserial_falls_back_to_int2() {
assert_snapshot!(goto("
create type pg_catalog.int2;
select 1::smallserial$0;
"), @r"
╭▸
2 │ create type pg_catalog.int2;
│ ──── 2. destination
3 │ select 1::smallserial;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_serial2_falls_back_to_int2() {
assert_snapshot!(goto("
create type pg_catalog.int2;
select 1::serial2$0;
"), @r"
╭▸
2 │ create type pg_catalog.int2;
│ ──── 2. destination
3 │ select 1::serial2;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_serial_falls_back_to_int4() {
assert_snapshot!(goto("
create type pg_catalog.int4;
select 1::serial$0;
"), @r"
╭▸
2 │ create type pg_catalog.int4;
│ ──── 2. destination
3 │ select 1::serial;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_serial4_falls_back_to_int4() {
assert_snapshot!(goto("
create type pg_catalog.int4;
select 1::serial4$0;
"), @r"
╭▸
2 │ create type pg_catalog.int4;
│ ──── 2. destination
3 │ select 1::serial4;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_bigserial_falls_back_to_int8() {
assert_snapshot!(goto("
create type pg_catalog.int8;
select 1::bigserial$0;
"), @r"
╭▸
2 │ create type pg_catalog.int8;
│ ──── 2. destination
3 │ select 1::bigserial;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_serial8_falls_back_to_int8() {
assert_snapshot!(goto("
create type pg_catalog.int8;
select 1::serial8$0;
"), @r"
╭▸
2 │ create type pg_catalog.int8;
│ ──── 2. destination
3 │ select 1::serial8;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_int_falls_back_to_int4() {
assert_snapshot!(goto("
create type pg_catalog.int4;
select 1::int$0;
"), @r"
╭▸
2 │ create type pg_catalog.int4;
│ ──── 2. destination
3 │ select 1::int;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_integer_falls_back_to_int4() {
assert_snapshot!(goto("
create type pg_catalog.int4;
select 1::integer$0;
"), @r"
╭▸
2 │ create type pg_catalog.int4;
│ ──── 2. destination
3 │ select 1::integer;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_smallint_falls_back_to_int2() {
assert_snapshot!(goto("
create type pg_catalog.int2;
select 1::smallint$0;
"), @r"
╭▸
2 │ create type pg_catalog.int2;
│ ──── 2. destination
3 │ select 1::smallint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_composite_type() {
assert_snapshot!(goto("
Expand Down
21 changes: 20 additions & 1 deletion crates/squawk_ide/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,26 @@ fn resolve_type_name_ptr(
schema: &Option<Schema>,
position: TextSize,
) -> Option<SyntaxNodePtr> {
binder.lookup_with(type_name, SymbolKind::Type, position, schema)
if let Some(ptr) = binder.lookup_with(type_name, SymbolKind::Type, position, schema) {
return Some(ptr);
}

if schema.is_none()
&& let Some(fallback_name) = fallback_type_alias(type_name)
{
return binder.lookup_with(&fallback_name, SymbolKind::Type, position, &None);
}

None
}

fn fallback_type_alias(type_name: &Name) -> Option<Name> {
match type_name.0.as_str() {
"bigint" | "bigserial" | "serial8" => Some(Name::from_string("int8")),
"int" | "integer" | "serial" | "serial4" => Some(Name::from_string("int4")),
"smallint" | "smallserial" | "serial2" => Some(Name::from_string("int2")),
_ => None,
}
}

fn resolve_view_name_ptr(
Expand Down
Loading