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
2 changes: 1 addition & 1 deletion crates/squawk_fmt/tests/after/create_function.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ create function percent_type_table(
-- comments in every position
create /*a*/ or /*b*/ replace /*c*/ function /*d*/ app /*e*/./*f*/ commented(
/*g*/ in /*h*/ value /*i*/ integer /*j*/ default /*k*/ 1 /*l*/,
/*m*/ out /*n*/ result /*o*/ text /*p*/
/*m*/ in /*n*/ result /*o*/ text /*p*/
) /*q*/ returns /*r*/ table /*s*/ (
/*t*/ id /*u*/ bigint /*v*/,
/*w*/ label /*x*/ text /*y*/
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_fmt/tests/before/create_function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ create function percent_type_table(unused integer) returns table (value accounts

-- comments in every position
create /*a*/ or /*b*/ replace /*c*/ function /*d*/ app /*e*/. /*f*/ commented
(/*g*/ in /*h*/ value /*i*/ integer /*j*/ default /*k*/ 1 /*l*/, /*m*/ out /*n*/ result /*o*/ text /*p*/)
(/*g*/ in /*h*/ value /*i*/ integer /*j*/ default /*k*/ 1 /*l*/, /*m*/ in /*n*/ result /*o*/ text /*p*/)
/*q*/ returns /*r*/ table /*s*/ (/*t*/ id /*u*/ bigint /*v*/, /*w*/ label /*x*/ text /*y*/)
/*z*/ language /*aa*/ sql
/*ab*/ immutable
Expand Down
12 changes: 6 additions & 6 deletions crates/squawk_ide/src/code_actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mod add_schema;
mod convert_comment;
mod quote_identifier;
mod remove_else_clause;
mod remove_function_param_in;
mod remove_redundant_alias;
mod remove_routine_param_in;
mod rewrite_as_dollar_quoted_string;
mod rewrite_as_regular_string;
mod rewrite_at_local_as_timezone;
Expand All @@ -24,7 +24,6 @@ mod rewrite_double_colon_to_cast;
mod rewrite_extract_as_function_call;
mod rewrite_from;
mod rewrite_function_param_default_as_equals;
mod rewrite_function_param_in_out_as_inout;
mod rewrite_in_as_expression;
mod rewrite_integer_radix;
mod rewrite_is_normalized_as_function_call;
Expand All @@ -37,6 +36,7 @@ mod rewrite_overlaps_as_function_call;
mod rewrite_overlay_as_function_call;
mod rewrite_pattern_matching_as_operators;
mod rewrite_position_as_function_call;
mod rewrite_routine_param_in_out_as_inout;
mod rewrite_rows_from_as_unnest;
mod rewrite_select_as_table;
mod rewrite_select_as_values;
Expand All @@ -60,8 +60,8 @@ use add_schema::add_schema;
use convert_comment::convert_comment;
use quote_identifier::quote_identifier;
use remove_else_clause::remove_else_clause;
use remove_function_param_in::remove_function_param_in;
use remove_redundant_alias::remove_redundant_alias;
use remove_routine_param_in::remove_routine_param_in;
use rewrite_as_dollar_quoted_string::rewrite_as_dollar_quoted_string;
use rewrite_as_regular_string::rewrite_as_regular_string;
use rewrite_at_local_as_timezone::rewrite_at_local_as_timezone;
Expand All @@ -75,7 +75,6 @@ use rewrite_double_colon_to_cast::rewrite_double_colon_to_cast;
use rewrite_extract_as_function_call::rewrite_extract_as_function_call;
use rewrite_from::rewrite_from;
use rewrite_function_param_default_as_equals::rewrite_function_param_default_as_equals;
use rewrite_function_param_in_out_as_inout::rewrite_function_param_in_out_as_inout;
use rewrite_in_as_expression::rewrite_in_as_expression;
use rewrite_integer_radix::rewrite_integer_radix;
use rewrite_is_normalized_as_function_call::rewrite_is_normalized_as_function_call;
Expand All @@ -88,6 +87,7 @@ use rewrite_overlaps_as_function_call::rewrite_overlaps_as_function_call;
use rewrite_overlay_as_function_call::rewrite_overlay_as_function_call;
use rewrite_pattern_matching_as_operators::rewrite_pattern_matching_as_operators;
use rewrite_position_as_function_call::rewrite_position_as_function_call;
use rewrite_routine_param_in_out_as_inout::rewrite_routine_param_in_out_as_inout;
use rewrite_rows_from_as_unnest::rewrite_rows_from_as_unnest;
use rewrite_select_as_table::rewrite_select_as_table;
use rewrite_select_as_values::rewrite_select_as_values;
Expand Down Expand Up @@ -125,8 +125,8 @@ pub fn code_actions(db: &dyn Db, position: InFile<TextSize>) -> Option<Vec<CodeA
rewrite_select_as_table(db, position, &mut actions);
rewrite_from(db, position, &mut actions);
rewrite_function_param_default_as_equals(db, position, &mut actions);
rewrite_function_param_in_out_as_inout(db, position, &mut actions);
remove_function_param_in(db, position, &mut actions);
rewrite_routine_param_in_out_as_inout(db, position, &mut actions);
remove_routine_param_in(db, position, &mut actions);
rewrite_integer_radix(db, position, &mut actions);
rewrite_leading_from(db, position, &mut actions);
rewrite_values_as_select(db, position, &mut actions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ use crate::{file::InFile, offsets::token_from_offset};

use super::{ActionKind, CodeAction};

pub(super) fn remove_function_param_in(
pub(super) fn remove_routine_param_in(
db: &dyn Db,
position: InFile<TextSize>,
actions: &mut Vec<CodeAction>,
) -> Option<()> {
let token = token_from_offset(db, position)?;
let param = token.parent_ancestors().find_map(ast::Param::cast)?;
param
.syntax()
.ancestors()
.find_map(ast::CreateFunction::cast)?;
let ast::ParamMode::ParamIn(mode) = param.mode()? else {
return None;
};
Expand All @@ -46,13 +42,13 @@ mod test {

use crate::code_actions::test_utils::{apply_code_action, code_action_not_applicable};

use super::remove_function_param_in;
use super::remove_routine_param_in;

#[test]
fn removes_in() {
assert_snapshot!(
apply_code_action(
remove_function_param_in,
remove_routine_param_in,
"create function f(i$0n value int) returns int language sql as $$ select value $$;",
),
@"create function f(value int) returns int language sql as $$ select value $$;"
Expand All @@ -63,7 +59,7 @@ mod test {
fn preserves_comments() {
assert_snapshot!(
apply_code_action(
remove_function_param_in,
remove_routine_param_in,
"create function f(i$0n /* before value */ value int) returns int language sql as $$ select value $$;",
),
@"create function f(/* before value */ value int) returns int language sql as $$ select value $$;"
Expand All @@ -74,34 +70,80 @@ mod test {
fn applies_when_mode_follows_name() {
assert_snapshot!(
apply_code_action(
remove_function_param_in,
remove_routine_param_in,
"create function f(value i$0n int) returns int language sql as $$ select value $$;",
),
@"create function f(value int) returns int language sql as $$ select value $$;"
);
}

#[test]
fn applies_to_create_aggregate_param() {
assert_snapshot!(
apply_code_action(
remove_routine_param_in,
"create aggregate a(i$0n value int) (sfunc = f, stype = int);",
),
@"create aggregate a(value int) (sfunc = f, stype = int);"
);
}

#[test]
fn applies_to_aggregate_signature() {
assert_snapshot!(
apply_code_action(remove_routine_param_in, "drop aggregate a(i$0n int);"),
@"drop aggregate a(int);"
);
}

#[test]
fn applies_to_function_signature() {
assert_snapshot!(
apply_code_action(remove_routine_param_in, "drop function f(i$0n int);"),
@"drop function f(int);"
);
}

#[test]
fn applies_to_procedure_signature() {
assert_snapshot!(
apply_code_action(remove_routine_param_in, "drop procedure p(i$0n int);"),
@"drop procedure p(int);"
);
}

#[test]
fn applies_to_routine_signature() {
assert_snapshot!(
apply_code_action(remove_routine_param_in, "drop routine r(i$0n int);"),
@"drop routine r(int);"
);
}

#[test]
fn not_applicable_to_out() {
assert!(code_action_not_applicable(
remove_function_param_in,
remove_routine_param_in,
"create function f(o$0ut value int) returns int language sql as $$ select value $$;"
));
}

#[test]
fn not_applicable_to_inout() {
assert!(code_action_not_applicable(
remove_function_param_in,
remove_routine_param_in,
"create function f(ino$0ut value int) returns int language sql as $$ select value $$;"
));
}

#[test]
fn not_applicable_to_procedure_param() {
assert!(code_action_not_applicable(
remove_function_param_in,
"create procedure p(i$0n value int) language sql as $$ select value $$;"
));
fn applies_to_procedure_param() {
assert_snapshot!(
apply_code_action(
remove_routine_param_in,
"create procedure p(i$0n value int) language sql as $$ select value $$;",
),
@"create procedure p(value int) language sql as $$ select value $$;"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ use crate::{file::InFile, offsets::token_from_offset};

use super::{ActionKind, CodeAction};

pub(super) fn rewrite_function_param_in_out_as_inout(
pub(super) fn rewrite_routine_param_in_out_as_inout(
db: &dyn Db,
position: InFile<TextSize>,
actions: &mut Vec<CodeAction>,
) -> Option<()> {
let token = token_from_offset(db, position)?;
let param = token.parent_ancestors().find_map(ast::Param::cast)?;
param
.syntax()
.ancestors()
.find_map(ast::CreateFunction::cast)?;
let ast::ParamMode::ParamInOut(mode) = param.mode()? else {
return None;
};
Expand All @@ -42,13 +38,13 @@ mod test {

use crate::code_actions::test_utils::{apply_code_action, code_action_not_applicable};

use super::rewrite_function_param_in_out_as_inout;
use super::rewrite_routine_param_in_out_as_inout;

#[test]
fn rewrites_in_out_as_inout() {
assert_snapshot!(
apply_code_action(
rewrite_function_param_in_out_as_inout,
rewrite_routine_param_in_out_as_inout,
"create function f(in $0out value int) returns int language sql as $$ select value $$;",
),
@"create function f(inout value int) returns int language sql as $$ select value $$;"
Expand All @@ -59,26 +55,62 @@ mod test {
fn applies_when_mode_follows_name() {
assert_snapshot!(
apply_code_action(
rewrite_function_param_in_out_as_inout,
rewrite_routine_param_in_out_as_inout,
"create function f(value in o$0ut int) returns int language sql as $$ select value $$;",
),
@"create function f(value inout int) returns int language sql as $$ select value $$;"
);
}

#[test]
fn applies_to_function_signature() {
assert_snapshot!(
apply_code_action(
rewrite_routine_param_in_out_as_inout,
"drop function f(in o$0ut int);",
),
@"drop function f(inout int);"
);
}

#[test]
fn applies_to_procedure_signature() {
assert_snapshot!(
apply_code_action(
rewrite_routine_param_in_out_as_inout,
"drop procedure p(in o$0ut int);",
),
@"drop procedure p(inout int);"
);
}

#[test]
fn applies_to_routine_signature() {
assert_snapshot!(
apply_code_action(
rewrite_routine_param_in_out_as_inout,
"drop routine r(in o$0ut int);",
),
@"drop routine r(inout int);"
);
}

#[test]
fn not_applicable_to_inout() {
assert!(code_action_not_applicable(
rewrite_function_param_in_out_as_inout,
rewrite_routine_param_in_out_as_inout,
"create function f(ino$0ut value int) returns int language sql as $$ select value $$;"
));
}

#[test]
fn not_applicable_to_procedure_param() {
assert!(code_action_not_applicable(
rewrite_function_param_in_out_as_inout,
"create procedure p(in o$0ut value int) language sql as $$ select value $$;"
));
fn applies_to_procedure_param() {
assert_snapshot!(
apply_code_action(
rewrite_routine_param_in_out_as_inout,
"create procedure p(in o$0ut value int) language sql as $$ select value $$;",
),
@"create procedure p(inout value int) language sql as $$ select value $$;"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
source: crates/squawk_syntax/src/test.rs
input_file: crates/squawk_syntax/test_data/validation/aggregate_object_params.sql
---
SOURCE_FILE@0..105
COMMENT_ON@0..47
COMMENT_KW@0..7 "comment"
WHITESPACE@7..8 " "
ON_KW@8..10 "on"
WHITESPACE@10..11 " "
OBJECT_AGGREGATE@11..33
AGGREGATE_KW@11..20 "aggregate"
WHITESPACE@20..21 " "
AGGREGATE@21..33
PATH_REF@21..22
PATH_SEGMENT_REF@21..22
IDENT@21..22 "a"
PARAM_LIST@22..33
L_PAREN@22..23 "("
PARAM@23..32
PARAM_IN_OUT@23..28
INOUT_KW@23..28 "inout"
WHITESPACE@28..29 " "
PATH_TYPE@29..32
PATH_REF@29..32
PATH_SEGMENT_REF@29..32
INT_KW@29..32 "int"
R_PAREN@32..33 ")"
WHITESPACE@33..34 " "
IS_KW@34..36 "is"
WHITESPACE@36..37 " "
LITERAL@37..46
STRING@37..46 "'invalid'"
SEMICOLON@46..47 ";"
WHITESPACE@47..49 "\n\n"
SECURITY_LABEL@49..104
SECURITY_KW@49..57 "security"
WHITESPACE@57..58 " "
LABEL_KW@58..63 "label"
WHITESPACE@63..64 " "
ON_KW@64..66 "on"
WHITESPACE@66..67 " "
OBJECT_AGGREGATE@67..90
AGGREGATE_KW@67..76 "aggregate"
WHITESPACE@76..77 " "
AGGREGATE@77..90
PATH_REF@77..78
PATH_SEGMENT_REF@77..78
IDENT@77..78 "a"
PARAM_LIST@78..90
L_PAREN@78..79 "("
PARAM@79..89
PARAM_IN_OUT@79..85
IN_KW@79..81 "in"
WHITESPACE@81..82 " "
OUT_KW@82..85 "out"
WHITESPACE@85..86 " "
PATH_TYPE@86..89
PATH_REF@86..89
PATH_SEGMENT_REF@86..89
INT_KW@86..89 "int"
R_PAREN@89..90 ")"
WHITESPACE@90..91 " "
IS_KW@91..93 "is"
WHITESPACE@93..94 " "
LITERAL@94..103
STRING@94..103 "'invalid'"
SEMICOLON@103..104 ";"
WHITESPACE@104..105 "\n"

error[syntax-error]: In Out params are not allowed with aggregates.
╭▸
1 │ comment on aggregate a(inout int) is 'invalid';
╰╴ ━━━━━
error[syntax-error]: In Out params are not allowed with aggregates.
╭▸
3 │ security label on aggregate a(in out int) is 'invalid';
╰╴ ━━━━━━
Loading
Loading