Skip to content

Commit 0c1e473

Browse files
committed
initial
1 parent 18b61b5 commit 0c1e473

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ biome-main/
5353
.review/
5454
pglinter_repo/
5555
.review/
56+
.opencode-session-id

crates/pgls_configuration/src/format.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ pub struct FormatConfiguration {
101101
/// Data type casing (text, varchar, int): "upper" or "lower". Default: "lower".
102102
#[partial(bpaf(long("type-case")))]
103103
pub type_case: KeywordCase,
104+
/// If `true`, skip formatting of SQL function bodies (keep them verbatim). Default: `false`.
105+
#[partial(bpaf(long("skip-fn-bodies")))]
106+
pub skip_fn_bodies: bool,
104107
/// A list of Unix shell style patterns. The formatter will ignore files/folders that will match these patterns.
105108
#[partial(bpaf(hide))]
106109
pub ignore: StringSet,
@@ -119,6 +122,7 @@ impl Default for FormatConfiguration {
119122
keyword_case: KeywordCase::default(),
120123
constant_case: KeywordCase::default(),
121124
type_case: KeywordCase::default(),
125+
skip_fn_bodies: false,
122126
ignore: Default::default(),
123127
include: Default::default(),
124128
}

crates/pgls_workspace/src/settings.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ fn to_formatter_settings(
376376
keyword_case: conf.keyword_case,
377377
constant_case: conf.constant_case,
378378
type_case: conf.type_case,
379+
skip_fn_bodies: conf.skip_fn_bodies,
379380
ignored_files: to_matcher(working_directory.clone(), Some(&conf.ignore))?,
380381
included_files: to_matcher(working_directory.clone(), Some(&conf.include))?,
381382
})
@@ -566,6 +567,9 @@ pub struct FormatterSettings {
566567
/// Data type casing (text, varchar, int): upper or lower. Default: lower.
567568
pub type_case: KeywordCase,
568569

570+
/// If true, skip formatting of SQL function bodies (keep them verbatim). Default: false.
571+
pub skip_fn_bodies: bool,
572+
569573
/// List of ignored paths/files to match
570574
pub ignored_files: Matcher,
571575

@@ -583,6 +587,7 @@ impl Default for FormatterSettings {
583587
keyword_case: KeywordCase::default(),
584588
constant_case: KeywordCase::default(),
585589
type_case: KeywordCase::default(),
590+
skip_fn_bodies: false,
586591
ignored_files: Matcher::empty(),
587592
included_files: Matcher::empty(),
588593
}

crates/pgls_workspace/src/workspace/server.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,24 +892,27 @@ impl Workspace for WorkspaceServer {
892892
let format_candidates: Vec<_> = doc.iter(FormatStatementMapper).collect();
893893
let mut formatted_sql_fn_bodies = HashMap::new();
894894

895-
for (id, _stmt_range, _text, ast_result) in &format_candidates {
896-
if !id.is_child() {
897-
continue;
898-
}
895+
// Only format SQL function bodies if skip_fn_bodies is false
896+
if !settings.formatter.skip_fn_bodies {
897+
for (id, _stmt_range, _text, ast_result) in &format_candidates {
898+
if !id.is_child() {
899+
continue;
900+
}
899901

900-
let Some(parent_id) = id.parent() else {
901-
continue;
902-
};
902+
let Some(parent_id) = id.parent() else {
903+
continue;
904+
};
903905

904-
let Ok(ast) = ast_result else {
905-
continue;
906-
};
906+
let Ok(ast) = ast_result else {
907+
continue;
908+
};
907909

908-
let Ok(result) = pgls_pretty_print::format_statement(ast, &config) else {
909-
continue;
910-
};
910+
let Ok(result) = pgls_pretty_print::format_statement(ast, &config) else {
911+
continue;
912+
};
911913

912-
formatted_sql_fn_bodies.insert(parent_id, result.formatted);
914+
formatted_sql_fn_bodies.insert(parent_id, result.formatted);
915+
}
913916
}
914917

915918
for (id, stmt_range, text, ast_result) in format_candidates {

0 commit comments

Comments
 (0)