Merge pull request #36 from mist-go/refactors-and-patches
Refactors and patches
This commit is contained in:
@@ -2,9 +2,7 @@ WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
|
|||||||
|
|
||||||
integer = @{ ASCII_DIGIT+ }
|
integer = @{ ASCII_DIGIT+ }
|
||||||
|
|
||||||
next_line = { "+" }
|
map = { "/*" ~ integer ~ ":" ~ integer ~ "*/" }
|
||||||
|
|
||||||
map = { "/*" ~ integer ~ ":" ~ integer ~ next_line? ~ "*/" }
|
|
||||||
|
|
||||||
non_map = { (!map ~ ANY)+ }
|
non_map = { (!map ~ ANY)+ }
|
||||||
|
|
||||||
|
|||||||
@@ -32,17 +32,7 @@ pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> {
|
|||||||
inner.next().unwrap().as_str().parse().unwrap(),
|
inner.next().unwrap().as_str().parse().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
mapping.insert((
|
mapping.insert((RustMap(rs.0, rs.1), MistMap(line, col)));
|
||||||
RustMap(rs.0, rs.1),
|
|
||||||
MistMap(
|
|
||||||
if inner.next().is_some() {
|
|
||||||
line
|
|
||||||
} else {
|
|
||||||
line - 1
|
|
||||||
},
|
|
||||||
col,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-10
@@ -30,7 +30,7 @@ pub fn build(mut args: Vec<String>, config: Config, root: PathBuf) -> bool {
|
|||||||
args.remove(0);
|
args.remove(0);
|
||||||
args.insert(1, "--message-format=json".to_string());
|
args.insert(1, "--message-format=json".to_string());
|
||||||
|
|
||||||
let is_root = root == env::current_dir().unwrap();
|
let is_root = root == env::current_dir().expect("Failed getting env");
|
||||||
|
|
||||||
let mut command = Command::new("cargo")
|
let mut command = Command::new("cargo")
|
||||||
.args(args)
|
.args(args)
|
||||||
@@ -38,9 +38,9 @@ pub fn build(mut args: Vec<String>, config: Config, root: PathBuf) -> bool {
|
|||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.stdin(Stdio::inherit())
|
.stdin(Stdio::inherit())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.expect("Failed to run cargo");
|
||||||
|
|
||||||
let mut reader = std::io::BufReader::new(command.stdout.take().unwrap());
|
let mut reader = std::io::BufReader::new(command.stdout.take().expect("Failed to get reader"));
|
||||||
|
|
||||||
let mut diagnostics = Vec::new();
|
let mut diagnostics = Vec::new();
|
||||||
|
|
||||||
@@ -60,17 +60,21 @@ pub fn build(mut args: Vec<String>, config: Config, root: PathBuf) -> bool {
|
|||||||
|
|
||||||
let mist_path = root.join(&mist_file);
|
let mist_path = root.join(&mist_file);
|
||||||
|
|
||||||
if !fs::exists(&mist_path).unwrap() {
|
if !fs::exists(&mist_path).expect("Unable to check if mist file exists") {
|
||||||
diagnostics.push(MistDiagnostic::Rust(msg));
|
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let map = mapping.entry(rust_path.clone()).or_insert_with(|| {
|
let map = mapping.entry(rust_path.clone()).or_insert_with(|| {
|
||||||
get_mapping(&fs::read_to_string(rust_path).unwrap())
|
get_mapping(
|
||||||
|
&fs::read_to_string(rust_path)
|
||||||
|
.expect("Failed to read file for mapping"),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mist_span =
|
let mist_span =
|
||||||
find_mapping(&map, &RustMap(span.line_end, span.column_start)).unwrap();
|
find_mapping(&map, &RustMap(span.line_end, span.column_start))
|
||||||
|
.expect("Unable to find mapping");
|
||||||
|
|
||||||
let mist_msg = MistDiagnosticMessage {
|
let mist_msg = MistDiagnosticMessage {
|
||||||
message: span.label.clone().unwrap_or(msg.message.message.clone()),
|
message: span.label.clone().unwrap_or(msg.message.message.clone()),
|
||||||
@@ -105,7 +109,9 @@ pub fn build(mut args: Vec<String>, config: Config, root: PathBuf) -> bool {
|
|||||||
let mut raw_reader = reader.into_inner();
|
let mut raw_reader = reader.into_inner();
|
||||||
let mut stdout = std::io::stdout();
|
let mut stdout = std::io::stdout();
|
||||||
|
|
||||||
std::io::copy(&mut raw_reader, &mut stdout).unwrap();
|
std::io::copy(&mut raw_reader, &mut stdout)
|
||||||
|
.map_err(|v| v.to_string())
|
||||||
|
.expect("(Mist) Failed to copy IO");
|
||||||
|
|
||||||
command.wait().unwrap();
|
command.wait().unwrap();
|
||||||
|
|
||||||
@@ -131,7 +137,7 @@ pub fn print_diagnostics(diagnostics: &Vec<MistDiagnostic>) {
|
|||||||
println!(
|
println!(
|
||||||
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line + 1,
|
msg.line,
|
||||||
msg.column,
|
msg.column,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),
|
line.unwrap_or_default(),
|
||||||
@@ -144,12 +150,13 @@ pub fn print_diagnostics(diagnostics: &Vec<MistDiagnostic>) {
|
|||||||
println!(
|
println!(
|
||||||
"\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
"\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line + 1,
|
msg.line,
|
||||||
msg.column,
|
msg.column,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),
|
line.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
MistDiagnostic::Rust(rs) => println!("{rs}"),
|
MistDiagnostic::Rust(rs) => println!("{rs}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +170,7 @@ pub fn get_line(
|
|||||||
|
|
||||||
let lines = files.entry(src_path.clone()).or_insert_with(|| {
|
let lines = files.entry(src_path.clone()).or_insert_with(|| {
|
||||||
fs::read_to_string(src_path)
|
fs::read_to_string(src_path)
|
||||||
.unwrap()
|
.expect("Unable to read mist file")
|
||||||
.lines()
|
.lines()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
|
|||||||
Reference in New Issue
Block a user