Skip to content

Commit 79fd5d5

Browse files
authored
ide: support func call syntax in select (#775)
1 parent 1a1dc1f commit 79fd5d5

File tree

3 files changed

+493
-64
lines changed

3 files changed

+493
-64
lines changed

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

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,241 @@ select myschema.foo$0();
10421042
");
10431043
}
10441044

1045+
#[test]
1046+
fn goto_function_call_style_column_access() {
1047+
assert_snapshot!(goto("
1048+
create table t(a int, b int);
1049+
select a$0(t) from t;
1050+
"), @r"
1051+
β•­β–Έ
1052+
2 β”‚ create table t(a int, b int);
1053+
β”‚ ─ 2. destination
1054+
3 β”‚ select a(t) from t;
1055+
β•°β•΄ ─ 1. source
1056+
");
1057+
}
1058+
1059+
#[test]
1060+
fn goto_function_call_style_column_access_with_function_precedence() {
1061+
assert_snapshot!(goto("
1062+
create table t(a int, b int);
1063+
create function b(t) returns int as 'select 1' LANGUAGE sql;
1064+
select b$0(t) from t;
1065+
"), @r"
1066+
β•­β–Έ
1067+
3 β”‚ create function b(t) returns int as 'select 1' LANGUAGE sql;
1068+
β”‚ ─ 2. destination
1069+
4 β”‚ select b(t) from t;
1070+
β•°β•΄ ─ 1. source
1071+
");
1072+
}
1073+
1074+
#[test]
1075+
fn goto_function_call_style_column_access_table_arg() {
1076+
assert_snapshot!(goto("
1077+
create table t(a int, b int);
1078+
select a(t$0) from t;
1079+
"), @r"
1080+
β•­β–Έ
1081+
2 β”‚ create table t(a int, b int);
1082+
β”‚ ─ 2. destination
1083+
3 β”‚ select a(t) from t;
1084+
β•°β•΄ ─ 1. source
1085+
");
1086+
}
1087+
1088+
#[test]
1089+
fn goto_function_call_style_column_access_table_arg_with_function() {
1090+
assert_snapshot!(goto("
1091+
create table t(a int, b int);
1092+
create function b(t) returns int as 'select 1' LANGUAGE sql;
1093+
select b(t$0) from t;
1094+
"), @r"
1095+
β•­β–Έ
1096+
2 β”‚ create table t(a int, b int);
1097+
β”‚ ─ 2. destination
1098+
3 β”‚ create function b(t) returns int as 'select 1' LANGUAGE sql;
1099+
4 β”‚ select b(t) from t;
1100+
β•°β•΄ ─ 1. source
1101+
");
1102+
}
1103+
1104+
#[test]
1105+
fn goto_function_call_multiple_args_not_column_access() {
1106+
goto_not_found(
1107+
"
1108+
create table t(a int, b int);
1109+
select a$0(t, 1) from t;
1110+
",
1111+
);
1112+
}
1113+
1114+
#[test]
1115+
fn goto_field_style_function_call() {
1116+
assert_snapshot!(goto("
1117+
create table t(a int);
1118+
create function b(t) returns int as 'select 1' language sql;
1119+
select t.b$0 from t;
1120+
"), @r"
1121+
β•­β–Έ
1122+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1123+
β”‚ ─ 2. destination
1124+
4 β”‚ select t.b from t;
1125+
β•°β•΄ ─ 1. source
1126+
");
1127+
}
1128+
1129+
#[test]
1130+
fn goto_field_style_function_call_column_precedence() {
1131+
assert_snapshot!(goto("
1132+
create table t(a int, b int);
1133+
create function b(t) returns int as 'select 1' language sql;
1134+
select t.b$0 from t;
1135+
"), @r"
1136+
β•­β–Έ
1137+
2 β”‚ create table t(a int, b int);
1138+
β”‚ ─ 2. destination
1139+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1140+
4 β”‚ select t.b from t;
1141+
β•°β•΄ ─ 1. source
1142+
");
1143+
}
1144+
1145+
#[test]
1146+
fn goto_field_style_function_call_table_ref() {
1147+
assert_snapshot!(goto("
1148+
create table t(a int);
1149+
create function b(t) returns int as 'select 1' language sql;
1150+
select t$0.b from t;
1151+
"), @r"
1152+
β•­β–Έ
1153+
2 β”‚ create table t(a int);
1154+
β”‚ ─ 2. destination
1155+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1156+
4 β”‚ select t.b from t;
1157+
β•°β•΄ ─ 1. source
1158+
");
1159+
}
1160+
1161+
#[test]
1162+
fn goto_function_call_style_in_where() {
1163+
assert_snapshot!(goto("
1164+
create table t(a int, b int);
1165+
select * from t where a$0(t) > 0;
1166+
"), @r"
1167+
β•­β–Έ
1168+
2 β”‚ create table t(a int, b int);
1169+
β”‚ ─ 2. destination
1170+
3 β”‚ select * from t where a(t) > 0;
1171+
β•°β•΄ ─ 1. source
1172+
");
1173+
}
1174+
1175+
#[test]
1176+
fn goto_function_call_style_in_where_function_precedence() {
1177+
assert_snapshot!(goto("
1178+
create table t(a int, b int);
1179+
create function b(t) returns int as 'select 1' language sql;
1180+
select * from t where b$0(t) > 0;
1181+
"), @r"
1182+
β•­β–Έ
1183+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1184+
β”‚ ─ 2. destination
1185+
4 β”‚ select * from t where b(t) > 0;
1186+
β•°β•΄ ─ 1. source
1187+
");
1188+
}
1189+
1190+
#[test]
1191+
fn goto_field_style_function_call_in_where() {
1192+
assert_snapshot!(goto("
1193+
create table t(a int);
1194+
create function b(t) returns int as 'select 1' language sql;
1195+
select * from t where t.b$0 > 0;
1196+
"), @r"
1197+
β•­β–Έ
1198+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1199+
β”‚ ─ 2. destination
1200+
4 β”‚ select * from t where t.b > 0;
1201+
β•°β•΄ ─ 1. source
1202+
");
1203+
}
1204+
1205+
#[test]
1206+
fn goto_field_style_in_where_column_precedence() {
1207+
assert_snapshot!(goto("
1208+
create table t(a int, b int);
1209+
create function b(t) returns int as 'select 1' language sql;
1210+
select * from t where t.b$0 > 0;
1211+
"), @r"
1212+
β•­β–Έ
1213+
2 β”‚ create table t(a int, b int);
1214+
β”‚ ─ 2. destination
1215+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1216+
4 β”‚ select * from t where t.b > 0;
1217+
β•°β•΄ ─ 1. source
1218+
");
1219+
}
1220+
1221+
#[test]
1222+
fn goto_function_call_style_in_order_by() {
1223+
assert_snapshot!(goto("
1224+
create table t(a int, b int);
1225+
create function b(t) returns int as 'select 1' language sql;
1226+
select * from t order by b$0(t);
1227+
"), @r"
1228+
β•­β–Έ
1229+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1230+
β”‚ ─ 2. destination
1231+
4 β”‚ select * from t order by b(t);
1232+
β•°β•΄ ─ 1. source
1233+
");
1234+
}
1235+
1236+
#[test]
1237+
fn goto_field_style_in_order_by() {
1238+
assert_snapshot!(goto("
1239+
create table t(a int);
1240+
create function b(t) returns int as 'select 1' language sql;
1241+
select * from t order by t.b$0;
1242+
"), @r"
1243+
β•­β–Έ
1244+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1245+
β”‚ ─ 2. destination
1246+
4 β”‚ select * from t order by t.b;
1247+
β•°β•΄ ─ 1. source
1248+
");
1249+
}
1250+
1251+
#[test]
1252+
fn goto_function_call_style_in_group_by() {
1253+
assert_snapshot!(goto("
1254+
create table t(a int, b int);
1255+
select * from t group by a$0(t);
1256+
"), @r"
1257+
β•­β–Έ
1258+
2 β”‚ create table t(a int, b int);
1259+
β”‚ ─ 2. destination
1260+
3 β”‚ select * from t group by a(t);
1261+
β•°β•΄ ─ 1. source
1262+
");
1263+
}
1264+
1265+
#[test]
1266+
fn goto_field_style_in_group_by() {
1267+
assert_snapshot!(goto("
1268+
create table t(a int);
1269+
create function b(t) returns int as 'select 1' language sql;
1270+
select * from t group by t.b$0;
1271+
"), @r"
1272+
β•­β–Έ
1273+
3 β”‚ create function b(t) returns int as 'select 1' language sql;
1274+
β”‚ ─ 2. destination
1275+
4 β”‚ select * from t group by t.b;
1276+
β•°β•΄ ─ 1. source
1277+
");
1278+
}
1279+
10451280
#[test]
10461281
fn goto_insert_table() {
10471282
assert_snapshot!(goto("

0 commit comments

Comments
Β (0)