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
29 changes: 29 additions & 0 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn bind_stmt(b: &mut Binder, stmt: ast::Stmt) {
ast::Stmt::CreateIndex(create_index) => bind_create_index(b, create_index),
ast::Stmt::CreateFunction(create_function) => bind_create_function(b, create_function),
ast::Stmt::CreateAggregate(create_aggregate) => bind_create_aggregate(b, create_aggregate),
ast::Stmt::CreateProcedure(create_procedure) => bind_create_procedure(b, create_procedure),
ast::Stmt::CreateSchema(create_schema) => bind_create_schema(b, create_schema),
ast::Stmt::Set(set) => bind_set(b, set),
_ => {}
Expand Down Expand Up @@ -190,6 +191,34 @@ fn bind_create_aggregate(b: &mut Binder, create_aggregate: ast::CreateAggregate)
b.scopes[root].insert(aggregate_name, aggregate_id);
}

fn bind_create_procedure(b: &mut Binder, create_procedure: ast::CreateProcedure) {
let Some(path) = create_procedure.path() else {
return;
};

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

let name_ptr = path_to_ptr(&path);

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

let params = extract_param_signature(create_procedure.param_list());

let procedure_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Procedure,
ptr: name_ptr,
schema,
params,
});

let root = b.root_scope();
b.scopes[root].insert(procedure_name, procedure_id);
}

