mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Merge #188
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:
commit
f605f6e70a
11 changed files with 197 additions and 72 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue