-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cc16f3
commit 4776b96
Showing
6 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "selene" | ||
version = "0.9.0" | ||
version = "0.9.1" | ||
license = "MPL-2.0" | ||
authors = ["Kampfkarren <[email protected]>"] | ||
description = "A blazing-fast modern Lua linter written in Rust" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use codespan_reporting::diagnostic::{ | ||
Diagnostic as CodespanDiagnostic, Label as CodespanLabel, LabelStyle, Severity, | ||
}; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
struct JsonDiagnostic { | ||
severity: Severity, | ||
code: Option<String>, | ||
message: String, | ||
primary_label: Label, | ||
notes: Vec<String>, | ||
secondary_labels: Vec<Label>, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct Label { | ||
span: Span, | ||
message: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct Span { | ||
start: usize, | ||
end: usize, | ||
} | ||
|
||
fn label_to_serializable<T>(label: &CodespanLabel<T>) -> Label { | ||
Label { | ||
message: label.message.to_owned(), | ||
span: Span { | ||
start: label.range.start, | ||
end: label.range.end, | ||
}, | ||
} | ||
} | ||
|
||
pub fn diagnostic_to_json( | ||
diagnostic: &CodespanDiagnostic<codespan::FileId>, | ||
) -> serde_json::Result<String> { | ||
serde_json::to_string(&JsonDiagnostic { | ||
code: diagnostic.code.to_owned(), | ||
message: diagnostic.message.to_owned(), | ||
severity: diagnostic.severity.to_owned(), | ||
notes: diagnostic.notes.to_owned(), | ||
primary_label: label_to_serializable(diagnostic.labels.first().expect("no labels passed")), | ||
secondary_labels: diagnostic | ||
.labels | ||
.iter() | ||
.filter(|label| label.style == LabelStyle::Secondary) | ||
.map(label_to_serializable) | ||
.collect(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters