use rustc::hir::def::Def as HirDef;
use rustc::hir::def_id::DefId;
+use rustc::session::config::Input;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashSet;
use std::path::Path;
+use std::env;
use syntax::ast::{self, Attribute, NodeId, PatKind, CRATE_NODE_ID};
use syntax::parse::token;
use span_utils::SpanUtils;
use sig;
-use rls_data::{CratePreludeData, Def, DefKind, GlobalCrateId, Import, ImportKind, Ref, RefKind,
- Relation, RelationKind, SpanData};
+use rls_data::{CompilationOptions, CratePreludeData, Def, DefKind, GlobalCrateId, Import,
+ ImportKind, Ref, RefKind, Relation, RelationKind, SpanData};
macro_rules! down_cast_data {
($id:ident, $kind:ident, $sp:expr) => {
self.dumper.crate_prelude(data);
}
+ pub fn dump_compilation_options(&mut self, input: &Input, crate_name: &str) {
+ // Apply possible `remap-path-prefix` remapping to the input source file
+ // (and don't include remapping args anymore)
+ let (program, arguments) = {
+ let remap_arg_indices = {
+ let mut indices = FxHashSet();
+ // Args are guaranteed to be valid UTF-8 (checked early)
+ for (i, e) in env::args().enumerate() {
+ if e.starts_with("--remap-path-prefix=") {
+ indices.insert(i);
+ } else if e == "--remap-path-prefix" {
+ indices.insert(i);
+ indices.insert(i + 1);
+ }
+ }
+ indices
+ };
+
+ let mut args = env::args()
+ .enumerate()
+ .filter(|(i, _)| !remap_arg_indices.contains(i))
+ .map(|(_, arg)| {
+ match input {
+ Input::File(ref path) if path == Path::new(&arg) => {
+ let mapped = &self.tcx.sess.local_crate_source_file;
+ mapped
+ .as_ref()
+ .unwrap()
+ .to_string_lossy()
+ .into()
+ },
+ _ => arg,
+ }
+ });
+
+ (args.next().unwrap(), args.collect())
+ };
+
+ let data = CompilationOptions {
+ directory: self.tcx.sess.working_dir.0.clone(),
+ program,
+ arguments,
+ output: self.save_ctxt.compilation_output(crate_name),
+ };
+
+ self.dumper.compilation_opts(data);
+ }
+
// Return all non-empty prefixes of a path.
// For each prefix, we return the span for the last segment in the prefix and
// a str representation of the entire prefix.