Skip to content

Commit bf1436a

Browse files
committed
ASTPrinter: Move the logic for collecting all module groups from SourceKit to an IDE API, NFC.
1 parent 24cede9 commit bf1436a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

include/swift/IDE/ModuleInterfacePrinting.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Basic/OptionSet.h"
1818

19+
#include <vector>
20+
1921
namespace swift {
2022
class ASTContext;
2123
class ASTPrinter;
@@ -38,6 +40,9 @@ enum class ModuleTraversal : unsigned {
3840
/// Options used to describe the traversal of a module for printing.
3941
typedef OptionSet<ModuleTraversal> ModuleTraversalOptions;
4042

43+
ArrayRef<StringRef> collectModuleGroups(ModuleDecl *M,
44+
std::vector<StringRef> &Scratch);
45+
4146
void printModuleInterface(ModuleDecl *M,
4247
ModuleTraversalOptions TraversalOptions,
4348
ASTPrinter &Printer, const PrintOptions &Options,

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ void findExtensionsFromConformingProtocols(Decl *D,
176176
}
177177
}
178178

179+
ArrayRef<StringRef>
180+
swift::ide::collectModuleGroups(Module *M, std::vector<StringRef> &Scratch) {
181+
for (auto File : M->getFiles()) {
182+
File->collectAllGroups(Scratch);
183+
}
184+
std::sort(Scratch.begin(), Scratch.end(), [](StringRef L, StringRef R) {
185+
return L.compare_lower(R) < 0;
186+
});
187+
return llvm::makeArrayRef(Scratch);
188+
}
189+
179190
void swift::ide::printSubmoduleInterface(
180191
Module *M,
181192
ArrayRef<StringRef> FullModuleName,

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,6 @@ void SwiftLangSupport::findModuleGroups(StringRef ModuleName,
901901
Receiver(Groups, Error);
902902
return;
903903
}
904-
for (auto File : M->getFiles()) {
905-
File->collectAllGroups(Groups);
906-
}
907-
std::sort(Groups.begin(), Groups.end(), [](StringRef L, StringRef R) {
908-
return L.compare_lower(R) < 0;
909-
});
910-
Receiver(Groups, Error);
904+
std::vector<StringRef> Scratch;
905+
Receiver(collectModuleGroups(M, Scratch), Error);
911906
}

0 commit comments

Comments
 (0)