add jsx,tsx,lua support
This commit is contained in:
parent
c6f2e07af0
commit
c077f88e48
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -111,7 +111,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ls-todo"
|
||||
name = "ls-todos"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"comment-parser",
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "ls-todo"
|
||||
name = "ls-todos"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
# ls todo
|
||||
# ls todos
|
||||
Lists all locations where TODO/FIXME/BUG was written anywhere inside a comment.
|
||||
|
32
src/main.rs
32
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<P: AsRef<Path> + ?Sized>(path: &P) -> Option<Vec<Reminder>>
|
||||
fn list_reminders(path: &Path) -> Option<Vec<Reminder>>
|
||||
{
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user