Skip to content

Commit ac3fccf

Browse files
authored
ide: goto def & hover with procedures (#792)
1 parent 11013d1 commit ac3fccf

File tree

5 files changed

+839
-0
lines changed

5 files changed

+839
-0
lines changed

β€Žcrates/squawk_ide/src/binder.rsβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn bind_stmt(b: &mut Binder, stmt: ast::Stmt) {
8181
ast::Stmt::CreateIndex(create_index) => bind_create_index(b, create_index),
8282
ast::Stmt::CreateFunction(create_function) => bind_create_function(b, create_function),
8383
ast::Stmt::CreateAggregate(create_aggregate) => bind_create_aggregate(b, create_aggregate),
84+
ast::Stmt::CreateProcedure(create_procedure) => bind_create_procedure(b, create_procedure),
8485
ast::Stmt::CreateSchema(create_schema) => bind_create_schema(b, create_schema),
8586
ast::Stmt::Set(set) => bind_set(b, set),
8687
_ => {}
@@ -190,6 +191,34 @@ fn bind_create_aggregate(b: &mut Binder, create_aggregate: ast::CreateAggregate)
190191
b.scopes[root].insert(aggregate_name, aggregate_id);
191192
}
192193

194+
fn bind_create_procedure(b: &mut Binder, create_procedure: ast::CreateProcedure) {
195+
let Some(path) = create_procedure.path() else {
196+
return;
197+
};
198+
199+
let Some(procedure_name) = item_name(&path) else {
200+
return;
201+
};
202+
203+
let name_ptr = path_to_ptr(&path);
204+
205+
let Some(schema) = schema_name(b, &path, false) else {
206+
return;
207+
};
208+
209+
let params = extract_param_signature(create_procedure.param_list());
210+
211+
let procedure_id = b.symbols.alloc(Symbol {
212+
kind: SymbolKind::Procedure,
213+
ptr: name_ptr,
214+
schema,
215+
params,
216+
});
217+
218+
let root = b.root_scope();
219+
b.scopes[root].insert(procedure_name, procedure_id);
220+
}
221+
193222
fn bind_create_schema(b: &mut Binder, create_schema: ast::CreateSchema) {
194223
let Some(schema_name_node) = create_schema.name() else {
195224
return;

β€Žcrates/squawk_ide/src/goto_definition.rsβ€Ž

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,353 @@ drop aggregate sum$0(bigint);
24532453
");
24542454
}
24552455

2456+
#[test]
2457+
fn goto_drop_routine_function() {
2458+
assert_snapshot!(goto("
2459+
create function foo() returns int as $$ select 1 $$ language sql;
2460+
drop routine foo$0();
2461+
"), @r"
2462+
β•­β–Έ
2463+
2 β”‚ create function foo() returns int as $$ select 1 $$ language sql;
2464+
β”‚ ─── 2. destination
2465+
3 β”‚ drop routine foo();
2466+
β•°β•΄ ─ 1. source
2467+
");
2468+
}
2469+
2470+
#[test]
2471+
fn goto_drop_routine_aggregate() {
2472+
assert_snapshot!(goto("
2473+
create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
2474+
drop routine myavg$0(int);
2475+
"), @r"
2476+
β•­β–Έ
2477+
2 β”‚ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
2478+
β”‚ ───── 2. destination
2479+
3 β”‚ drop routine myavg(int);
2480+
β•°β•΄ ─ 1. source
2481+
");
2482+
}
2483+
2484+
#[test]
2485+
fn goto_drop_routine_with_schema() {
2486+
assert_snapshot!(goto("
2487+
set search_path to public;
2488+
create function foo() returns int as $$ select 1 $$ language sql;
2489+
drop routine public.foo$0();
2490+
"), @r"
2491+
β•­β–Έ
2492+
3 β”‚ create function foo() returns int as $$ select 1 $$ language sql;
2493+
β”‚ ─── 2. destination
2494+
4 β”‚ drop routine public.foo();
2495+
β•°β•΄ ─ 1. source
2496+
");
2497+
}
2498+
2499+
#[test]
2500+
fn goto_drop_routine_defined_after() {
2501+
assert_snapshot!(goto("
2502+
drop routine foo$0();
2503+
create function foo() returns int as $$ select 1 $$ language sql;
2504+
"), @r"
2505+
β•­β–Έ
2506+
2 β”‚ drop routine foo();
2507+
β”‚ ─ 1. source
2508+
3 β”‚ create function foo() returns int as $$ select 1 $$ language sql;
2509+
β•°β•΄ ─── 2. destination
2510+
");
2511+
}
2512+
2513+
#[test]
2514+
fn goto_drop_routine_with_search_path() {
2515+
assert_snapshot!(goto("
2516+
create function foo() returns int as $$ select 1 $$ language sql;
2517+
set search_path to bar;
2518+
create function foo() returns int as $$ select 1 $$ language sql;
2519+
set search_path to default;
2520+
drop routine foo$0();
2521+
"), @r"
2522+
β•­β–Έ
2523+
2 β”‚ create function foo() returns int as $$ select 1 $$ language sql;
2524+
β”‚ ─── 2. destination
2525+
‑
2526+
6 β”‚ drop routine foo();
2527+
β•°β•΄ ─ 1. source
2528+
");
2529+
}
2530+
2531+
#[test]
2532+
fn goto_drop_routine_overloaded() {
2533+
assert_snapshot!(goto("
2534+
create function add(complex) returns complex as $$ select null $$ language sql;
2535+
create function add(bigint) returns bigint as $$ select 1 $$ language sql;
2536+
drop routine add$0(complex);
2537+
"), @r"
2538+
β•­β–Έ
2539+
2 β”‚ create function add(complex) returns complex as $$ select null $$ language sql;
2540+
β”‚ ─── 2. destination
2541+
3 β”‚ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
2542+
4 β”‚ drop routine add(complex);
2543+
β•°β•΄ ─ 1. source
2544+
");
2545+
}
2546+
2547+
#[test]
2548+
fn goto_drop_routine_second_overload() {
2549+
assert_snapshot!(goto("
2550+
create function add(complex) returns complex as $$ select null $$ language sql;
2551+
create function add(bigint) returns bigint as $$ select 1 $$ language sql;
2552+
drop routine add$0(bigint);
2553+
"), @r"
2554+
β•­β–Έ
2555+
3 β”‚ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
2556+
β”‚ ─── 2. destination
2557+
4 β”‚ drop routine add(bigint);
2558+
β•°β•΄ ─ 1. source
2559+
");
2560+
}
2561+
2562+
#[test]
2563+
fn goto_drop_routine_aggregate_overloaded() {
2564+
assert_snapshot!(goto("
2565+
create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
2566+
create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
2567+
drop routine sum$0(complex);
2568+
"), @r"
2569+
β•­β–Έ
2570+
2 β”‚ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
2571+
β”‚ ─── 2. destination
2572+
3 β”‚ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
2573+
4 β”‚ drop routine sum(complex);
2574+
β•°β•΄ ─ 1. source
2575+
");
2576+
}
2577+
2578+
#[test]
2579+
fn goto_drop_routine_multiple() {
2580+
assert_snapshot!(goto("
2581+
create function foo() returns int as $$ select 1 $$ language sql;
2582+
create function bar() returns int as $$ select 1 $$ language sql;
2583+
drop routine foo(), bar$0();
2584+
"), @r"
2585+
β•­β–Έ
2586+
3 β”‚ create function bar() returns int as $$ select 1 $$ language sql;
2587+
β”‚ ─── 2. destination
2588+
4 β”‚ drop routine foo(), bar();
2589+
β•°β•΄ ─ 1. source
2590+
");
2591+
}
2592+
2593+
#[test]
2594+
fn goto_drop_procedure() {
2595+
assert_snapshot!(goto("
2596+
create procedure foo() language sql as $$ select 1 $$;
2597+
drop procedure foo$0();
2598+
"), @r"
2599+
β•­β–Έ
2600+
2 β”‚ create procedure foo() language sql as $$ select 1 $$;
2601+
β”‚ ─── 2. destination
2602+
3 β”‚ drop procedure foo();
2603+
β•°β•΄ ─ 1. source
2604+
");
2605+
}
2606+
2607+
#[test]
2608+
fn goto_drop_procedure_with_schema() {
2609+
assert_snapshot!(goto("
2610+
set search_path to public;
2611+
create procedure foo() language sql as $$ select 1 $$;
2612+
drop procedure public.foo$0();
2613+
"), @r"
2614+
β•­β–Έ
2615+
3 β”‚ create procedure foo() language sql as $$ select 1 $$;
2616+
β”‚ ─── 2. destination
2617+
4 β”‚ drop procedure public.foo();
2618+
β•°β•΄ ─ 1. source
2619+
");
2620+
}
2621+
2622+
#[test]
2623+
fn goto_drop_procedure_defined_after() {
2624+
assert_snapshot!(goto("
2625+
drop procedure foo$0();
2626+
create procedure foo() language sql as $$ select 1 $$;
2627+
"), @r"
2628+
β•­β–Έ
2629+
2 β”‚ drop procedure foo();
2630+
β”‚ ─ 1. source
2631+
3 β”‚ create procedure foo() language sql as $$ select 1 $$;
2632+
β•°β•΄ ─── 2. destination
2633+
");
2634+
}
2635+
2636+
#[test]
2637+
fn goto_drop_procedure_with_search_path() {
2638+
assert_snapshot!(goto("
2639+
create procedure foo() language sql as $$ select 1 $$;
2640+
set search_path to bar;
2641+
create procedure foo() language sql as $$ select 1 $$;
2642+
set search_path to default;
2643+
drop procedure foo$0();
2644+
"), @r"
2645+
β•­β–Έ
2646+
2 β”‚ create procedure foo() language sql as $$ select 1 $$;
2647+
β”‚ ─── 2. destination
2648+
‑
2649+
6 β”‚ drop procedure foo();
2650+
β•°β•΄ ─ 1. source
2651+
");
2652+
}
2653+
2654+
#[test]
2655+
fn goto_drop_procedure_overloaded() {
2656+
assert_snapshot!(goto("
2657+
create procedure add(complex) language sql as $$ select null $$;
2658+
create procedure add(bigint) language sql as $$ select 1 $$;
2659+
drop procedure add$0(complex);
2660+
"), @r"
2661+
β•­β–Έ
2662+
2 β”‚ create procedure add(complex) language sql as $$ select null $$;
2663+
β”‚ ─── 2. destination
2664+
3 β”‚ create procedure add(bigint) language sql as $$ select 1 $$;
2665+
4 β”‚ drop procedure add(complex);
2666+
β•°β•΄ ─ 1. source
2667+
");
2668+
}
2669+
2670+
#[test]
2671+
fn goto_drop_procedure_second_overload() {
2672+
assert_snapshot!(goto("
2673+
create procedure add(complex) language sql as $$ select null $$;
2674+
create procedure add(bigint) language sql as $$ select 1 $$;
2675+
drop procedure add$0(bigint);
2676+
"), @r"
2677+
β•­β–Έ
2678+
3 β”‚ create procedure add(bigint) language sql as $$ select 1 $$;
2679+
β”‚ ─── 2. destination
2680+
4 β”‚ drop procedure add(bigint);
2681+
β•°β•΄ ─ 1. source
2682+
");
2683+
}
2684+
2685+
#[test]
2686+
fn goto_drop_procedure_multiple() {
2687+
assert_snapshot!(goto("
2688+
create procedure foo() language sql as $$ select 1 $$;
2689+
create procedure bar() language sql as $$ select 1 $$;
2690+
drop procedure foo(), bar$0();
2691+
"), @r"
2692+
β•­β–Έ
2693+
3 β”‚ create procedure bar() language sql as $$ select 1 $$;
2694+
β”‚ ─── 2. destination
2695+
4 β”‚ drop procedure foo(), bar();
2696+
β•°β•΄ ─ 1. source
2697+
");
2698+
}
2699+
2700+
#[test]
2701+
fn goto_procedure_definition_returns_self() {
2702+
assert_snapshot!(goto("
2703+
create procedure foo$0() language sql as $$ select 1 $$;
2704+
"), @r"
2705+
β•­β–Έ
2706+
2 β”‚ create procedure foo() language sql as $$ select 1 $$;
2707+
β”‚ ┬─┬
2708+
β”‚ β”‚ β”‚
2709+
β”‚ β”‚ 1. source
2710+
β•°β•΄ 2. destination
2711+
");
2712+
}
2713+
2714+
#[test]
2715+
fn goto_call_procedure() {
2716+
assert_snapshot!(goto("
2717+
create procedure foo() language sql as $$ select 1 $$;
2718+
call foo$0();
2719+
"), @r"
2720+
β•­β–Έ
2721+
2 β”‚ create procedure foo() language sql as $$ select 1 $$;
2722+
β”‚ ─── 2. destination
2723+
3 β”‚ call foo();
2724+
β•°β•΄ ─ 1. source
2725+
");
2726+
}
2727+
2728+
#[test]
2729+
fn goto_call_procedure_with_schema() {
2730+
assert_snapshot!(goto("
2731+
create procedure public.foo() language sql as $$ select 1 $$;
2732+
call public.foo$0();
2733+
"), @r"
2734+
β•­β–Έ
2735+
2 β”‚ create procedure public.foo() language sql as $$ select 1 $$;
2736+
β”‚ ─── 2. destination
2737+
3 β”‚ call public.foo();
2738+
β•°β•΄ ─ 1. source
2739+
");
2740+
}
2741+
2742+
#[test]
2743+
fn goto_call_procedure_with_search_path() {
2744+
assert_snapshot!(goto("
2745+
set search_path to myschema;
2746+
create procedure foo() language sql as $$ select 1 $$;
2747+
call myschema.foo$0();
2748+
"), @r"
2749+
β•­β–Έ
2750+
3 β”‚ create procedure foo() language sql as $$ select 1 $$;
2751+
β”‚ ─── 2. destination
2752+
4 β”‚ call myschema.foo();
2753+
β•°β•΄ ─ 1. source
2754+
");
2755+
}
2756+
2757+
#[test]
2758+
fn goto_drop_routine_procedure() {
2759+
assert_snapshot!(goto("
2760+
create procedure foo() language sql as $$ select 1 $$;
2761+
drop routine foo$0();
2762+
"), @r"
2763+
β•­β–Έ
2764+
2 β”‚ create procedure foo() language sql as $$ select 1 $$;
2765+
β”‚ ─── 2. destination
2766+
3 β”‚ drop routine foo();
2767+
β•°β•΄ ─ 1. source
2768+
");
2769+
}
2770+
2771+
#[test]
2772+
fn goto_drop_routine_prefers_function_over_procedure() {
2773+
assert_snapshot!(goto("
2774+
create function foo() returns int as $$ select 1 $$ language sql;
2775+
create procedure foo() language sql as $$ select 1 $$;
2776+
drop routine foo$0();
2777+
"), @r"
2778+
β•­β–Έ
2779+
2 β”‚ create function foo() returns int as $$ select 1 $$ language sql;
2780+
β”‚ ─── 2. destination
2781+
3 β”‚ create procedure foo() language sql as $$ select 1 $$;
2782+
4 β”‚ drop routine foo();
2783+
β•°β•΄ ─ 1. source
2784+
");
2785+
}
2786+
2787+
#[test]
2788+
fn goto_drop_routine_prefers_aggregate_over_procedure() {
2789+
assert_snapshot!(goto("
2790+
create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
2791+
create procedure foo(int) language sql as $$ select 1 $$;
2792+
drop routine foo$0(int);
2793+
"), @r"
2794+
β•­β–Έ
2795+
2 β”‚ create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
2796+
β”‚ ─── 2. destination
2797+
3 β”‚ create procedure foo(int) language sql as $$ select 1 $$;
2798+
4 β”‚ drop routine foo(int);
2799+
β•°β•΄ ─ 1. source
2800+
");
2801+
}
2802+
24562803
#[test]
24572804
fn goto_table_alias_in_qualified_column() {
24582805
assert_snapshot!(goto("

0 commit comments

Comments
Β (0)