Skip to content

Commit

Permalink
chore: fix document root calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Mar 30, 2024
1 parent 8a2e6e7 commit c15869d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,10 @@ SuppressionComments.js:1:1 suppressions/deprecatedSuppressionComment FIXABLE
i Unsafe fix: Use // biome-ignore instead
1 │ - //·rome-ignore·lint/correctness/noUnreachable:·this·comment·does·nothing
1 │ + //·biome-ignore·lint/correctness/noUnreachable:·this·comment·does·nothing
2 2 │ function SuppressionComments1() {
3 3 │ beforeReturn();
4 4 │ return;
5 5 │ afterReturn();
6 │ - }
6 │ + }
7 │ +
8 │ + function·SuppressionComments2()·{
9 │ + ····beforeReturn();
10 │ + ····return;
11 │ + ····//·rome-ignore·lint/correctness/noUnreachable:·supress·warning
12 │ + ····afterReturn();
13 │ + }
14 │ +
1 │ - //·rome-ignore·lint/correctness/noUnreachable:·this·comment·does·nothing
1 │ + //·biome-ignore·lint/correctness/noUnreachable:·this·comment·does·nothing
2 2 │ function SuppressionComments1() {
3 3 │ beforeReturn();
```
Expand Down Expand Up @@ -91,23 +79,12 @@ SuppressionComments.js:11:5 suppressions/deprecatedSuppressionComment FIXABLE
i Unsafe fix: Use // biome-ignore instead
1 │ -
2 │ - ····//·rome-ignore·lint/correctness/noUnreachable:·supress·warning
3 │ - ····afterReturn
1 │ + //·rome-ignore·lint/correctness/noUnreachable:·this·comment·does·nothing
2 │ + function·SuppressionComments1()·{
3 │ + ····beforeReturn();
4 │ + ····return;
5 │ + ····afterReturn();
6 │ + }
7 │ +
8 │ + function·SuppressionComments2()·{
9 │ + ····beforeReturn();
10 │ + ····return;
11 │ + ····//·biome-ignore·lint/correctness/noUnreachable:·supress·warning
12 │ + ····afterReturn();
13 │ + }
14 │ +
9 9 │ beforeReturn();
10 10 │ return;
11 │ - ····//·rome-ignore·lint/correctness/noUnreachable:·supress·warning
11 │ + ····//·biome-ignore·lint/correctness/noUnreachable:·supress·warning
12 12 │ afterReturn();
13 13 │ }
```
Expand All @@ -124,5 +101,3 @@ SuppressionComments.js:1:1 suppressions/unused ━━━━━━━━━━━
```


17 changes: 12 additions & 5 deletions crates/biome_rowan/src/ast/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,14 @@ where
// Convert mutations to text edit
let mut text_range = TextRange::default();
let mut text_edit_builder = TextEditBuilder::default();
let root_text = self.root().to_string();

// Mutation root is not necessarily the document root in some rule actions.
let mut document_root = self.root().clone();
while let Some(parent) = document_root.parent() {
document_root = parent;
}

let document_root_text = document_root.to_string();

let mut pointer: usize = 0;

Expand All @@ -346,10 +353,10 @@ where
) {
text_range = text_range.cover(old_text_range);
if range_start > pointer {
text_edit_builder.equal(&root_text[pointer..range_start]);
text_edit_builder.equal(&document_root_text[pointer..range_start]);
}

let old = &root_text[range_start..range_end];
let old = &document_root_text[range_start..range_end];
let new = &optional_new_text.map_or(String::new(), |t| t);

text_edit_builder.with_unicode_words_diff(old, new);
Expand All @@ -358,9 +365,9 @@ where
}
}

let end_pos = root_text.len();
let end_pos = document_root_text.len();
if end_pos > pointer {
text_edit_builder.equal(&root_text[pointer..end_pos]);
text_edit_builder.equal(&document_root_text[pointer..end_pos]);
}

let text_edit = text_edit_builder.finish();
Expand Down

0 comments on commit c15869d

Please sign in to comment.