Skip to content

Commit 91b5ed5

Browse files
committed
save-analysis-json: introduce a lowering step
...in which we make the spans nice.
1 parent e7b8c5e commit 91b5ed5

File tree

2 files changed

+607
-9
lines changed

2 files changed

+607
-9
lines changed

src/librustc_save_analysis/data.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,37 @@ use std::hash::Hasher;
1818
use rustc::hir::def_id::DefId;
1919
use rustc::ty;
2020
use syntax::ast::{CrateNum, NodeId};
21-
use syntax::codemap::Span;
21+
use syntax::codemap::{Span, CodeMap};
22+
23+
#[derive(Debug, Clone, RustcEncodable)]
24+
pub struct SpanData {
25+
file_name: String,
26+
byte_start: u32,
27+
byte_end: u32,
28+
/// 1-based.
29+
line_start: usize,
30+
line_end: usize,
31+
/// 1-based, character offset.
32+
column_start: usize,
33+
column_end: usize,
34+
}
35+
36+
impl SpanData {
37+
pub fn from_span(span: Span, cm: &CodeMap) -> SpanData {
38+
let start = cm.lookup_char_pos(span.lo);
39+
let end = cm.lookup_char_pos(span.hi);
40+
41+
SpanData {
42+
file_name: start.file.name.clone(),
43+
byte_start: span.lo.0,
44+
byte_end: span.hi.0,
45+
line_start: start.line,
46+
line_end: end.line,
47+
column_start: start.col.0 + 1,
48+
column_end: end.col.0 + 1,
49+
}
50+
}
51+
}
2252

2353
pub struct CrateData {
2454
pub name: String,

0 commit comments

Comments
 (0)