Skip to content

Commit

Permalink
feat(struct): make output in really results
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 23, 2021
1 parent 7a7c318 commit 718e232
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 13 additions & 6 deletions plugins/coco_struct_analysis/src/ctags_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::str::Lines;

pub struct CtagsParser {
class_map: HashMap<String, ClassInfo>,
Expand Down Expand Up @@ -66,14 +67,18 @@ lazy_static! {
}

impl CtagsParser {
pub fn parse_str(str: &str) -> CtagsParser {
pub fn parse_str(lines: Vec<Lines>) -> CtagsParser {
let mut parser = CtagsParser::default();
for line in str.lines() {
parser.parse_class(line);
for lines in lines.clone() {
for line in lines.into_iter() {
parser.parse_class(line);
}
}

for line in str.lines() {
parser.parse_method_methods(line);
for lines in lines {
for line in lines.into_iter() {
parser.parse_method_methods(line);
}
}

parser
Expand Down Expand Up @@ -260,7 +265,9 @@ mod test {
let str = "MethodIdentifier SubscriberRegistry.java /^ MethodIdentifier(Method method) {$/;\" method line:239 language:Java class:SubscriberRegistry.MethodIdentifier access:default
MethodIdentifier SubscriberRegistry.java /^ private static final class MethodIdentifier {$/;\" class line:234 language:Java class:SubscriberRegistry access:private";

let parser = CtagsParser::parse_str(str);
let mut lines = vec![];
lines.push(str.lines());
let parser = CtagsParser::parse_str(lines);
let classes = parser.classes();

assert_eq!(1, classes.len());
Expand Down
12 changes: 10 additions & 2 deletions plugins/coco_struct_analysis/src/struct_analysis_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ fn write_to_file(url_str: &str, result: String) {

fn run_ctags(opt: &Opt, files: &Vec<String>) -> Vec<ClassInfo> {
let outputs = CmdCtags::call(&opt, &files).unwrap();
let out_str = str::from_utf8(&outputs[0].stdout).unwrap();
let mut iters = Vec::new();
for o in &outputs {
let iter = if opt.validate_utf8 {
str::from_utf8(&o.stdout).unwrap().lines()
} else {
unsafe { str::from_utf8_unchecked(&o.stdout).lines() }
};
iters.push(iter);
}

let parser = CtagsParser::parse_str(out_str);
let parser = CtagsParser::parse_str(iters);
let classes = parser.classes();

classes
Expand Down

0 comments on commit 718e232

Please sign in to comment.