use super::types::StructuredDiagnostic;
use crate::lang::classify_ts_code;
pub const PARSER_ID: &str = "tsc-text-v1";
pub fn parse(raw: &str) -> Vec<StructuredDiagnostic> {
raw.lines().filter_map(parse_line).collect()
}
fn parse_line(line: &str) -> Option<StructuredDiagnostic> {
let marker = line.find(": error TS")?;
let (location, rest) = line.split_at(marker);
let rest = &rest[": error ".len()..];
let (code, message) = rest.split_once(": ")?;
let (path, position) = location.rsplit_once('(')?;
let position = position.strip_suffix(')')?;
let (line_no, column) = position.split_once(',')?;
Some(StructuredDiagnostic {
class: classify_ts_code(code),
code: Some(code.to_string()),
message: message.to_string(),
path: Some(path.to_string()),
line: line_no.trim().parse().ok(),
column: column.trim().parse().ok(),
primary: true,
suggestion: None,
})
}