11use std:: {
2+ collections:: { HashMap , HashSet } ,
23 iter,
34 ops:: { Bound , Range } ,
45} ;
@@ -35,6 +36,10 @@ pub struct FreeFunctions;
3536
3637pub struct RaSpanServer {
3738 pub ( crate ) interner : SymbolInternerRef ,
39+ // FIXME: Report this back to the caller to track as dependencies
40+ pub tracked_env_vars : HashMap < Box < str > , Option < Box < str > > > ,
41+ // FIXME: Report this back to the caller to track as dependencies
42+ pub tracked_paths : HashSet < Box < str > > ,
3843 pub call_site : Span ,
3944 pub def_site : Span ,
4045 pub mixed_site : Span ,
@@ -49,11 +54,12 @@ impl server::Types for RaSpanServer {
4954}
5055
5156impl server:: FreeFunctions for RaSpanServer {
52- fn track_env_var ( & mut self , _var : & str , _value : Option < & str > ) {
53- // FIXME: track env var accesses
54- // https://github.com/rust-lang/rust/pull/71858
57+ fn track_env_var ( & mut self , var : & str , value : Option < & str > ) {
58+ self . tracked_env_vars . insert ( var. into ( ) , value. map ( Into :: into) ) ;
59+ }
60+ fn track_path ( & mut self , path : & str ) {
61+ self . tracked_paths . insert ( path. into ( ) ) ;
5562 }
56- fn track_path ( & mut self , _path : & str ) { }
5763
5864 fn literal_from_str (
5965 & mut self ,
@@ -247,24 +253,38 @@ impl server::Span for RaSpanServer {
247253 /// See PR:
248254 /// https://github.com/rust-lang/rust/pull/55780
249255 fn source_text ( & mut self , _span : Self :: Span ) -> Option < String > {
256+ // FIXME requires db
250257 None
251258 }
252259
253260 fn parent ( & mut self , _span : Self :: Span ) -> Option < Self :: Span > {
254- // FIXME handle span
261+ // FIXME requires db, looks up the parent call site
255262 None
256263 }
257264 fn source ( & mut self , span : Self :: Span ) -> Self :: Span {
258- // FIXME handle span
265+ // FIXME requires db, returns the top level call site
259266 span
260267 }
261- fn byte_range ( & mut self , _span : Self :: Span ) -> Range < usize > {
262- // FIXME handle span
263- Range { start : 0 , end : 0 }
268+ fn byte_range ( & mut self , span : Self :: Span ) -> Range < usize > {
269+ // FIXME requires db to resolve the ast id, THIS IS NOT INCREMENTAL
270+ Range { start : span . range . start ( ) . into ( ) , end : span . range . end ( ) . into ( ) }
264271 }
265- fn join ( & mut self , first : Self :: Span , _second : Self :: Span ) -> Option < Self :: Span > {
266- // Just return the first span again, because some macros will unwrap the result.
267- Some ( first)
272+ fn join ( & mut self , first : Self :: Span , second : Self :: Span ) -> Option < Self :: Span > {
273+ if first. anchor != second. anchor {
274+ return None ;
275+ }
276+ if first. ctx != second. ctx {
277+ if first. ctx . is_root ( ) {
278+ return Some ( second) ;
279+ } else if second. ctx . is_root ( ) {
280+ return Some ( first) ;
281+ }
282+ }
283+ Some ( Span {
284+ range : first. range . cover ( second. range ) ,
285+ anchor : second. anchor ,
286+ ctx : second. ctx ,
287+ } )
268288 }
269289 fn subspan (
270290 & mut self ,
0 commit comments