diff --git a/Cargo.lock b/Cargo.lock index 33a8450..7422caa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,7 +111,7 @@ dependencies = [ ] [[package]] -name = "ls-todo" +name = "ls-todos" version = "1.0.0" dependencies = [ "comment-parser", diff --git a/Cargo.toml b/Cargo.toml index 21979c8..620ab88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ls-todo" +name = "ls-todos" version = "1.0.0" edition = "2021" diff --git a/README.md b/README.md index c5d6140..d54fe08 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# ls todo +# ls todos Lists all locations where TODO/FIXME/BUG was written anywhere inside a comment. diff --git a/src/main.rs b/src/main.rs index 902481b..8f15c8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,8 @@ use std::{env, path::Path, fs, collections::HashSet}; -use comment_parser::CommentParser; +use comment_parser::{CommentParser, SyntaxRule}; use ignore::Walk; use regex::Regex; -// TODO: Add language support for tsx, jsx, lua - #[derive(Debug)] struct Reminder { row: u32, @@ -14,6 +12,19 @@ struct Reminder { static ALLOWED_VERBS: [&str; 3] = ["TODO", "FIXME", "BUG"]; +const JS: [SyntaxRule; 3] = [ + SyntaxRule::LineComment(b"//"), + SyntaxRule::BlockComment(b"/*", b"*/"), + SyntaxRule::String(b"\""), +]; + +const LUA: [SyntaxRule; 4] = [ + SyntaxRule::LineComment(b"--"), + SyntaxRule::BlockComment(b"--[[", b"]]--"), + SyntaxRule::String(b"\""), + SyntaxRule::String(b"'") +]; + fn get_row_and_column(contents: &str, substr: &str, from: usize) -> (u32, u32) { let occurence = contents[from..].find(substr).unwrap() + from; let row = (contents.chars().take(occurence).filter(|c| *c == '\n').count()+1) as u32; @@ -22,13 +33,22 @@ fn get_row_and_column(contents: &str, substr: &str, from: usize) -> (u32, u32) { (row, col) } -fn list_reminders + ?Sized>(path: &P) -> Option> +fn list_reminders(path: &Path) -> Option> { let mut reminders = vec![]; let reminder_pattern: Regex = Regex::new(r"^[A-Z]+.*:").unwrap(); - let rules = comment_parser::get_syntax_from_path(path); - if rules.is_err() { return None; } + let mut rules = comment_parser::get_syntax_from_path(path); + if rules.is_err() { + let ext = path.extension()?; + if ext == "jsx" || ext == "tsx" { + rules = Ok(&JS) + } else if ext == "lua" { + rules = Ok(&LUA) + } else { + return None; + } + } let rules = rules.unwrap(); let file_contents = fs::read_to_string(path).unwrap();