diff --git a/client/testFixture/formatter/expected.sas b/client/testFixture/formatter/expected.sas index e124b2e41..a6bc781d1 100644 --- a/client/testFixture/formatter/expected.sas +++ b/client/testFixture/formatter/expected.sas @@ -167,3 +167,11 @@ submit; end endsubmit; run; + +proc python; +/* comment */ +i; +print('hello') +endinteractive; + /* comment */ +run; diff --git a/client/testFixture/formatter/unformatted.sas b/client/testFixture/formatter/unformatted.sas index bec169cda..3948a9c53 100644 --- a/client/testFixture/formatter/unformatted.sas +++ b/client/testFixture/formatter/unformatted.sas @@ -157,4 +157,12 @@ submit; end end endsubmit; +run; + +proc python; +/* comment */ +i; +print('hello') +endinteractive; +/* comment */ run; \ No newline at end of file diff --git a/server/src/sas/formatter/parser.ts b/server/src/sas/formatter/parser.ts index 09f91e0a7..41c30592b 100644 --- a/server/src/sas/formatter/parser.ts +++ b/server/src/sas/formatter/parser.ts @@ -119,16 +119,19 @@ const preserveProcs = ( model: Model, ) => { // should not format python/lua, treat it as raw data + const lastStatement = + region.children.length >= 2 && + region.children[region.children.length - 1].children; if ( current === -1 && region.block?.name === "PROC" && - region.children.length === 2 && + lastStatement && region.children[0].children.length > 0 && - region.children[1].children.length > 1 && + lastStatement.length > 1 && "text" in region.children[0].children[1] && /^(python|lua)$/i.test(region.children[0].children[1].text) && - "text" in region.children[1].children[0] && - /^(submit|interactive)$/i.test(region.children[1].children[0].text) + "text" in lastStatement[0] && + /^(submit|interactive|i)$/i.test(lastStatement[0].text) ) { current = 0; }