@@ -119,6 +119,11 @@ fn documentation_for_definition(
119
119
def. docs ( sema. db , famous_defs. as_ref ( ) )
120
120
}
121
121
122
+ pub enum VendoredLibrariesConfig < ' a > {
123
+ Included { workspace_root : & ' a VfsPath } ,
124
+ Excluded ,
125
+ }
126
+
122
127
impl StaticIndex < ' _ > {
123
128
fn add_file ( & mut self , file_id : FileId ) {
124
129
let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -230,15 +235,22 @@ impl StaticIndex<'_> {
230
235
self . files . push ( result) ;
231
236
}
232
237
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 > {
234
242
let db = & * analysis. db ;
235
243
let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
236
244
let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
237
245
let source_root = db. file_source_root ( file_id. into ( ) ) ;
238
246
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
+
242
254
!source_root. is_library || is_vendored
243
255
} ) ;
244
256
let mut this = StaticIndex {
@@ -268,10 +280,11 @@ mod tests {
268
280
use ide_db:: { base_db:: VfsPath , FileRange , FxHashSet } ;
269
281
use syntax:: TextSize ;
270
282
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 < ' _ > ) {
272
286
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) ;
275
288
let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
276
289
for f in s. files {
277
290
for ( range, _) in f. tokens {
@@ -288,10 +301,9 @@ mod tests {
288
301
}
289
302
290
303
#[ track_caller]
291
- fn check_definitions ( ra_fixture : & str ) {
304
+ fn check_definitions ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
292
305
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) ;
295
307
let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
296
308
for ( _, t) in s. tokens . iter ( ) {
297
309
if let Some ( t) = t. definition {
@@ -319,6 +331,9 @@ struct Foo;
319
331
enum E { X(Foo) }
320
332
//^ ^ ^^^
321
333
"# ,
334
+ VendoredLibrariesConfig :: Included {
335
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
336
+ } ,
322
337
) ;
323
338
check_definitions (
324
339
r#"
@@ -327,6 +342,9 @@ struct Foo;
327
342
enum E { X(Foo) }
328
343
//^ ^
329
344
"# ,
345
+ VendoredLibrariesConfig :: Included {
346
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
347
+ } ,
330
348
) ;
331
349
}
332
350
@@ -349,6 +367,9 @@ pub func() {
349
367
350
368
}
351
369
"# ,
370
+ VendoredLibrariesConfig :: Included {
371
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
372
+ } ,
352
373
) ;
353
374
}
354
375
@@ -367,9 +388,30 @@ struct ExternalLibrary(i32);
367
388
struct VendoredLibrary(i32);
368
389
//^^^^^^^^^^^^^^^ ^^^
369
390
"# ,
391
+ VendoredLibrariesConfig :: Included {
392
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
393
+ } ,
370
394
) ;
371
395
}
372
396
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:[email protected] ,https://a.b/foo.git library
406
+ struct ExternalLibrary(i32);
407
+
408
+ //- /workspace/vendored/lib.rs new_source_root:library crate:[email protected] ,https://a.b/bar.git library
409
+ struct VendoredLibrary(i32);
410
+ "# ,
411
+ VendoredLibrariesConfig :: Excluded ,
412
+ )
413
+ }
414
+
373
415
#[ test]
374
416
fn derives ( ) {
375
417
check_all_ranges (
@@ -384,6 +426,9 @@ pub macro Copy {}
384
426
struct Hello(i32);
385
427
//^^^^^ ^^^
386
428
"# ,
429
+ VendoredLibrariesConfig :: Included {
430
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
431
+ } ,
387
432
) ;
388
433
}
389
434
}
0 commit comments