Skip to content

Commit b6b5a72

Browse files
committed
feat: added diagnostic conversioné
1 parent 0104e32 commit b6b5a72

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lsp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2024"
66
[dependencies]
77
tower-lsp = "0.20"
88
tokio = { version = "1", features = ["full"] }
9+
diagnostics = { path = "../compiler/diagnostics" }

lsp/src/diags.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use diagnostics::diagnostic::Level;
2+
use tower_lsp::lsp_types::{
3+
Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Location, Position, Range, Url,
4+
};
5+
6+
pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnostic {
7+
let severity = match diagnostic.level {
8+
Level::Error => DiagnosticSeverity::ERROR,
9+
Level::Warning => DiagnosticSeverity::WARNING,
10+
Level::Note => DiagnosticSeverity::INFORMATION,
11+
};
12+
13+
let mut related_info = vec![];
14+
15+
for span in diagnostic.spans {
16+
related_info.push(DiagnosticRelatedInformation {
17+
location: Location {
18+
uri: Url::parse(&span.start.file_path).unwrap(),
19+
range: Range {
20+
start: Position::new(span.start.line as u32, span.start.col as u32),
21+
end: Position::new(span.start.line as u32, span.start.end_col as u32),
22+
},
23+
},
24+
message: span.label.unwrap().into(),
25+
});
26+
}
27+
28+
let main_range = Range {
29+
start: Position::new(
30+
diagnostic.primary_span.start.line as u32,
31+
diagnostic.primary_span.start.col as u32,
32+
),
33+
end: Position::new(
34+
diagnostic.primary_span.start.line as u32,
35+
diagnostic.primary_span.start.end_col as u32,
36+
),
37+
};
38+
39+
Diagnostic {
40+
range: main_range,
41+
message: diagnostic.primary_span.label.unwrap(),
42+
severity: Some(severity),
43+
related_information: Some(related_info),
44+
45+
..Default::default()
46+
}
47+
}

lsp/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod diags;
12
pub mod lsp;
23

34
fn main() {}

0 commit comments

Comments
 (0)