diff --git a/crates/squawk_ide/src/column_name.rs b/crates/squawk_ide/src/column_name.rs index 0f812320..672b3883 100644 --- a/crates/squawk_ide/src/column_name.rs +++ b/crates/squawk_ide/src/column_name.rs @@ -168,6 +168,18 @@ fn name_from_name_ref(name_ref: ast::NameRef, in_type: bool) -> Option<(ColumnNa name_ref.syntax().clone(), )); } + SyntaxKind::BOOLEAN_KW => { + return Some(( + ColumnName::Column("bool".to_owned()), + name_ref.syntax().clone(), + )); + } + SyntaxKind::DECIMAL_KW => { + return Some(( + ColumnName::Column("numeric".to_owned()), + name_ref.syntax().clone(), + )); + } SyntaxKind::INT_KW | SyntaxKind::INTEGER_KW => { return Some(( ColumnName::Column("int4".to_owned()), @@ -569,6 +581,8 @@ fn examples() { assert_snapshot!(name("col_name::text"), @"col_name"); assert_snapshot!(name("col_name::int::text"), @"col_name"); assert_snapshot!(name("'1'::bigint"), @"int8"); + assert_snapshot!(name("'1'::decimal"), @"numeric"); + assert_snapshot!(name("'1'::boolean"), @"bool"); assert_snapshot!(name("'1'::int"), @"int4"); assert_snapshot!(name("'1'::smallint"), @"int2"); assert_snapshot!(name("'{{1, 2}, {3, 4}}'::bigint[][]"), @"int8"); diff --git a/crates/squawk_ide/src/goto_definition.rs b/crates/squawk_ide/src/goto_definition.rs index e62c53ca..11acd519 100644 --- a/crates/squawk_ide/src/goto_definition.rs +++ b/crates/squawk_ide/src/goto_definition.rs @@ -2882,6 +2882,48 @@ select '{[1.234, 5.678]}'::floatmultirangerange$0; "); } + #[test] + fn goto_cast_boolean_falls_back_to_bool() { + assert_snapshot!(goto(" +create type pg_catalog.bool; +select '1'::boolean$0; +"), @" + ╭▸ + 2 │ create type pg_catalog.bool; + │ ──── 2. destination + 3 │ select '1'::boolean; + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_cast_decimal_falls_back_to_numeric() { + assert_snapshot!(goto(" +create type pg_catalog.numeric; +select 1::decimal$0(10, 2); +"), @" + ╭▸ + 2 │ create type pg_catalog.numeric; + │ ─────── 2. destination + 3 │ select 1::decimal(10, 2); + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_cast_float_falls_back_to_float8() { + assert_snapshot!(goto(" +create type pg_catalog.float8; +select 1::float$0; +"), @" + ╭▸ + 2 │ create type pg_catalog.float8; + │ ────── 2. destination + 3 │ select 1::float; + ╰╴ ─ 1. source + "); + } + #[test] fn goto_cast_bigint_falls_back_to_int8() { assert_snapshot!(goto(" @@ -2896,6 +2938,20 @@ select 1::bigint$0; "); } + #[test] + fn goto_cast_real_falls_back_to_float4() { + assert_snapshot!(goto(" +create type pg_catalog.float4; +select 1::real$0; +"), @" + ╭▸ + 2 │ create type pg_catalog.float4; + │ ────── 2. destination + 3 │ select 1::real; + ╰╴ ─ 1. source + "); + } + #[test] fn goto_cast_bigint_prefers_user_type() { assert_snapshot!(goto(" diff --git a/crates/squawk_ide/src/resolve.rs b/crates/squawk_ide/src/resolve.rs index 31ca6d2d..58be843a 100644 --- a/crates/squawk_ide/src/resolve.rs +++ b/crates/squawk_ide/src/resolve.rs @@ -607,7 +607,11 @@ fn type_name_and_schema_from_type(ty: &ast::Type) -> Option<(Name, Option Option { match type_name.0.as_str() { "bigint" | "bigserial" | "serial8" => Some(Name::from_string("int8")), + "boolean" => Some(Name::from_string("bool")), + "decimal" => Some(Name::from_string("numeric")), + "float" => Some(Name::from_string("float8")), "int" | "integer" | "serial" | "serial4" => Some(Name::from_string("int4")), + "real" => Some(Name::from_string("float4")), "smallint" | "smallserial" | "serial2" => Some(Name::from_string("int2")), _ => None, }