Skip to content

Commit b4a74cb

Browse files
committed
support scanning todo!() Rust macros
1 parent a9a6a66 commit b4a74cb

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

samples/2.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo() {
2+
// Rust TODOs can only be generic
3+
todo!("generic");
4+
todo!();
5+
todo!("@foo not category");
6+
todo!("00 not priority");
7+
}

src/scan.rs

+63
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ fn parse_priority(word: &str) -> Option<isize> {
8989
}
9090
}
9191

92+
/// Remove closing tags, comments, and whitespace
9293
fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str {
9394
return line.split_once(delimiter_word).unwrap().1
9495
.trim()
@@ -154,6 +155,19 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
154155

155156
let text = clean_line(line, word);
156157

158+
if word.starts_with("todo!(") {
159+
entries.push(Entry {
160+
text: line.trim().to_string(),
161+
location: Location {
162+
file: filename.clone(),
163+
line: line_num + 1,
164+
},
165+
data: EntryData::Generic,
166+
});
167+
168+
break;
169+
}
170+
157171
// Handles: `todo`, `TODO`, `todo:`, `TODO:`
158172
// Also trims `"` and `'` to handle cases like `foo="bar todo"`
159173
if word.to_lowercase().trim_end_matches(':').trim_end_matches('"').trim_end_matches('\'') == "todo" {
@@ -773,6 +787,55 @@ mod tests {
773787
}, entries[9]);
774788
}
775789

790+
#[test]
791+
fn sample_test_rs() {
792+
let mut entries: Vec<Entry> = vec![];
793+
794+
let mut path = std::env::current_dir().unwrap();
795+
path.push("samples");
796+
path.push("2.rs");
797+
798+
scan_file(path.as_path(), &mut entries).unwrap();
799+
800+
assert_eq!(4, entries.len());
801+
802+
assert_eq!(Entry {
803+
data: EntryData::Generic,
804+
text: String::from("todo!(\"generic\");"),
805+
location: Location {
806+
file: path.clone(),
807+
line: 3,
808+
}
809+
}, entries[0]);
810+
811+
assert_eq!(Entry {
812+
data: EntryData::Generic,
813+
text: String::from("todo!();"),
814+
location: Location {
815+
file: path.clone(),
816+
line: 4,
817+
}
818+
}, entries[1]);
819+
820+
assert_eq!(Entry {
821+
data: EntryData::Generic,
822+
text: String::from("todo!(\"@foo not category\");"),
823+
location: Location {
824+
file: path.clone(),
825+
line: 5,
826+
}
827+
}, entries[2]);
828+
829+
assert_eq!(Entry {
830+
data: EntryData::Generic,
831+
text: String::from("todo!(\"00 not priority\");"),
832+
location: Location {
833+
file: path.clone(),
834+
line: 6,
835+
}
836+
}, entries[3]);
837+
}
838+
776839
#[test]
777840
fn todo_file_test() {
778841
let mut entries: Vec<Entry> = vec![];

0 commit comments

Comments
 (0)