Skip to content

Commit 9233896

Browse files
fix: apply_all_code_actions function disallow multi-line
fix #2222
1 parent 1b49e95 commit 9233896

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

crates/lsp/tests/basic.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ language: TypeScript
7979
rule:
8080
pattern: console.log($$$A)
8181
note: no console.log
82-
fix: |
82+
fix: |-
8383
alert($$$A)
8484
",
8585
&globals,
@@ -426,8 +426,12 @@ fn apply_all_code_actions(text: &str, actions: &Vec<Value>) -> String {
426426
}
427427
});
428428

429-
// Apply edits
430-
for (start_line, start_char, _end_line, end_char, new_text) in all_edits {
429+
// Apply edits (support same-line and cross-line)
430+
for (start_line, start_char, end_line, end_char, new_text) in all_edits {
431+
assert!(
432+
start_line == end_line,
433+
"Multi-line edits are not supported in this test"
434+
);
431435
let line = &lines[start_line];
432436
let prefix = &line[..start_char];
433437
let suffix = &line[end_char..];
@@ -445,7 +449,7 @@ id: no-console-rule
445449
language: TypeScript
446450
rule:
447451
pattern: console.log($$$A)
448-
fix: |
452+
fix: |-
449453
alert($$$A)
450454
";
451455
let mut client = create_lsp_framed(yamls).await;
@@ -477,7 +481,7 @@ fix: |
477481

478482
// Apply the first code action and verify the text change
479483
let fixed_text = apply_all_code_actions(file_content, actions);
480-
assert_eq!(fixed_text, "alert('Hello, world!')\n");
484+
assert_eq!(fixed_text, "alert('Hello, world!')");
481485
}
482486

483487
#[tokio::test]
@@ -488,15 +492,15 @@ language: TypeScript
488492
message: Use alert instead of console.log
489493
rule:
490494
pattern: console.log($$$A)
491-
fix: |
495+
fix: |-
492496
alert($$$A)
493497
---
494498
id: use-window-alert
495499
language: TypeScript
496500
message: Use window.alert instead of console.log
497501
rule:
498502
pattern: console.log($$$A)
499-
fix: |
503+
fix: |-
500504
window.alert($$$A)
501505
";
502506
let mut client = create_lsp_framed(yamls).await;
@@ -526,12 +530,12 @@ fix: |
526530
assert_eq!(actions[0]["title"], "Fix `use-alert` with ast-grep");
527531

528532
let fixed_text = apply_all_code_actions(file_content, actions);
529-
assert_eq!(fixed_text, "alert('Hello, world!')\n");
533+
assert_eq!(fixed_text, "alert('Hello, world!')");
530534
} else if diagnostic["code"] == "use-window-alert" {
531535
assert_eq!(actions[0]["title"], "Fix `use-window-alert` with ast-grep");
532536

533537
let fixed_text = apply_all_code_actions(file_content, actions);
534-
assert_eq!(fixed_text, "window.alert('Hello, world!')\n");
538+
assert_eq!(fixed_text, "window.alert('Hello, world!')");
535539
} else {
536540
panic!("Unexpected diagnostic code");
537541
}
@@ -546,7 +550,7 @@ language: TypeScript
546550
message: Use alert instead of console.log
547551
rule:
548552
pattern: console.log($$$A)
549-
fix: |
553+
fix: |-
550554
alert($$$A)";
551555
let mut client = create_lsp_framed(yamls).await;
552556

0 commit comments

Comments
 (0)