@@ -55,20 +55,6 @@ struct Result : public Item {
55
55
return item->getKind () == ItemKind::Result;
56
56
}
57
57
};
58
- class ImportDepth {
59
- llvm::StringMap<uint8_t > depths;
60
-
61
- public:
62
- ImportDepth () = default ;
63
- ImportDepth (ASTContext &context, const CompilerInvocation &invocation);
64
-
65
- Optional<uint8_t > lookup (StringRef module ) {
66
- auto I = depths.find (module );
67
- if (I == depths.end ())
68
- return None;
69
- return I->getValue ();
70
- }
71
- };
72
58
} // end anonymous namespace
73
59
74
60
struct CodeCompletion ::Group : public Item {
@@ -93,7 +79,8 @@ std::vector<Completion *> SourceKit::CodeCompletion::extendCompletions(
93
79
ImportDepth depth;
94
80
if (info.swiftASTContext ) {
95
81
// Build import depth map.
96
- depth = ImportDepth (*info.swiftASTContext , *info.invocation );
82
+ depth = ImportDepth (*info.swiftASTContext ,
83
+ info.invocation ->getFrontendOptions ());
97
84
}
98
85
99
86
if (info.completionContext )
@@ -330,75 +317,6 @@ CodeCompletionViewRef CodeCompletionOrganizer::takeResultsView() {
330
317
return impl.takeView ();
331
318
}
332
319
333
- // ===----------------------------------------------------------------------===//
334
- // ImportDepth
335
- // ===----------------------------------------------------------------------===//
336
-
337
- ImportDepth::ImportDepth (ASTContext &context,
338
- const CompilerInvocation &invocation) {
339
- llvm::DenseSet<ModuleDecl *> seen;
340
- std::deque<std::pair<ModuleDecl *, uint8_t >> worklist;
341
-
342
- StringRef mainModule = invocation.getModuleName ();
343
- auto *main = context.getLoadedModule (context.getIdentifier (mainModule));
344
- assert (main && " missing main module" );
345
- worklist.emplace_back (main, uint8_t (0 ));
346
-
347
- // Imports from -import-name such as Playground auxiliary sources are treated
348
- // specially by applying import depth 0.
349
- llvm::StringSet<> auxImports;
350
- for (const auto &pair :
351
- invocation.getFrontendOptions ().getImplicitImportModuleNames ())
352
- auxImports.insert (pair.first );
353
-
354
- // Private imports from this module.
355
- // FIXME: only the private imports from the current source file.
356
- // FIXME: ImportFilterKind::ShadowedByCrossImportOverlay?
357
- SmallVector<ImportedModule, 16 > mainImports;
358
- main->getImportedModules (mainImports,
359
- {ModuleDecl::ImportFilterKind::Default,
360
- ModuleDecl::ImportFilterKind::ImplementationOnly});
361
- for (auto &import : mainImports) {
362
- uint8_t depth = 1 ;
363
- if (auxImports.count (import .importedModule ->getName ().str ()))
364
- depth = 0 ;
365
- worklist.emplace_back (import .importedModule , depth);
366
- }
367
-
368
- // Fill depths with BFS over module imports.
369
- while (!worklist.empty ()) {
370
- ModuleDecl *module ;
371
- uint8_t depth;
372
- std::tie (module , depth) = worklist.front ();
373
- worklist.pop_front ();
374
-
375
- if (!seen.insert (module ).second )
376
- continue ;
377
-
378
- // Insert new module:depth mapping.
379
- const clang::Module *CM = module ->findUnderlyingClangModule ();
380
- if (CM) {
381
- depths[CM->getFullModuleName ()] = depth;
382
- } else {
383
- depths[module ->getName ().str ()] = depth;
384
- }
385
-
386
- // Add imports to the worklist.
387
- SmallVector<ImportedModule, 16 > imports;
388
- module ->getImportedModules (imports);
389
- for (auto &import : imports) {
390
- uint8_t next = std::max (depth, uint8_t (depth + 1 )); // unsigned wrap
391
-
392
- // Implicitly imported sub-modules get the same depth as their parent.
393
- if (const clang::Module *CMI =
394
- import .importedModule ->findUnderlyingClangModule ())
395
- if (CM && CMI->isSubModuleOf (CM))
396
- next = depth;
397
- worklist.emplace_back (import .importedModule , next);
398
- }
399
- }
400
- }
401
-
402
320
// ===----------------------------------------------------------------------===//
403
321
// CodeCompletionOrganizer::Impl utilities
404
322
// ===----------------------------------------------------------------------===//
0 commit comments