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
11 changes: 10 additions & 1 deletion crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
.and_then(ast::FieldExpr::cast)
.is_some();

let mut in_arg_list = false;
let mut in_from_clause = false;
let mut in_on_clause = false;
let mut in_returning_clause = false;
let mut in_set_clause = false;
let mut in_where_clause = false;
let mut in_when_clause = false;
for ancestor in parent.ancestors() {
if ast::ArgList::can_cast(ancestor.kind()) {
in_arg_list = true;
}
if ast::OnClause::can_cast(ancestor.kind()) {
in_on_clause = true;
}
Expand Down Expand Up @@ -191,7 +195,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
}
}
}
if ast::Select::can_cast(ancestor.kind()) && (!in_from_clause || in_on_clause) {
if ast::Select::can_cast(ancestor.kind())
&& (!in_from_clause || in_on_clause || in_arg_list)
{
if is_function_call || is_schema_table_col {
return Some(NameRefClass::Schema);
} else {
Expand Down Expand Up @@ -607,6 +613,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
return Some(NameRefClass::SelectFunctionCall);
}
if in_from_clause && !in_on_clause {
if in_arg_list {
return Some(NameRefClass::SelectColumn);
}
return Some(NameRefClass::FromTable);
}
// Classify as SelectColumn for target list, WHERE, ORDER BY, GROUP BY, etc.
Expand Down
42 changes: 42 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,48 @@ select t$0.* from t;
");
}

#[test]
fn goto_cross_join_func_column() {
assert_snapshot!(goto(r#"
with t(x) as (select $$[{"a":1,"b":2}]$$::json)
select * from t, json_to_recordset(x$0) as r(a int, b int);
"#), @r#"
╭▸
2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
│ ─ 2. destination
3 │ select * from t, json_to_recordset(x) as r(a int, b int);
╰╴ ─ 1. source
"#);
}

#[test]
fn goto_cross_join_func_qualified_column_table() {
assert_snapshot!(goto(r#"
with t(x) as (select $$[{"a":1,"b":2}]$$::json)
select * from t, json_to_recordset(t$0.x) as r(a int, b int);
"#), @r#"
╭▸
2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
│ ─ 2. destination
3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
╰╴ ─ 1. source
"#);
}

#[test]
fn goto_cross_join_func_qualified_column_field() {
assert_snapshot!(goto(r#"
with t(x) as (select $$[{"a":1,"b":2}]$$::json)
select * from t, json_to_recordset(t.x$0) as r(a int, b int);
"#), @r#"
╭▸
2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
│ ─ 2. destination
3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
╰╴ ─ 1. source
"#);
}

#[test]
fn goto_drop_sequence() {
assert_snapshot!(goto("
Expand Down
Loading