fn bind_create_schema(b: &mut Binder, create_schema: ast::CreateSchema) {
let Some(schema_name_node) = create_schema.name() else {
return;
Expand Down
347 changes: 347 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,353 @@ drop aggregate sum$0(bigint);
");
}

#[test]
fn goto_drop_routine_function() {
assert_snapshot!(goto("
create function foo() returns int as $$ select 1 $$ language sql;
drop routine foo$0();
"), @r"
╭▸
2 │ create function foo() returns int as $$ select 1 $$ language sql;
│ ─── 2. destination
3 │ drop routine foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_aggregate() {
assert_snapshot!(goto("
create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
drop routine myavg$0(int);
"), @r"
╭▸
2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
│ ───── 2. destination
3 │ drop routine myavg(int);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_with_schema() {
assert_snapshot!(goto("
set search_path to public;
create function foo() returns int as $$ select 1 $$ language sql;
drop routine public.foo$0();
"), @r"
╭▸
3 │ create function foo() returns int as $$ select 1 $$ language sql;
│ ─── 2. destination
4 │ drop routine public.foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_defined_after() {
assert_snapshot!(goto("
drop routine foo$0();
create function foo() returns int as $$ select 1 $$ language sql;
"), @r"
╭▸
2 │ drop routine foo();
│ ─ 1. source
3 │ create function foo() returns int as $$ select 1 $$ language sql;
╰╴ ─── 2. destination
");
}

#[test]
fn goto_drop_routine_with_search_path() {
assert_snapshot!(goto("
create function foo() returns int as $$ select 1 $$ language sql;
set search_path to bar;
create function foo() returns int as $$ select 1 $$ language sql;
set search_path to default;
drop routine foo$0();
"), @r"
╭▸
2 │ create function foo() returns int as $$ select 1 $$ language sql;
│ ─── 2. destination
6 │ drop routine foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_overloaded() {
assert_snapshot!(goto("
create function add(complex) returns complex as $$ select null $$ language sql;
create function add(bigint) returns bigint as $$ select 1 $$ language sql;
drop routine add$0(complex);
"), @r"
╭▸
2 │ create function add(complex) returns complex as $$ select null $$ language sql;
│ ─── 2. destination
3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
4 │ drop routine add(complex);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_second_overload() {
assert_snapshot!(goto("
create function add(complex) returns complex as $$ select null $$ language sql;
create function add(bigint) returns bigint as $$ select 1 $$ language sql;
drop routine add$0(bigint);
"), @r"
╭▸
3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
│ ─── 2. destination
4 │ drop routine add(bigint);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_aggregate_overloaded() {
assert_snapshot!(goto("
create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
drop routine sum$0(complex);
"), @r"
╭▸
2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
│ ─── 2. destination
3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
4 │ drop routine sum(complex);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_multiple() {
assert_snapshot!(goto("
create function foo() returns int as $$ select 1 $$ language sql;
create function bar() returns int as $$ select 1 $$ language sql;
drop routine foo(), bar$0();
"), @r"
╭▸
3 │ create function bar() returns int as $$ select 1 $$ language sql;
│ ─── 2. destination
4 │ drop routine foo(), bar();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure() {
assert_snapshot!(goto("
create procedure foo() language sql as $$ select 1 $$;
drop procedure foo$0();
"), @r"
╭▸
2 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
3 │ drop procedure foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure_with_schema() {
assert_snapshot!(goto("
set search_path to public;
create procedure foo() language sql as $$ select 1 $$;
drop procedure public.foo$0();
"), @r"
╭▸
3 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
4 │ drop procedure public.foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure_defined_after() {
assert_snapshot!(goto("
drop procedure foo$0();
create procedure foo() language sql as $$ select 1 $$;
"), @r"
╭▸
2 │ drop procedure foo();
│ ─ 1. source
3 │ create procedure foo() language sql as $$ select 1 $$;
╰╴ ─── 2. destination
");
}

#[test]
fn goto_drop_procedure_with_search_path() {
assert_snapshot!(goto("
create procedure foo() language sql as $$ select 1 $$;
set search_path to bar;
create procedure foo() language sql as $$ select 1 $$;
set search_path to default;
drop procedure foo$0();
"), @r"
╭▸
2 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
6 │ drop procedure foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure_overloaded() {
assert_snapshot!(goto("
create procedure add(complex) language sql as $$ select null $$;
create procedure add(bigint) language sql as $$ select 1 $$;
drop procedure add$0(complex);
"), @r"
╭▸
2 │ create procedure add(complex) language sql as $$ select null $$;
│ ─── 2. destination
3 │ create procedure add(bigint) language sql as $$ select 1 $$;
4 │ drop procedure add(complex);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure_second_overload() {
assert_snapshot!(goto("
create procedure add(complex) language sql as $$ select null $$;
create procedure add(bigint) language sql as $$ select 1 $$;
drop procedure add$0(bigint);
"), @r"
╭▸
3 │ create procedure add(bigint) language sql as $$ select 1 $$;
│ ─── 2. destination
4 │ drop procedure add(bigint);
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_procedure_multiple() {
assert_snapshot!(goto("
create procedure foo() language sql as $$ select 1 $$;
create procedure bar() language sql as $$ select 1 $$;
drop procedure foo(), bar$0();
"), @r"
╭▸
3 │ create procedure bar() language sql as $$ select 1 $$;
│ ─── 2. destination
4 │ drop procedure foo(), bar();
╰╴ ─ 1. source
");
}

#[test]
fn goto_procedure_definition_returns_self() {
assert_snapshot!(goto("
create procedure foo$0() language sql as $$ select 1 $$;
"), @r"
╭▸
2 │ create procedure foo() language sql as $$ select 1 $$;
│ ┬─┬
│ │ │
│ │ 1. source
╰╴ 2. destination
");
}

#[test]
fn goto_call_procedure() {
assert_snapshot!(goto("
create procedure foo() language sql as $$ select 1 $$;
call foo$0();
"), @r"
╭▸
2 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
3 │ call foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_call_procedure_with_schema() {
assert_snapshot!(goto("
create procedure public.foo() language sql as $$ select 1 $$;
call public.foo$0();
"), @r"
╭▸
2 │ create procedure public.foo() language sql as $$ select 1 $$;
│ ─── 2. destination
3 │ call public.foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_call_procedure_with_search_path() {
assert_snapshot!(goto("
set search_path to myschema;
create procedure foo() language sql as $$ select 1 $$;
call myschema.foo$0();
"), @r"
╭▸
3 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
4 │ call myschema.foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_procedure() {
assert_snapshot!(goto("
create procedure foo() language sql as $$ select 1 $$;
drop routine foo$0();
"), @r"
╭▸
2 │ create procedure foo() language sql as $$ select 1 $$;
│ ─── 2. destination
3 │ drop routine foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_prefers_function_over_procedure() {
assert_snapshot!(goto("
create function foo() returns int as $$ select 1 $$ language sql;
create procedure foo() language sql as $$ select 1 $$;
drop routine foo$0();
"), @r"
╭▸
2 │ create function foo() returns int as $$ select 1 $$ language sql;
│ ─── 2. destination
3 │ create procedure foo() language sql as $$ select 1 $$;
4 │ drop routine foo();
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_routine_prefers_aggregate_over_procedure() {
assert_snapshot!(goto("
create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
create procedure foo(int) language sql as $$ select 1 $$;
drop routine foo$0(int);
"), @r"
╭▸
2 │ create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
│ ─── 2. destination
3 │ create procedure foo(int) language sql as $$ select 1 $$;
4 │ drop routine foo(int);
╰╴ ─ 1. source
");
}

#[test]
fn goto_table_alias_in_qualified_column() {
assert_snapshot!(goto("
Expand Down
Loading
Loading