Skip to content

Commit 4ca2bdd

Browse files
authored
ide: goto def with table stmt (#748)
1 parent 1800c13 commit 4ca2bdd

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

crates/squawk_ide/src/goto_definition.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,47 @@ drop table t$0;
603603
╰╴ ─ 1. source
604604
");
605605
}
606+
607+
#[test]
608+
fn goto_table_stmt() {
609+
assert_snapshot!(goto("
610+
create table t();
611+
table t$0;
612+
"), @r"
613+
╭▸
614+
2 │ create table t();
615+
│ ─ 2. destination
616+
3 │ table t;
617+
╰╴ ─ 1. source
618+
");
619+
}
620+
621+
#[test]
622+
fn goto_table_stmt_with_schema() {
623+
assert_snapshot!(goto("
624+
create table public.t();
625+
table public.t$0;
626+
"), @r"
627+
╭▸
628+
2 │ create table public.t();
629+
│ ─ 2. destination
630+
3 │ table public.t;
631+
╰╴ ─ 1. source
632+
");
633+
}
634+
635+
#[test]
636+
fn goto_table_stmt_with_search_path() {
637+
assert_snapshot!(goto("
638+
set search_path to foo;
639+
create table foo.t();
640+
table t$0;
641+
"), @r"
642+
╭▸
643+
3 │ create table foo.t();
644+
│ ─ 2. destination
645+
4 │ table t;
646+
╰╴ ─ 1. source
647+
");
648+
}
606649
}

crates/squawk_ide/src/resolve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ use crate::symbols::{Name, Schema, SymbolKind};
1010
#[derive(Debug)]
1111
enum NameRefContext {
1212
DropTable,
13+
Table,
1314
}
1415

1516
pub(crate) fn resolve_name_ref(binder: &Binder, name_ref: &ast::NameRef) -> Option<SyntaxNodePtr> {
1617
let context = classify_name_ref_context(name_ref)?;
1718

1819
match context {
19-
NameRefContext::DropTable => {
20+
NameRefContext::DropTable | NameRefContext::Table => {
2021
let path = find_containing_path(name_ref)?;
2122
let table_name = extract_table_name(&path)?;
2223
let schema = extract_schema_name(&path);
@@ -31,6 +32,9 @@ fn classify_name_ref_context(name_ref: &ast::NameRef) -> Option<NameRefContext>
3132
if ast::DropTable::can_cast(ancestor.kind()) {
3233
return Some(NameRefContext::DropTable);
3334
}
35+
if ast::Table::can_cast(ancestor.kind()) {
36+
return Some(NameRefContext::Table);
37+
}
3438
}
3539

3640
None

0 commit comments

Comments
 (0)