188: Introduce `SyntaxErrorKind` and `TextRange` to `SyntaxError` r=matklad a=aochagavia



Co-authored-by: Adolfo Ochagavía <aochagavia92@gmail.com>
Co-authored-by: Adolfo Ochagavía <github@adolfo.ochagavia.xyz>
This commit is contained in:
bors[bot] 2018-11-05 21:32:25 +00:00
commit f605f6e70a
11 changed files with 197 additions and 72 deletions

View file

@ -31,6 +31,7 @@ use ra_syntax::{
algo::find_leaf_at_offset,
ast::{self, AstNode, NameOwner},
File,
Location,
SyntaxKind::{self, *},
SyntaxNodeRef, TextRange, TextUnit,
};
@ -100,11 +101,18 @@ pub fn highlight(file: &File) -> Vec<HighlightedRange> {
}
pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
fn location_to_range(location: Location) -> TextRange {
match location {
Location::Offset(offset) => TextRange::offset_len(offset, 1.into()),
Location::Range(range) => range,
}
}
file.errors()
.into_iter()
.map(|err| Diagnostic {
range: TextRange::offset_len(err.offset, 1.into()),
msg: "Syntax Error: ".to_string() + &err.msg,
range: location_to_range(err.location()),
msg: format!("Syntax Error: {}", err),
})
.collect()
}