@@ -28,7 +28,8 @@ use rustc::hir::def_id::DefId;
2828use rustc:: ty:: { self , TyCtxt } ;
2929use rustc_data_structures:: fx:: FxHashSet ;
3030
31- use std:: path:: Path ;
31+ use std:: path:: { Path , PathBuf } ;
32+ use std:: env;
3233
3334use syntax:: ast:: { self , Attribute , NodeId , PatKind , CRATE_NODE_ID } ;
3435use syntax:: parse:: token;
@@ -49,8 +50,10 @@ use json_dumper::{Access, DumpOutput, JsonDumper};
4950use span_utils:: SpanUtils ;
5051use sig;
5152
52- use rls_data:: { CratePreludeData , Def , DefKind , GlobalCrateId , Import , ImportKind , Ref , RefKind ,
53- Relation , RelationKind , SpanData } ;
53+ use rls_data:: {
54+ CompilationOptions , CratePreludeData , Def , DefKind , GlobalCrateId , Import , ImportKind , Ref ,
55+ RefKind , Relation , RelationKind , SpanData ,
56+ } ;
5457
5558macro_rules! down_cast_data {
5659 ( $id: ident, $kind: ident, $sp: expr) => {
@@ -169,6 +172,61 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
169172 self . dumper . crate_prelude ( data) ;
170173 }
171174
175+ pub fn dump_compilation_options ( & mut self ) {
176+ // Apply possible `remap-path-prefix` remapping to the raw invocation
177+ let invocation = {
178+ let remap_arg_indices = {
179+ let mut indices = FxHashSet ( ) ;
180+ for ( i, e) in env:: args ( ) . enumerate ( ) {
181+ if e. starts_with ( "--remap-path-prefix=" ) {
182+ indices. insert ( i) ;
183+ } else if e == "--remap-path-prefix" {
184+ indices. insert ( i) ;
185+ indices. insert ( i + 1 ) ;
186+ }
187+ }
188+ indices
189+ } ;
190+
191+ let args_without_remap_args = env:: args ( )
192+ . enumerate ( )
193+ . filter ( |( i, _) | !remap_arg_indices. contains ( i) )
194+ . map ( |( _, e) | e) ;
195+
196+ let mapping = self . tcx . sess . source_map ( ) . path_mapping ( ) ;
197+ let remap_arg = |x : & str | -> String {
198+ mapping. map_prefix ( PathBuf :: from ( x) ) . 0 . to_str ( ) . unwrap ( ) . to_owned ( )
199+ } ;
200+
201+ // Naively attempt to remap every argument
202+ let args = args_without_remap_args
203+ . map ( |elem| {
204+ let mut arg = elem. splitn ( 2 , '=' ) ;
205+ match ( arg. next ( ) , arg. next ( ) ) {
206+ // Apart from `--remap...`, in `a=b` args usually only
207+ // `b` is a path (e.g. `--extern some_crate=/path/to..`)
208+ ( Some ( a) , Some ( b) ) => format ! ( "{}={}" , a, remap_arg( b) ) ,
209+ ( Some ( a) , _) => remap_arg ( a) ,
210+ _ => unreachable ! ( ) ,
211+ }
212+ } ) . collect :: < Vec < _ > > ( ) ;
213+
214+ args. as_slice ( ) . join ( " " )
215+ } ;
216+
217+ let opts = & self . tcx . sess . opts ;
218+
219+ let data = CompilationOptions {
220+ invocation,
221+ crate_name : opts. crate_name . clone ( ) ,
222+ test : opts. test ,
223+ sysroot : opts. maybe_sysroot . clone ( ) ,
224+ target_triple : opts. target_triple . to_string ( ) ,
225+ } ;
226+
227+ self . dumper . compilation_opts ( data) ;
228+ }
229+
172230 // Return all non-empty prefixes of a path.
173231 // For each prefix, we return the span for the last segment in the prefix and
174232 // a str representation of the entire prefix.
0 commit comments