Skip to content

Commit 097d527

Browse files
committed
Fix: use a concise way to change link form when generating package.json
1 parent ffc6cdd commit 097d527

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,17 +1289,17 @@ mod tests {
12891289
.to_string();
12901290
schema.push_str(",\n");
12911291

1292-
let mut new_schema = schema.clone();
1292+
// Transform the asciidoc form link to markdown style.
12931293
let url_matches = schema.match_indices("https://");
1294-
let mut cnt = 0;
1295-
for (idx, _) in url_matches {
1294+
let mut url_offsets = url_matches.map(|(idx, _)| idx).collect::<Vec<usize>>();
1295+
url_offsets.reverse();
1296+
for idx in url_offsets {
12961297
let link = &schema[idx..];
12971298
// matching on whitespace to ignore normal links
12981299
if let Some(link_end) = link.find(|c| c == ' ' || c == '[') {
12991300
if link.chars().nth(link_end) == Some('[') {
1300-
new_schema.insert(idx + cnt, '(');
1301-
new_schema.insert(idx + link_end + cnt + 1, ')');
1302-
cnt = cnt + 2;
1301+
schema.insert(idx, '(');
1302+
schema.insert(idx + link_end + 1, ')');
13031303
}
13041304
}
13051305
}
@@ -1314,9 +1314,9 @@ mod tests {
13141314
let end = package_json.find(end_marker).unwrap();
13151315

13161316
let p = remove_ws(&package_json[start..end]);
1317-
let s = remove_ws(&new_schema);
1317+
let s = remove_ws(&schema);
13181318
if !p.contains(&s) {
1319-
package_json.replace_range(start..end, &new_schema);
1319+
package_json.replace_range(start..end, &schema);
13201320
ensure_file_contents(&package_json_path, &package_json)
13211321
}
13221322
}

0 commit comments

Comments
 (0)