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
30 changes: 7 additions & 23 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn bind_stmt(b: &mut Binder, stmt: ast::Stmt) {
match stmt {
ast::Stmt::CreateTable(create_table) => bind_create_table(b, create_table),
ast::Stmt::CreateForeignTable(create_foreign_table) => {
bind_create_foreign_table(b, create_foreign_table)
bind_create_table(b, create_foreign_table)
}
ast::Stmt::CreateIndex(create_index) => bind_create_index(b, create_index),
ast::Stmt::CreateFunction(create_function) => bind_create_function(b, create_function),
Expand All @@ -197,7 +197,7 @@ fn bind_stmt(b: &mut Binder, stmt: ast::Stmt) {
}
}

fn bind_create_table(b: &mut Binder, create_table: ast::CreateTable) {
fn bind_create_table(b: &mut Binder, create_table: impl ast::HasCreateTable) {
let Some(path) = create_table.path() else {
return;
};
Expand All @@ -213,36 +213,20 @@ fn bind_create_table(b: &mut Binder, create_table: ast::CreateTable) {
let table_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Table,
ptr: name_ptr,
schema: Some(schema),
schema: Some(schema.clone()),
params: None,
});

let root = b.root_scope();
b.scopes[root].insert(table_name, table_id);
}

// TODO: combine with bind_create_table
fn bind_create_foreign_table(b: &mut Binder, create_foreign_table: ast::CreateForeignTable) {
let Some(path) = create_foreign_table.path() else {
return;
};
let Some(table_name) = item_name(&path) else {
return;
};
let name_ptr = path_to_ptr(&path);
let Some(schema) = schema_name(b, &path, false) else {
return;
};

let table_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Table,
let type_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Type,
ptr: name_ptr,
schema: Some(schema),
params: None,
});

let root = b.root_scope();
b.scopes[root].insert(table_name, table_id);
b.scopes[root].insert(table_name.clone(), table_id);
b.scopes[root].insert(table_name, type_id);
}

fn bind_create_index(b: &mut Binder, create_index: ast::CreateIndex) {
Expand Down
14 changes: 14 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,20 @@ create table user(id int, member person_info$0);
");
}

#[test]
fn goto_function_param_table_type() {
assert_snapshot!(goto("
create table t(a int, b int);
create function b(t$0) returns int as 'select 1' language sql;
"), @r"
╭▸
2 │ create table t(a int, b int);
│ ─ 2. destination
3 │ create function b(t) returns int as 'select 1' language sql;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_type_reference_enum() {
assert_snapshot!(goto("
Expand Down
14 changes: 13 additions & 1 deletion crates/squawk_syntax/src/ast/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use squawk_parser::SyntaxKind;

// based on rust-analyzer's ast traits
// https://github.com/rust-lang/rust-analyzer/blob/d8887c0758bbd2d5f752d5bd405d4491e90e7ed6/crates/syntax/src/ast/traits.rs
use crate::ast;
use crate::ast::{AstNode, support};
use crate::{SyntaxToken, ast};

pub trait NameLike: AstNode {}

Expand All @@ -16,6 +18,16 @@ pub trait HasCreateTable: AstNode {
support::child(self.syntax())
}

#[inline]
fn temp_token(&self) -> Option<SyntaxToken> {
support::token(self.syntax(), SyntaxKind::TEMP_KW)
}

#[inline]
fn temporary_token(&self) -> Option<SyntaxToken> {
support::token(self.syntax(), SyntaxKind::TEMPORARY_KW)
}

#[inline]
fn inherits(&self) -> Option<ast::Inherits> {
support::child(self.syntax())
Expand Down
Loading