Skip to content

Commit 01adc49

Browse files
committed
chore: update Cargo.lock for v0.2.1
1 parent b68a105 commit 01adc49

File tree

4 files changed

+154
-67
lines changed

4 files changed

+154
-67
lines changed

Cargo.lock

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/engine/java.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,46 @@ fn wrap_inline_java(body: &str) -> String {
285285
return body.to_string();
286286
}
287287

288-
let mut wrapped = String::from(
289-
"public class Main {\n public static void main(String[] args) throws Exception {\n",
290-
);
288+
// Preserve leading package/import lines at top-level so they aren't placed
289+
// inside the generated Main class. Collect header lines then wrap the
290+
// remaining code inside the Main class's main method.
291+
let mut header_lines = Vec::new();
292+
let mut rest_lines = Vec::new();
293+
let mut in_header = true;
294+
291295
for line in body.lines() {
296+
let trimmed = line.trim_start();
297+
if in_header && (trimmed.starts_with("import ") || trimmed.starts_with("package ")) {
298+
header_lines.push(line);
299+
continue;
300+
}
301+
in_header = false;
302+
rest_lines.push(line);
303+
}
304+
305+
let mut result = String::new();
306+
if !header_lines.is_empty() {
307+
for hl in header_lines {
308+
result.push_str(hl);
309+
if !hl.ends_with('\n') {
310+
result.push('\n');
311+
}
312+
}
313+
result.push('\n');
314+
}
315+
316+
result.push_str("public class Main {\n public static void main(String[] args) throws Exception {\n");
317+
for line in rest_lines {
292318
if line.trim().is_empty() {
293-
wrapped.push_str(" \n");
319+
result.push_str(" \n");
294320
} else {
295-
wrapped.push_str(" ");
296-
wrapped.push_str(line);
297-
wrapped.push('\n');
321+
result.push_str(" ");
322+
result.push_str(line);
323+
result.push('\n');
298324
}
299325
}
300-
wrapped.push_str(" }\n}\n");
301-
wrapped
326+
result.push_str(" }\n}\n");
327+
result
302328
}
303329

304330
struct JavaSession {

src/engine/kotlin.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,46 @@ fn wrap_inline_kotlin(body: &str) -> String {
207207
return body.to_string();
208208
}
209209

210-
let mut wrapped = String::from("fun main() {\n");
210+
// Pull any leading import/package lines out so they remain at top-level
211+
// (imports are not allowed inside a function). We'll keep those lines
212+
// verbatim, then wrap the remaining snippet body inside fun main().
213+
let mut header_lines = Vec::new();
214+
let mut rest_lines = Vec::new();
215+
let mut in_header = true;
216+
211217
for line in body.lines() {
218+
let trimmed = line.trim_start();
219+
if in_header && (trimmed.starts_with("import ") || trimmed.starts_with("package ")) {
220+
header_lines.push(line);
221+
continue;
222+
}
223+
in_header = false;
224+
rest_lines.push(line);
225+
}
226+
227+
let mut result = String::new();
228+
if !header_lines.is_empty() {
229+
for hl in header_lines {
230+
result.push_str(hl);
231+
if !hl.ends_with('\n') {
232+
result.push('\n');
233+
}
234+
}
235+
result.push('\n');
236+
}
237+
238+
result.push_str("fun main() {\n");
239+
for line in rest_lines {
212240
if line.trim().is_empty() {
213-
wrapped.push_str(" \n");
241+
result.push_str(" \n");
214242
} else {
215-
wrapped.push_str(" ");
216-
wrapped.push_str(line);
217-
wrapped.push('\n');
243+
result.push_str(" ");
244+
result.push_str(line);
245+
result.push('\n');
218246
}
219247
}
220-
wrapped.push_str("}\n");
221-
wrapped
248+
result.push_str("}\n");
249+
result
222250
}
223251

224252
fn contains_main_function(code: &str) -> bool {

0 commit comments

Comments
 (0)