Skip to content

Commit febab0a

Browse files
authored
fix: formatting should allow statements between proc python and submit (#1227)
1 parent 4e61203 commit febab0a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

client/testFixture/formatter/expected.sas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,11 @@ submit;
167167
end
168168
endsubmit;
169169
run;
170+
171+
proc python;
172+
/* comment */
173+
i;
174+
print('hello')
175+
endinteractive;
176+
/* comment */
177+
run;

client/testFixture/formatter/unformatted.sas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ submit;
157157
end
158158
end
159159
endsubmit;
160+
run;
161+
162+
proc python;
163+
/* comment */
164+
i;
165+
print('hello')
166+
endinteractive;
167+
/* comment */
160168
run;

server/src/sas/formatter/parser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,19 @@ const preserveProcs = (
119119
model: Model,
120120
) => {
121121
// should not format python/lua, treat it as raw data
122+
const lastStatement =
123+
region.children.length >= 2 &&
124+
region.children[region.children.length - 1].children;
122125
if (
123126
current === -1 &&
124127
region.block?.name === "PROC" &&
125-
region.children.length === 2 &&
128+
lastStatement &&
126129
region.children[0].children.length > 0 &&
127-
region.children[1].children.length > 1 &&
130+
lastStatement.length > 1 &&
128131
"text" in region.children[0].children[1] &&
129132
/^(python|lua)$/i.test(region.children[0].children[1].text) &&
130-
"text" in region.children[1].children[0] &&
131-
/^(submit|interactive)$/i.test(region.children[1].children[0].text)
133+
"text" in lastStatement[0] &&
134+
/^(submit|interactive|i)$/i.test(lastStatement[0].text)
132135
) {
133136
current = 0;
134137
}

0 commit comments

Comments
 (0)