mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Introduce Location and make SyntaxError fields private
This commit is contained in:
parent
3b42ddae60
commit
fda8ddc5fe
10 changed files with 82 additions and 52 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: err.range,
|
||||
msg: format!("Syntax Error: {}", err.kind),
|
||||
range: location_to_range(err.location()),
|
||||
msg: format!("Syntax Error: {}", err),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue