fix(body): prevent joining continuation lines to comments
CI / Test (push) Failing after 24s
CI / Build (push) Has been skipped

* Ensure comment-only lines are flushed before adding new statements
* Adjust logic to handle col-0 continuation lines correctly
This commit is contained in:
2026-06-30 22:51:25 +02:00
parent c8030247f2
commit f17e87e749
2 changed files with 246 additions and 164 deletions
+24
View File
@@ -471,6 +471,30 @@ func formatBodyStatements(text string, st config.Style) string {
fw := lowerASCII(firstBodyKeyword(stripped)) fw := lowerASCII(firstBodyKeyword(stripped))
isColZero := indent == "" isColZero := indent == ""
joinToPrev := isColZero && parenDepth == 0 && len(stmt) > 0 && !sqlClauseKw[fw] joinToPrev := isColZero && parenDepth == 0 && len(stmt) > 0 && !sqlClauseKw[fw]
// Don't join a col-0 continuation to a comment-only preceding bline:
// the comment has no structural keyword so `continue ;` at col-0 would
// disappear into the comment text and be invisible to the lexer.
if joinToPrev {
if lowerASCII(firstBodyKeyword(stmt[len(stmt)-1].text)) == "" {
joinToPrev = false
}
}
// Pre-flush pending comment-only blines before adding a new non-comment
// non-joined bline. Without this, a comment + `end if;` end up in the
// same stmt, `fw` comes from the comment (empty string), depth is never
// decremented, and the formatter diverges on the second pass.
if !joinToPrev && fw != "" && len(stmt) > 0 {
allComments := true
for _, ll := range stmt {
if lowerASCII(firstBodyKeyword(ll.text)) != "" {
allComments = false
break
}
}
if allComments {
flush()
}
}
if joinToPrev { if joinToPrev {
last := &stmt[len(stmt)-1] last := &stmt[len(stmt)-1]
+82 -24
View File
@@ -97,9 +97,18 @@ BEGIN
m_guid = newid(); m_guid = newid();
m_user = f_getuser(); m_user = f_getuser();
-- if p_doctype ilike '%plain%' and f_iscompressed(p_template) in ('none') -- and byteatotext(p_template) not ilike '%'|| G_TAG_S || '%' || G_TAG_E || '%' -- then -- raise warning 'No tags to merge in plain template.'; -- p_doc = p_template; -- return; -- end if; -- if p_doctype ilike '%plain%' and f_iscompressed(p_template) in ('none')
-- and byteatotext(p_template) not ilike '%'|| G_TAG_S || '%' || G_TAG_E || '%'
-- then
-- raise warning 'No tags to merge in plain template.';
-- p_doc = p_template;
-- return;
-- end if;
-- perform log_event(m_funcname,format('INIT _ type=%s commtype=%s p_data_prefix=%s p_data_rid=%s Template:%s' -- ,p_doctype, p_commtype,p_data_prefix,p_data_rid -- ,case when octet_length(p_template) < 100 then byteatotext(p_template) else octet_length(p_template)::text end -- ),bt_enum('eventlog','local notice')); -- perform log_event(m_funcname,format('INIT _ type=%s commtype=%s p_data_prefix=%s p_data_rid=%s Template:%s'
-- ,p_doctype, p_commtype,p_data_prefix,p_data_rid
-- ,case when octet_length(p_template) < 100 then byteatotext(p_template) else octet_length(p_template)::text end
-- ),bt_enum('eventlog','local notice'));
if p_data_prefix::citext = 'com' if p_data_prefix::citext = 'com'
then then
@@ -158,7 +167,8 @@ BEGIN
,null::bytea as blob ,null::bytea as blob
into r_doc; into r_doc;
-- perform log_event(m_funcname,format('init = p_doctype = %s p_data_prefix = %s p_data_rid = %s p_template[size] = %s' -- ,p_doctype,p_data_prefix,p_data_rid,octet_length(p_template)),bt_enum('eventlog','local notice')); -- perform log_event(m_funcname,format('init = p_doctype = %s p_data_prefix = %s p_data_rid = %s p_template[size] = %s'
-- ,p_doctype,p_data_prefix,p_data_rid,octet_length(p_template)),bt_enum('eventlog','local notice'));
if p_doctype = 'allfieldvalues' if p_doctype = 'allfieldvalues'
then then
@@ -280,13 +290,16 @@ BEGIN
, d.grand_filter_string , d.grand_filter_string
from src d ; from src d ;
--CREATE INDEX "idx_tmp_merge_init_src_type" ON tmp_merge_init_src USING btree (merge_type); --CREATE INDEX "idx_tmp_merge_init_src_tag" ON tmp_merge_init_src USING btree (mergetag); --CREATE INDEX "idx_tmp_merge_init_src_type" ON tmp_merge_init_src USING btree (merge_type);
--CREATE INDEX "idx_tmp_merge_init_src_tag" ON tmp_merge_init_src USING btree (mergetag);
--HTML field types has a special meaning in the frontend. We treat them as normal fields. update tmp_merge_init_src u --HTML field types has a special meaning in the frontend. We treat them as normal fields.
update tmp_merge_init_src u
set merge_type = G_MTYPE_FIELD set merge_type = G_MTYPE_FIELD
where u.merge_type = G_MTYPE_HTML; where u.merge_type = G_MTYPE_HTML;
--raise notice 'After MergeMenu: %', (clock_timestamp() - m_ltime); if G_BENCHMARK = 1 --raise notice 'After MergeMenu: %', (clock_timestamp() - m_ltime);
if G_BENCHMARK = 1
then then
perform log_event(m_funcname,format('Perf After MergeMenu SinceStart: %s Duration: %s', clock_timestamp() - m_start, clock_timestamp() - m_ltime),bt_enum('eventlog','local notice')); perform log_event(m_funcname,format('Perf After MergeMenu SinceStart: %s Duration: %s', clock_timestamp() - m_start, clock_timestamp() - m_ltime),bt_enum('eventlog','local notice'));
m_ltime = clock_timestamp(); m_ltime = clock_timestamp();
@@ -433,7 +446,8 @@ BEGIN
,row_number() over(order by d.source, d.mergetag) as rowid ,row_number() over(order by d.source, d.mergetag) as rowid
from docfields d ; from docfields d ;
---special update for tables linking update tmp_merge_init_fields u ---special update for tables linking
update tmp_merge_init_fields u
set tblparent = r.p_tblparent set tblparent = r.p_tblparent
, source = r.source , source = r.source
, tblid = r.p_tblid from ( , tblid = r.p_tblid from (
@@ -498,7 +512,9 @@ BEGIN
where nv(m.mergetag) <> '' where nv(m.mergetag) <> ''
) )
then then
-- perform log_event(m_funcname,format('NO TAGS p_doctype=%s p_commtype=%s p_data_prefix=%s p_data_rid=%s' -- ,p_doctype, p_commtype,p_data_prefix,p_data_rid),bt_enum('eventlog','local notice')); -- -- perform log_event(m_funcname,format('NO TAGS p_doctype=%s p_commtype=%s p_data_prefix=%s p_data_rid=%s'
-- ,p_doctype, p_commtype,p_data_prefix,p_data_rid),bt_enum('eventlog','local notice'));
--
p_doc = p_template; p_doc = p_template;
return; return;
@@ -536,7 +552,8 @@ BEGIN
--cross join view_blob(tat.rid_templateattachment,'templateattachment','maindoc','rid_templateattachment','utf8') v --cross join view_blob(tat.rid_templateattachment,'templateattachment','maindoc','rid_templateattachment','utf8') v
where tat.description ilike 'Form 16 (%' where tat.description ilike 'Form 16 (%'
), 'TCLI',1000016) r ), 'TCLI',1000016) r
*/ /* */
/*
drop table if exists debug_merge_init_src; drop table if exists debug_merge_init_src;
create table debug_merge_init_src as create table debug_merge_init_src as
@@ -631,9 +648,11 @@ BEGIN
, field_name = replace(u.field_name, r_lp.key, r_lp.value) , field_name = replace(u.field_name, r_lp.key, r_lp.value)
, parent_field_name = replace(u.parent_field_name, r_lp.key, r_lp.value) , parent_field_name = replace(u.parent_field_name, r_lp.key, r_lp.value)
, filter_string = replace(u.filter_string, r_lp.key, r_lp.value) , filter_string = replace(u.filter_string, r_lp.key, r_lp.value)
, parent_filter_string = replace(u.parent_filter_string, r_lp.key, r_lp.value) ; , parent_filter_string = replace(u.parent_filter_string, r_lp.key, r_lp.value)
;
end loop; end loop;
-----------------------------------------------------------[CHANGE ID: 29078] 14/07/2020 14:54 End for r_lp in ( -----------------------------------------------------------[CHANGE ID: 29078] 14/07/2020 14:54 End
for r_lp in (
with keywords as ( with keywords as (
select distinct r.v[1]::citext as colname select distinct r.v[1]::citext as colname
from tmp_merge_init_src f from tmp_merge_init_src f
@@ -700,7 +719,8 @@ BEGIN
, field_name = replace(u.field_name, r_lp.key, r_lp.value) , field_name = replace(u.field_name, r_lp.key, r_lp.value)
, parent_field_name = replace(u.parent_field_name, r_lp.key, r_lp.value) , parent_field_name = replace(u.parent_field_name, r_lp.key, r_lp.value)
, filter_string = replace(u.filter_string, r_lp.key, r_lp.value) , filter_string = replace(u.filter_string, r_lp.key, r_lp.value)
, parent_filter_string = replace(u.parent_filter_string, r_lp.key, r_lp.value) ; , parent_filter_string = replace(u.parent_filter_string, r_lp.key, r_lp.value)
;
end loop; end loop;
@@ -829,7 +849,8 @@ BEGIN
--,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text
),bt_enum('eventlog','local notice')); ),bt_enum('eventlog','local notice'));
end if; end if;
--raise exception 'Blank field name for record %', r_lp; continue ; --raise exception 'Blank field name for record %', r_lp;
continue ;
end if; end if;
if nv(r_lp.ops_string) = '' if nv(r_lp.ops_string) = ''
@@ -1005,7 +1026,8 @@ BEGIN
end if; end if;
m_json_full_complex = jsonb_build_object(); m_json_full_complex = jsonb_build_object();
--a_tblroot = array[-1]; BEGIN --a_tblroot = array[-1];
BEGIN
for r_lp_t in ( for r_lp_t in (
with fields as ( with fields as (
@@ -1107,7 +1129,11 @@ m_json_full_complex = jsonb_build_object();
,rn desc ,rn desc
) )
loop loop
-- perform log_event(m_funcname,format(' Tables %s=%s src=%s rn=%s' ,p_data_prefix,p_data_rid -- ,r_lp_t.source,r_lp_t.rn -- ),bt_enum('eventlog','local notice') -- --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text -- ); -- perform log_event(m_funcname,format(' Tables %s=%s src=%s rn=%s' ,p_data_prefix,p_data_rid
-- ,r_lp_t.source,r_lp_t.rn
-- ),bt_enum('eventlog','local notice')
-- --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text
-- );
if r_lp_t.table_name = any(a_inner_selected) and nv(r_lp_t.table_name ) <> '' if r_lp_t.table_name = any(a_inner_selected) and nv(r_lp_t.table_name ) <> ''
then then
@@ -1127,7 +1153,8 @@ m_json_full_complex = jsonb_build_object();
--,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text
); );
end if; end if;
--raise exception 'Blank field name for record %', r_lp; continue; --raise exception 'Blank field name for record %', r_lp;
continue;
end if; end if;
@@ -1231,12 +1258,19 @@ m_json_full_complex = jsonb_build_object();
$S$ $S$
|| ||
'}' '}'
) : : json )
:
:
json
from $S$ || max ( from $S$ || max (
f f
. .
table_name table_name
) || ' ' || ifblnk ( )
||
' '
||
ifblnk (
max max
( (
f f
@@ -1244,7 +1278,13 @@ m_json_full_complex = jsonb_build_object();
filter_string filter_string
), ),
'where 1=1' 'where 1=1'
) || ')' ) : : citext as qry , ( )
||
')'
)
:
:
citext as qry , (
$S $S
$(select ('{'|| $S$ || string_agg(format($SS$'"%1$s": ' || json_build_object('value', '[]', 'type','%3$s') $(select ('{'|| $S$ || string_agg(format($SS$'"%1$s": ' || json_build_object('value', '[]', 'type','%3$s')
: :
@@ -1267,14 +1307,20 @@ m_json_full_complex = jsonb_build_object();
$S$ $S$
|| ||
'}' '}'
) : : json $S$ || ')' ) : : citext as qryblnk , nv ( )
:
:
json $S$ || ')' ) : : citext as qryblnk , nv (
max max
( (
f f
. .
parent_order_string parent_order_string
) )
) : : citext as parent_order_string )
:
:
citext as parent_order_string
from tmp_merge_init_src f from tmp_merge_init_src f
inner inner
join tmp_merge_init_src c join tmp_merge_init_src c
@@ -1338,7 +1384,11 @@ m_json_full_complex = jsonb_build_object();
m_json_full_complex = jsonb_set(m_json_full_complex, format('{%s}',r_lp_t.tblid)::text[], _jsonb_object_cat(m_json_full_complex->r_lp_t.tblid,m_json::jsonb),true); m_json_full_complex = jsonb_set(m_json_full_complex, format('{%s}',r_lp_t.tblid)::text[], _jsonb_object_cat(m_json_full_complex->r_lp_t.tblid,m_json::jsonb),true);
end if; end if;
-- perform log_event(m_funcname,format('Complex Tables %s=%s m_json_full_complex=%s' ,p_data_prefix,p_data_rid -- ,m_json_full_complex::text -- ),bt_enum('eventlog','local notice') -- --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text -- ); -- perform log_event(m_funcname,format('Complex Tables %s=%s m_json_full_complex=%s' ,p_data_prefix,p_data_rid
-- ,m_json_full_complex::text
-- ),bt_enum('eventlog','local notice')
-- --,(select jsonb_agg(row_to_json(f)::jsonb) from tmp_merge_init_fields f)::text
-- );
m_execfilter = ''; m_execfilter = '';
m_execstr = ''; m_execstr = '';
@@ -1383,7 +1433,8 @@ end if;
m_json_full_complex = _jsonb_object_cat(m_json_full_complex, jsonb_build_object('p_retval',p_retval,'p_errmsg',p_errmsg)); m_json_full_complex = _jsonb_object_cat(m_json_full_complex, jsonb_build_object('p_retval',p_retval,'p_errmsg',p_errmsg));
return; return;
--raise exception '%', m_errmsg using hint = 'in merge jsonbuild process'; END; --raise exception '%', m_errmsg using hint = 'in merge jsonbuild process';
END;
-------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------
m_json_full = json_build_object('fields',m_json_full, 'complexfields',m_json_full_complex); m_json_full = json_build_object('fields',m_json_full, 'complexfields',m_json_full_complex);
@@ -1451,7 +1502,14 @@ end if;
else else
m_ltime = clock_timestamp(); m_ltime = clock_timestamp();
-- -- select r.p_retval, r.p_errmsg -- from f_tempfile_add(null, 'template', r_template.guid, 600,m_data_rid, m_data_prefix,r_template.blob) r -- into m_retval, m_errmsg; -- -- perform log_event(m_funcname,format('Dbg D:%s J:%s template:%s', p_doctype, m_json_full, r_template.guid) -- ,bt_enum('eventlog','local notice')); -- --stream --
-- select r.p_retval, r.p_errmsg
-- from f_tempfile_add(null, 'template', r_template.guid, 600,m_data_rid, m_data_prefix,r_template.blob) r
-- into m_retval, m_errmsg;
--
-- perform log_event(m_funcname,format('Dbg D:%s J:%s template:%s', p_doctype, m_json_full, r_template.guid)
-- ,bt_enum('eventlog','local notice'));
-- --stream
select r.p_retval select r.p_retval
, r.p_errmsg , r.p_errmsg
, r.p_result , r.p_result