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
43 changes: 43 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
");
}
}
6 changes: 5 additions & 1 deletion crates/squawk_ide/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SyntaxNodePtr> {
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);
Expand All @@ -31,6 +32,9 @@ fn classify_name_ref_context(name_ref: &ast::NameRef) -> Option<NameRefContext>
if ast::DropTable::can_cast(ancestor.kind()) {
return Some(NameRefContext::DropTable);
}
if ast::Table::can_cast(ancestor.kind()) {
return Some(NameRefContext::Table);
}
}

None
Expand Down
Loading