diff --git a/crates/squawk_ide/src/goto_definition.rs b/crates/squawk_ide/src/goto_definition.rs index 0d567216..6b64eaaa 100644 --- a/crates/squawk_ide/src/goto_definition.rs +++ b/crates/squawk_ide/src/goto_definition.rs @@ -603,4 +603,47 @@ drop table t$0; ╰╴ ─ 1. source "); } + + #[test] + fn goto_table_stmt() { + assert_snapshot!(goto(" +create table t(); +table t$0; +"), @r" + ╭▸ + 2 │ create table t(); + │ ─ 2. destination + 3 │ table t; + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_table_stmt_with_schema() { + assert_snapshot!(goto(" +create table public.t(); +table public.t$0; +"), @r" + ╭▸ + 2 │ create table public.t(); + │ ─ 2. destination + 3 │ table public.t; + ╰╴ ─ 1. source + "); + } + + #[test] + fn goto_table_stmt_with_search_path() { + assert_snapshot!(goto(" +set search_path to foo; +create table foo.t(); +table t$0; +"), @r" + ╭▸ + 3 │ create table foo.t(); + │ ─ 2. destination + 4 │ table t; + ╰╴ ─ 1. source + "); + } } diff --git a/crates/squawk_ide/src/resolve.rs b/crates/squawk_ide/src/resolve.rs index 4c0c4212..4869afeb 100644 --- a/crates/squawk_ide/src/resolve.rs +++ b/crates/squawk_ide/src/resolve.rs @@ -10,13 +10,14 @@ use crate::symbols::{Name, Schema, SymbolKind}; #[derive(Debug)] enum NameRefContext { DropTable, + Table, } pub(crate) fn resolve_name_ref(binder: &Binder, name_ref: &ast::NameRef) -> Option { let context = classify_name_ref_context(name_ref)?; match context { - NameRefContext::DropTable => { + NameRefContext::DropTable | NameRefContext::Table => { let path = find_containing_path(name_ref)?; let table_name = extract_table_name(&path)?; let schema = extract_schema_name(&path); @@ -31,6 +32,9 @@ fn classify_name_ref_context(name_ref: &ast::NameRef) -> Option if ast::DropTable::can_cast(ancestor.kind()) { return Some(NameRefContext::DropTable); } + if ast::Table::can_cast(ancestor.kind()) { + return Some(NameRefContext::Table); + } } None