Skip to content

Commit 115e09f

Browse files
authored
ide: goto def for create aggregate params (#972)
1 parent 1098fcd commit 115e09f

2 files changed

Lines changed: 66 additions & 8 deletions

File tree

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,31 @@ pub(crate) fn classify_name_ref(node: &SyntaxNode) -> Option<NameRefClass> {
308308
return Some(NameRefClass::Schema);
309309
}
310310

311-
// Check for function/procedure reference in CREATE OPERATOR before the type check
311+
// Check for function/procedure reference in CREATE OPERATOR / CREATE AGGREGATE
312+
// before the type check
312313
for ancestor in node.ancestors() {
313314
if let Some(attr_option) = ast::AttributeOption::cast(ancestor.clone())
314315
&& let Some(name) = attr_option.name()
315316
{
316317
let attr_name = Name::from_node(&name);
317-
if attr_name == Name::from_string("function")
318-
|| attr_name == Name::from_string("procedure")
319-
{
320-
for outer in attr_option.syntax().ancestors() {
321-
if ast::CreateOperator::can_cast(outer.kind()) {
322-
return Some(NameRefClass::FunctionName);
323-
}
318+
for outer in attr_option.syntax().ancestors() {
319+
if ast::CreateOperator::can_cast(outer.kind())
320+
&& (attr_name == Name::from_string("function")
321+
|| attr_name == Name::from_string("procedure"))
322+
{
323+
return Some(NameRefClass::FunctionName);
324+
}
325+
if ast::CreateAggregate::can_cast(outer.kind())
326+
&& (attr_name == Name::from_string("sfunc")
327+
|| attr_name == Name::from_string("finalfunc")
328+
|| attr_name == Name::from_string("combinefunc")
329+
|| attr_name == Name::from_string("serialfunc")
330+
|| attr_name == Name::from_string("deserialfunc")
331+
|| attr_name == Name::from_string("msfunc")
332+
|| attr_name == Name::from_string("minvfunc")
333+
|| attr_name == Name::from_string("mfinalfunc"))
334+
{
335+
return Some(NameRefClass::FunctionName);
324336
}
325337
}
326338
}

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4053,6 +4053,52 @@ select foo$0(1);
40534053
");
40544054
}
40554055

4056+
#[test]
4057+
fn goto_create_aggregate_sfunc() {
4058+
assert_snapshot!(goto("
4059+
create function pg_catalog.int8inc(bigint) returns bigint
4060+
language internal;
4061+
4062+
create aggregate pg_catalog.count(*) (
4063+
sfunc = int8inc$0,
4064+
stype = bigint,
4065+
combinefunc = int8pl,
4066+
initcond = '0'
4067+
);
4068+
"), @r"
4069+
β•­β–Έ
4070+
2 β”‚ create function pg_catalog.int8inc(bigint) returns bigint
4071+
β”‚ ─────── 2. destination
4072+
‑
4073+
6 β”‚ sfunc = int8inc,
4074+
β•°β•΄ ─ 1. source
4075+
"
4076+
);
4077+
}
4078+
4079+
#[test]
4080+
fn goto_create_aggregate_combinefunc() {
4081+
assert_snapshot!(goto("
4082+
create function pg_catalog.int8pl(bigint, bigint) returns bigint
4083+
language internal;
4084+
4085+
create aggregate pg_catalog.count(*) (
4086+
sfunc = int8inc,
4087+
stype = bigint,
4088+
combinefunc = int8pl$0,
4089+
initcond = '0'
4090+
);
4091+
"), @r"
4092+
β•­β–Έ
4093+
2 β”‚ create function pg_catalog.int8pl(bigint, bigint) returns bigint
4094+
β”‚ ────── 2. destination
4095+
‑
4096+
8 β”‚ combinefunc = int8pl,
4097+
β•°β•΄ ─ 1. source
4098+
"
4099+
);
4100+
}
4101+
40564102
#[test]
40574103
fn goto_default_constraint_function_call() {
40584104
assert_snapshot!(goto("

0 commit comments

Comments
Β (0)