@@ -124,6 +124,11 @@ fn documentation_for_definition(
124
124
)
125
125
}
126
126
127
+ pub enum VendoredLibrariesConfig < ' a > {
128
+ Included { workspace_root : & ' a VfsPath } ,
129
+ Excluded ,
130
+ }
131
+
127
132
impl StaticIndex < ' _ > {
128
133
fn add_file ( & mut self , file_id : FileId ) {
129
134
let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -240,15 +245,22 @@ impl StaticIndex<'_> {
240
245
self . files . push ( result) ;
241
246
}
242
247
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 > {
244
252
let db = & * analysis. db ;
245
253
let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
246
254
let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
247
255
let source_root = db. file_source_root ( file_id. into ( ) ) ;
248
256
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
+
252
264
!source_root. is_library || is_vendored
253
265
} ) ;
254
266
let mut this = StaticIndex {
@@ -278,10 +290,11 @@ mod tests {
278
290
use ide_db:: { base_db:: VfsPath , FileRange , FxHashSet } ;
279
291
use syntax:: TextSize ;
280
292
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 < ' _ > ) {
282
296
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) ;
285
298
let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
286
299
for f in s. files {
287
300
for ( range, _) in f. tokens {
@@ -298,10 +311,9 @@ mod tests {
298
311
}
299
312
300
313
#[ track_caller]
301
- fn check_definitions ( ra_fixture : & str ) {
314
+ fn check_definitions ( ra_fixture : & str , vendored_libs_config : VendoredLibrariesConfig < ' _ > ) {
302
315
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) ;
305
317
let mut range_set: FxHashSet < _ > = ranges. iter ( ) . map ( |it| it. 0 ) . collect ( ) ;
306
318
for ( _, t) in s. tokens . iter ( ) {
307
319
if let Some ( t) = t. definition {
@@ -329,6 +341,9 @@ struct Foo;
329
341
enum E { X(Foo) }
330
342
//^ ^ ^^^
331
343
"# ,
344
+ VendoredLibrariesConfig :: Included {
345
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
346
+ } ,
332
347
) ;
333
348
check_definitions (
334
349
r#"
@@ -337,6 +352,9 @@ struct Foo;
337
352
enum E { X(Foo) }
338
353
//^ ^
339
354
"# ,
355
+ VendoredLibrariesConfig :: Included {
356
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
357
+ } ,
340
358
) ;
341
359
}
342
360
@@ -359,6 +377,9 @@ pub func() {
359
377
360
378
}
361
379
"# ,
380
+ VendoredLibrariesConfig :: Included {
381
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
382
+ } ,
362
383
) ;
363
384
}
364
385
@@ -377,9 +398,30 @@ struct ExternalLibrary(i32);
377
398
struct VendoredLibrary(i32);
378
399
//^^^^^^^^^^^^^^^ ^^^
379
400
"# ,
401
+ VendoredLibrariesConfig :: Included {
402
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
403
+ } ,
380
404
) ;
381
405
}
382
406
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
+
383
425
#[ test]
384
426
fn derives ( ) {
385
427
check_all_ranges (
@@ -394,6 +436,9 @@ pub macro Copy {}
394
436
struct Hello(i32);
395
437
//^^^^^ ^^^
396
438
"# ,
439
+ VendoredLibrariesConfig :: Included {
440
+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
441
+ } ,
397
442
) ;
398
443
}
399
444
}
0 commit comments