From 1a24ee9a1bd43666da4351526889db9cc967f4f8 Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Wed, 20 Oct 2021 20:13:03 +0800 Subject: [PATCH 1/4] Fix a format error --- editors/code/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/code/package.json b/editors/code/package.json index 5dcdcb27695..ab69a44c9ab 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -436,7 +436,7 @@ ] }, "rust-analyzer.assist.importGroup": { - "markdownDescription": "Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines.", + "markdownDescription": "Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import [following order]. Groups are separated by newlines.", "default": true, "type": "boolean" }, From ffc6cdd8714b44a7a50648109fdc8eb42b580c2c Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Thu, 28 Oct 2021 10:13:43 +0800 Subject: [PATCH 2/4] Fix: transform the asciidoc form link to markdown style when generating the package.json --- crates/rust-analyzer/src/config.rs | 19 +++++++++++++++++-- editors/code/package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 0d6b1bcbfb0..ee6ab698fa4 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1289,6 +1289,21 @@ fn generate_package_json_config() { .to_string(); schema.push_str(",\n"); + let mut new_schema = schema.clone(); + let url_matches = schema.match_indices("https://"); + let mut cnt = 0; + for (idx, _) in url_matches { + let link = &schema[idx..]; + // matching on whitespace to ignore normal links + if let Some(link_end) = link.find(|c| c == ' ' || c == '[') { + if link.chars().nth(link_end) == Some('[') { + new_schema.insert(idx + cnt, '('); + new_schema.insert(idx + link_end + cnt + 1, ')'); + cnt = cnt + 2; + } + } + } + let package_json_path = project_root().join("editors/code/package.json"); let mut package_json = fs::read_to_string(&package_json_path).unwrap(); @@ -1299,9 +1314,9 @@ fn generate_package_json_config() { let end = package_json.find(end_marker).unwrap(); let p = remove_ws(&package_json[start..end]); - let s = remove_ws(&schema); + let s = remove_ws(&new_schema); if !p.contains(&s) { - package_json.replace_range(start..end, &schema); + package_json.replace_range(start..end, &new_schema); ensure_file_contents(&package_json_path, &package_json) } } diff --git a/editors/code/package.json b/editors/code/package.json index ab69a44c9ab..fffaf6c9b86 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -436,7 +436,7 @@ ] }, "rust-analyzer.assist.importGroup": { - "markdownDescription": "Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import [following order]. Groups are separated by newlines.", + "markdownDescription": "Group inserted imports by the (https://rust-analyzer.github.io/manual.html#auto-import)[following order]. Groups are separated by newlines.", "default": true, "type": "boolean" }, From 097d527cbdd288c9a702cfe6f6611e9c0831ad4e Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Fri, 29 Oct 2021 10:00:10 +0800 Subject: [PATCH 3/4] Fix: use a concise way to change link form when generating package.json --- crates/rust-analyzer/src/config.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index ee6ab698fa4..32e4e8ebeeb 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1289,17 +1289,17 @@ fn generate_package_json_config() { .to_string(); schema.push_str(",\n"); - let mut new_schema = schema.clone(); + // Transform the asciidoc form link to markdown style. let url_matches = schema.match_indices("https://"); - let mut cnt = 0; - for (idx, _) in url_matches { + let mut url_offsets = url_matches.map(|(idx, _)| idx).collect::>(); + url_offsets.reverse(); + for idx in url_offsets { let link = &schema[idx..]; // matching on whitespace to ignore normal links if let Some(link_end) = link.find(|c| c == ' ' || c == '[') { if link.chars().nth(link_end) == Some('[') { - new_schema.insert(idx + cnt, '('); - new_schema.insert(idx + link_end + cnt + 1, ')'); - cnt = cnt + 2; + schema.insert(idx, '('); + schema.insert(idx + link_end + 1, ')'); } } } @@ -1314,9 +1314,9 @@ fn generate_package_json_config() { let end = package_json.find(end_marker).unwrap(); let p = remove_ws(&package_json[start..end]); - let s = remove_ws(&new_schema); + let s = remove_ws(&schema); if !p.contains(&s) { - package_json.replace_range(start..end, &new_schema); + package_json.replace_range(start..end, &schema); ensure_file_contents(&package_json_path, &package_json) } } From 74396d27c0b94b9143519aa0075afe6c51fd6822 Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Fri, 29 Oct 2021 18:25:32 +0800 Subject: [PATCH 4/4] Fix: correct markdown link form. --- crates/rust-analyzer/src/config.rs | 12 ++++++++++-- editors/code/package.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 32e4e8ebeeb..81f4ccd365c 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1290,6 +1290,8 @@ fn generate_package_json_config() { schema.push_str(",\n"); // Transform the asciidoc form link to markdown style. + // + // https://link[text] => [text](https://link) let url_matches = schema.match_indices("https://"); let mut url_offsets = url_matches.map(|(idx, _)| idx).collect::>(); url_offsets.reverse(); @@ -1298,8 +1300,14 @@ fn generate_package_json_config() { // matching on whitespace to ignore normal links if let Some(link_end) = link.find(|c| c == ' ' || c == '[') { if link.chars().nth(link_end) == Some('[') { - schema.insert(idx, '('); - schema.insert(idx + link_end + 1, ')'); + if let Some(link_text_end) = link.find(']') { + let link_text = link[link_end..(link_text_end + 1)].to_string(); + + schema.replace_range((idx + link_end)..(idx + link_text_end + 1), ""); + schema.insert(idx, '('); + schema.insert(idx + link_end + 1, ')'); + schema.insert_str(idx, &link_text); + } } } } diff --git a/editors/code/package.json b/editors/code/package.json index fffaf6c9b86..336081e88c5 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -436,7 +436,7 @@ ] }, "rust-analyzer.assist.importGroup": { - "markdownDescription": "Group inserted imports by the (https://rust-analyzer.github.io/manual.html#auto-import)[following order]. Groups are separated by newlines.", + "markdownDescription": "Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines.", "default": true, "type": "boolean" },