mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-30 07:07:32 +00:00
refactor comment extraction from tasks
This commit is contained in:
parent
a409a12f1b
commit
a40d02c9eb
2 changed files with 44 additions and 39 deletions
|
@ -8,7 +8,7 @@
|
|||
mod gen_syntax;
|
||||
mod gen_parser_tests;
|
||||
|
||||
use std::{fs, path::Path};
|
||||
use std::{fs, mem, path::Path};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
|
@ -44,3 +44,26 @@ pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
|||
fs::write(path, contents)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
|
||||
let mut res = Vec::new();
|
||||
|
||||
let prefix = "// ";
|
||||
let lines = text.lines().map(str::trim_start);
|
||||
|
||||
let mut block = vec![];
|
||||
for line in lines {
|
||||
let is_comment = line.starts_with(prefix);
|
||||
if is_comment {
|
||||
block.push(line[prefix.len()..].to_string());
|
||||
} else {
|
||||
if !block.is_empty() {
|
||||
res.push(mem::replace(&mut block, Vec::new()))
|
||||
}
|
||||
}
|
||||
}
|
||||
if !block.is_empty() {
|
||||
res.push(mem::replace(&mut block, Vec::new()))
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue