@@ -124,6 +124,11 @@ fn documentation_for_definition(
124124 )
125125}
126126
127+ pub enum VendoredLibrariesConfig < ' a > {
128+ Included { workspace_root : & ' a VfsPath } ,
129+ Excluded ,
130+ }
131+
127132impl StaticIndex < ' _ > {
128133 fn add_file ( & mut self , file_id : FileId ) {
129134 let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -240,15 +245,22 @@ impl StaticIndex<'_> {
240245 self . files . push ( result) ;
241246 }
242247
243- pub fn compute < ' a > ( analysis : & ' a Analysis , workspace_root : & VfsPath ) -> StaticIndex < ' a > {
248+ pub fn compute < ' a > (
249+ analysis : & ' a Analysis ,
250+ vendored_libs_config : VendoredLibrariesConfig < ' _ > ,
251+ ) -> StaticIndex < ' a > {
244252 let db = & * analysis. db ;
245253 let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
246254 let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
247255 let source_root = db. file_source_root ( file_id. into ( ) ) ;
248256 let source_root = db. source_root ( source_root) ;
249- let is_vendored = source_root
250- . path_for_file ( & file_id. into ( ) )
251- . is_some_and ( |module_path| module_path. starts_with ( workspace_root) ) ;
257+ let is_vendored = match vendored_libs_config {
258+ VendoredLibrariesConfig :: Included { workspace_root } => source_root
259+ . path_for_file ( & file_id. into ( ) )
260+ . is_some_and ( |module_path| module_path. starts_with ( workspace_root) ) ,
261+ VendoredLibrariesConfig :: Excluded => false ,
262+ } ;
263+
252264 !source_root. is_library || is_vendored
253265 } ) ;
254266 let mut this = StaticIndex {
@@ -278,10 +290,11 @@ mod tests {
278290 use ide_db:: { base_db:: VfsPath , FileRange , FxHashSet } ;
279291 use syntax:: TextSize ;
280292
281- fn check_all_ranges ( ra_fixture : & str ) {
293+ use super :: VendoredLibrariesConfig ;
294+
295+ fn check_all_ranges ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
282296 let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
283- let s =
284- StaticIndex :: compute ( & analysis, & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ) ;
297+ let s = StaticIndex :: compute ( & analysis, vendored_libs_config) ;
285298 let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
286299 for f in s. files {
287300 for ( range, _) in f. tokens {
@@ -298,10 +311,9 @@ mod tests {
298311 }
299312
300313 #[ track_caller]
301- fn check_definitions ( ra_fixture : & str ) {
314+ fn check_definitions ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
302315 let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
303- let s =
304- StaticIndex :: compute ( & analysis, & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ) ;
316+ let s = StaticIndex :: compute ( & analysis, vendored_libs_config) ;
305317 let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
306318 for ( _, t) in s. tokens . iter ( ) {
307319 if let Some ( t) = t. definition {
@@ -329,6 +341,9 @@ struct Foo;
329341enum E { X(Foo) }
330342 //^ ^ ^^^
331343"# ,
344+ VendoredLibrariesConfig :: Included {
345+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
346+ } ,
332347 ) ;
333348 check_definitions (
334349 r#"
@@ -337,6 +352,9 @@ struct Foo;
337352enum E { X(Foo) }
338353 //^ ^
339354"# ,
355+ VendoredLibrariesConfig :: Included {
356+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
357+ } ,
340358 ) ;
341359 }
342360
@@ -359,6 +377,9 @@ pub func() {
359377
360378}
361379"# ,
380+ VendoredLibrariesConfig :: Included {
381+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
382+ } ,
362383 ) ;
363384 }
364385
@@ -377,9 +398,30 @@ struct ExternalLibrary(i32);
377398struct VendoredLibrary(i32);
378399 //^^^^^^^^^^^^^^^ ^^^
379400"# ,
401+ VendoredLibrariesConfig :: Included {
402+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
403+ } ,
380404 ) ;
381405 }
382406
407+ #[ test]
408+ fn vendored_crate_excluded ( ) {
409+ check_all_ranges (
410+ r#"
411+ //- /workspace/main.rs crate:main deps:external,vendored
412+ struct Main(i32);
413+ //^^^^ ^^^
414+
415+ //- /external/lib.rs new_source_root:library crate:external@0.1.0,https://a.b/foo.git library
416+ struct ExternalLibrary(i32);
417+
418+ //- /workspace/vendored/lib.rs new_source_root:library crate:vendored@0.1.0,https://a.b/bar.git library
419+ struct VendoredLibrary(i32);
420+ "# ,
421+ VendoredLibrariesConfig :: Excluded ,
422+ )
423+ }
424+
383425 #[ test]
384426 fn derives ( ) {
385427 check_all_ranges (
@@ -394,6 +436,9 @@ pub macro Copy {}
394436struct Hello(i32);
395437 //^^^^^ ^^^
396438"# ,
439+ VendoredLibrariesConfig :: Included {
440+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
441+ } ,
397442 ) ;
398443 }
399444}
0 commit comments