提交 e3afba5b 编写于 作者: I Igor Matuszewski

Emit crate disambiguators in save-analysis data

上级 f7b080b3
...@@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" } ...@@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_typeck = { path = "../librustc_typeck" } rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" } syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" } syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.11" rls-data = { git = "https://github.com/Xanewok/rls-data", branch = "crate-source" }
rls-span = "0.4" rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree # FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3" rustc-serialize = "0.3"
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
use span_utils::SpanUtils; use span_utils::SpanUtils;
use sig; use sig;
use rls_data::{CratePreludeData, Import, ImportKind, SpanData, Ref, RefKind, use rls_data::{CratePreludeData, GlobalCrateId, Import, ImportKind, SpanData,
Def, DefKind, Relation, RelationKind}; Ref, RefKind, Def, DefKind, Relation, RelationKind};
macro_rules! down_cast_data { macro_rules! down_cast_data {
($id:ident, $kind:ident, $sp:expr) => { ($id:ident, $kind:ident, $sp:expr) => {
...@@ -131,7 +131,10 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) { ...@@ -131,7 +131,10 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
}); });
let data = CratePreludeData { let data = CratePreludeData {
crate_name: name.into(), crate_id: GlobalCrateId {
name: name.into(),
disambiguator: self.tcx.sess.local_crate_disambiguator().to_string(),
},
crate_root: crate_root.unwrap_or("<no source>".to_owned()), crate_root: crate_root.unwrap_or("<no source>".to_owned()),
external_crates: self.save_ctxt.get_external_crates(), external_crates: self.save_ctxt.get_external_crates(),
span: self.span_from_span(krate.span), span: self.span_from_span(krate.span),
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
use span_utils::SpanUtils; use span_utils::SpanUtils;
use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind, use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind,
ExternalCrateData}; ExternalCrateData, GlobalCrateId};
use rls_data::config::Config; use rls_data::config::Config;
...@@ -82,10 +82,6 @@ pub enum Data { ...@@ -82,10 +82,6 @@ pub enum Data {
RelationData(Relation), RelationData(Relation),
} }
macro_rules! option_try(
($e:expr) => (match $e { Some(e) => e, None => return None })
);
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
fn span_from_span(&self, span: Span) -> SpanData { fn span_from_span(&self, span: Span) -> SpanData {
use rls_span::{Row, Column}; use rls_span::{Row, Column};
...@@ -119,9 +115,12 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> { ...@@ -119,9 +115,12 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
}; };
let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo()); let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo());
result.push(ExternalCrateData { result.push(ExternalCrateData {
name: self.tcx.crate_name(n).to_string(),
num: n.as_u32(),
file_name: SpanUtils::make_path_string(&lo_loc.file.name), file_name: SpanUtils::make_path_string(&lo_loc.file.name),
num: n.as_u32(),
id: GlobalCrateId {
name: self.tcx.crate_name(n).to_string(),
disambiguator: self.tcx.crate_disambiguator(n).to_string(),
},
}); });
} }
...@@ -725,8 +724,8 @@ pub fn get_macro_use_data(&self, span: Span) -> Option<MacroRef> { ...@@ -725,8 +724,8 @@ pub fn get_macro_use_data(&self, span: Span) -> Option<MacroRef> {
// macro uses. // macro uses.
let callsite = span.source_callsite(); let callsite = span.source_callsite();
let callsite_span = self.span_from_span(callsite); let callsite_span = self.span_from_span(callsite);
let callee = option_try!(span.source_callee()); let callee = span.source_callee()?;
let callee_span = option_try!(callee.span); let callee_span = callee.span?;
// Ignore attribute macros, their spans are usually mangled // Ignore attribute macros, their spans are usually mangled
if let MacroAttribute(_) = callee.format { if let MacroAttribute(_) = callee.format {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册