perspt_coding/diag/
tsc.rs1use super::types::StructuredDiagnostic;
8use crate::lang::classify_ts_code;
9
10pub const PARSER_ID: &str = "tsc-text-v1";
12
13pub fn parse(raw: &str) -> Vec<StructuredDiagnostic> {
15 raw.lines().filter_map(parse_line).collect()
16}
17
18fn parse_line(line: &str) -> Option<StructuredDiagnostic> {
19 let marker = line.find(": error TS")?;
21 let (location, rest) = line.split_at(marker);
22 let rest = &rest[": error ".len()..];
23 let (code, message) = rest.split_once(": ")?;
24 let (path, position) = location.rsplit_once('(')?;
25 let position = position.strip_suffix(')')?;
26 let (line_no, column) = position.split_once(',')?;
27 Some(StructuredDiagnostic {
28 class: classify_ts_code(code),
29 code: Some(code.to_string()),
30 message: message.to_string(),
31 path: Some(path.to_string()),
32 line: line_no.trim().parse().ok(),
33 column: column.trim().parse().ok(),
34 primary: true,
35 suggestion: None,
36 })
37}