@@ -119,6 +119,11 @@ fn documentation_for_definition(
119119 def. docs ( sema. db , famous_defs. as_ref ( ) )
120120}
121121
122+ pub enum VendoredLibrariesConfig < ' a > {
123+ Included { workspace_root : & ' a VfsPath } ,
124+ Excluded ,
125+ }
126+
122127impl StaticIndex < ' _ > {
123128 fn add_file ( & mut self , file_id : FileId ) {
124129 let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -230,15 +235,22 @@ impl StaticIndex<'_> {
230235 self . files . push ( result) ;
231236 }
232237
233- pub fn compute < ' a > ( analysis : & ' a Analysis , workspace_root : & VfsPath ) -> StaticIndex < ' a > {
238+ pub fn compute < ' a > (
239+ analysis : & ' a Analysis ,
240+ vendored_libs_config : VendoredLibrariesConfig < ' _ > ,
241+ ) -> StaticIndex < ' a > {
234242 let db = & * analysis. db ;
235243 let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
236244 let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
237245 let source_root = db. file_source_root ( file_id. into ( ) ) ;
238246 let source_root = db. source_root ( source_root) ;
239- let is_vendored = source_root
240- . path_for_file ( & file_id. into ( ) )
241- . is_some_and ( |module_path| module_path. starts_with ( workspace_root) ) ;
247+ let is_vendored = match vendored_libs_config {
248+ VendoredLibrariesConfig :: Included { workspace_root } => source_root
249+ . path_for_file ( & file_id. into ( ) )
250+ . is_some_and ( |module_path| module_path. starts_with ( workspace_root) ) ,
251+ VendoredLibrariesConfig :: Excluded => false ,
252+ } ;
253+
242254 !source_root. is_library || is_vendored
243255 } ) ;
244256 let mut this = StaticIndex {
@@ -268,10 +280,11 @@ mod tests {
268280 use ide_db:: { base_db:: VfsPath , FileRange , FxHashSet } ;
269281 use syntax:: TextSize ;
270282
271- fn check_all_ranges ( ra_fixture : & str ) {
283+ use super :: VendoredLibrariesConfig ;
284+
285+ fn check_all_ranges ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
272286 let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
273- let s =
274- StaticIndex :: compute ( & analysis, & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ) ;
287+ let s = StaticIndex :: compute ( & analysis, vendored_libs_config) ;
275288 let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
276289 for f in s. files {
277290 for ( range, _) in f. tokens {
@@ -288,10 +301,9 @@ mod tests {
288301 }
289302
290303 #[ track_caller]
291- fn check_definitions ( ra_fixture : & str ) {
304+ fn check_definitions ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
292305 let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
293- let s =
294- StaticIndex :: compute ( & analysis, & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ) ;
306+ let s = StaticIndex :: compute ( & analysis, vendored_libs_config) ;
295307 let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
296308 for ( _, t) in s. tokens . iter ( ) {
297309 if let Some ( t) = t. definition {
@@ -319,6 +331,9 @@ struct Foo;
319331enum E { X(Foo) }
320332 //^ ^ ^^^
321333"# ,
334+ VendoredLibrariesConfig :: Included {
335+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
336+ } ,
322337 ) ;
323338 check_definitions (
324339 r#"
@@ -327,6 +342,9 @@ struct Foo;
327342enum E { X(Foo) }
328343 //^ ^
329344"# ,
345+ VendoredLibrariesConfig :: Included {
346+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
347+ } ,
330348 ) ;
331349 }
332350
@@ -349,6 +367,9 @@ pub func() {
349367
350368}
351369"# ,
370+ VendoredLibrariesConfig :: Included {
371+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
372+ } ,
352373 ) ;
353374 }
354375
@@ -367,9 +388,30 @@ struct ExternalLibrary(i32);
367388struct VendoredLibrary(i32);
368389 //^^^^^^^^^^^^^^^ ^^^
369390"# ,
391+ VendoredLibrariesConfig :: Included {
392+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
393+ } ,
370394 ) ;
371395 }
372396
397+ #[ test]
398+ fn vendored_crate_excluded ( ) {
399+ check_all_ranges (
400+ r#"
401+ //- /workspace/main.rs crate:main deps:external,vendored
402+ struct Main(i32);
403+ //^^^^ ^^^
404+
405+ //- /external/lib.rs new_source_root:library crate:external@0.1.0,https://a.b/foo.git library
406+ struct ExternalLibrary(i32);
407+
408+ //- /workspace/vendored/lib.rs new_source_root:library crate:vendored@0.1.0,https://a.b/bar.git library
409+ struct VendoredLibrary(i32);
410+ "# ,
411+ VendoredLibrariesConfig :: Excluded ,
412+ )
413+ }
414+
373415 #[ test]
374416 fn derives ( ) {
375417 check_all_ranges (
@@ -384,6 +426,9 @@ pub macro Copy {}
384426struct Hello(i32);
385427 //^^^^^ ^^^
386428"# ,
429+ VendoredLibrariesConfig :: Included {
430+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
431+ } ,
387432 ) ;
388433 }
389434}
0 commit comments