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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ biome-main/
.review/
pglinter_repo/
.review/
.opencode-session-id
4 changes: 4 additions & 0 deletions crates/pgls_configuration/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pub struct FormatConfiguration {
/// Data type casing (text, varchar, int): "upper" or "lower". Default: "lower".
#[partial(bpaf(long("type-case")))]
pub type_case: KeywordCase,
/// If `true`, skip formatting of SQL function bodies (keep them verbatim). Default: `false`.
#[partial(bpaf(long("skip-fn-bodies")))]
pub skip_fn_bodies: bool,
/// A list of Unix shell style patterns. The formatter will ignore files/folders that will match these patterns.
#[partial(bpaf(hide))]
pub ignore: StringSet,
Expand All @@ -119,6 +122,7 @@ impl Default for FormatConfiguration {
keyword_case: KeywordCase::default(),
constant_case: KeywordCase::default(),
type_case: KeywordCase::default(),
skip_fn_bodies: false,
ignore: Default::default(),
include: Default::default(),
}
Expand Down
5 changes: 5 additions & 0 deletions crates/pgls_workspace/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ fn to_formatter_settings(
keyword_case: conf.keyword_case,
constant_case: conf.constant_case,
type_case: conf.type_case,
skip_fn_bodies: conf.skip_fn_bodies,
ignored_files: to_matcher(working_directory.clone(), Some(&conf.ignore))?,
included_files: to_matcher(working_directory.clone(), Some(&conf.include))?,
})
Expand Down Expand Up @@ -566,6 +567,9 @@ pub struct FormatterSettings {
/// Data type casing (text, varchar, int): upper or lower. Default: lower.
pub type_case: KeywordCase,

/// If true, skip formatting of SQL function bodies (keep them verbatim). Default: false.
pub skip_fn_bodies: bool,

/// List of ignored paths/files to match
pub ignored_files: Matcher,

Expand All @@ -583,6 +587,7 @@ impl Default for FormatterSettings {
keyword_case: KeywordCase::default(),
constant_case: KeywordCase::default(),
type_case: KeywordCase::default(),
skip_fn_bodies: false,
ignored_files: Matcher::empty(),
included_files: Matcher::empty(),
}
Expand Down
31 changes: 17 additions & 14 deletions crates/pgls_workspace/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,24 +892,27 @@ impl Workspace for WorkspaceServer {
let format_candidates: Vec<_> = doc.iter(FormatStatementMapper).collect();
let mut formatted_sql_fn_bodies = HashMap::new();

for (id, _stmt_range, _text, ast_result) in &format_candidates {
if !id.is_child() {
continue;
}
// Only format SQL function bodies if skip_fn_bodies is false
if !settings.formatter.skip_fn_bodies {
for (id, _stmt_range, _text, ast_result) in &format_candidates {
if !id.is_child() {
continue;
}

let Some(parent_id) = id.parent() else {
continue;
};
let Some(parent_id) = id.parent() else {
continue;
};

let Ok(ast) = ast_result else {
continue;
};
let Ok(ast) = ast_result else {
continue;
};

let Ok(result) = pgls_pretty_print::format_statement(ast, &config) else {
continue;
};
let Ok(result) = pgls_pretty_print::format_statement(ast, &config) else {
continue;
};

formatted_sql_fn_bodies.insert(parent_id, result.formatted);
formatted_sql_fn_bodies.insert(parent_id, result.formatted);
}
}

for (id, stmt_range, text, ast_result) in format_candidates {
Expand Down
7 changes: 7 additions & 0 deletions docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@
"format": "uint16",
"minimum": 0.0
},
"skipFnBodies": {
"description": "If `true`, skip formatting of SQL function bodies (keep them verbatim). Default: `false`.",
"type": [
"boolean",
"null"
]
},
"typeCase": {
"description": "Data type casing (text, varchar, int): \"upper\" or \"lower\". Default: \"lower\".",
"anyOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ export interface PartialFormatConfiguration {
* Maximum line width before breaking. Default: 100.
*/
lineWidth?: number;
/**
* If `true`, skip formatting of SQL function bodies (keep them verbatim). Default: `false`.
*/
skipFnBodies?: boolean;
/**
* Data type casing (text, varchar, int): "upper" or "lower". Default: "lower".
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/@postgrestools/backend-jsonrpc/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ export interface PartialFormatConfiguration {
* Maximum line width before breaking. Default: 100.
*/
lineWidth?: number;
/**
* If `true`, skip formatting of SQL function bodies (keep them verbatim). Default: `false`.
*/
skipFnBodies?: boolean;
/**
* Data type casing (text, varchar, int): "upper" or "lower". Default: "lower".
*/
Expand Down
Loading