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
28 changes: 28 additions & 0 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ fn bind_stmt(b: &mut Binder, stmt: ast::Stmt) {
ast::Stmt::CreateProcedure(create_procedure) => bind_create_procedure(b, create_procedure),
ast::Stmt::CreateSchema(create_schema) => bind_create_schema(b, create_schema),
ast::Stmt::CreateType(create_type) => bind_create_type(b, create_type),
ast::Stmt::CreateDomain(create_domain) => bind_create_domain(b, create_domain),
ast::Stmt::CreateView(create_view) => bind_create_view(b, create_view),
ast::Stmt::CreateMaterializedView(create_view) => {
bind_create_materialized_view(b, create_view)
Expand Down Expand Up @@ -494,6 +495,33 @@ fn bind_create_type(b: &mut Binder, create_type: ast::CreateType) {
}
}

fn bind_create_domain(b: &mut Binder, create_domain: ast::CreateDomain) {
let Some(path) = create_domain.path() else {
return;
};

let Some(domain_name) = item_name(&path) else {
return;
};

let name_ptr = path_to_ptr(&path);

let Some(schema) = schema_name(b, &path, false) else {
return;
};

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

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

fn multirange_type_from_range(
b: &Binder,
create_type: ast::CreateType,
Expand Down
4 changes: 4 additions & 0 deletions crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) enum NameRefClass {
Table,
DropIndex,
DropType,
DropDomain,
DropView,
DropMaterializedView,
DropSequence,
Expand Down Expand Up @@ -438,6 +439,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
if ast::DropType::can_cast(ancestor.kind()) {
return Some(NameRefClass::DropType);
}
if ast::DropDomain::can_cast(ancestor.kind()) {
return Some(NameRefClass::DropDomain);
}
if ast::DropView::can_cast(ancestor.kind()) {
return Some(NameRefClass::DropView);
}
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 @@ -1861,6 +1861,48 @@ drop type int4_range$0;
");
}

#[test]
fn goto_drop_domain() {
assert_snapshot!(goto("
create domain posint as integer check (value > 0);
drop domain posint$0;
"), @r"
╭▸
2 │ create domain posint as integer check (value > 0);
│ ────── 2. destination
3 │ drop domain posint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_cast_to_domain() {
assert_snapshot!(goto("
create domain posint as integer check (value > 0);
select 1::posint$0;
"), @r"
╭▸
2 │ create domain posint as integer check (value > 0);
│ ────── 2. destination
3 │ select 1::posint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_type_domain() {
assert_snapshot!(goto("
create domain posint as integer check (value > 0);
drop type posint$0;
"), @r"
╭▸
2 │ create domain posint as integer check (value > 0);
│ ────── 2. destination
3 │ drop type posint;
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_view() {
assert_snapshot!(goto("
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn hover(file: &ast::SourceFile, offset: TextSize) -> Option<String> {
| NameRefClass::AlterTableDropColumn => {
return hover_column(root, &name_ref, &binder);
}
NameRefClass::TypeReference | NameRefClass::DropType => {
NameRefClass::TypeReference | NameRefClass::DropType | NameRefClass::DropDomain => {
return hover_type(root, &name_ref, &binder);
}
NameRefClass::CompositeTypeField => {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) fn resolve_name_ref_ptrs(
let position = name_ref.syntax().text_range().start();
resolve_index_name_ptr(binder, &index_name, &schema, position).map(|ptr| smallvec![ptr])
}
NameRefClass::DropType | NameRefClass::TypeReference => {
NameRefClass::DropType | NameRefClass::DropDomain | NameRefClass::TypeReference => {
let (type_name, schema) = if let Some(parent) = name_ref.syntax().parent()
&& let Some(field_expr) = ast::FieldExpr::cast(parent)
&& field_expr
Expand Down
Loading