Skip to content

Commit c97f115

Browse files
committed
[ModulePrinter] When printing decls in a module group, we print them according to their source order.
Source order preserves semantic information better than printing alphabetically.
1 parent 98734f5 commit c97f115

File tree

2 files changed

+271
-265
lines changed

2 files changed

+271
-265
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ void swift::ide::printSubmoduleInterface(
308308
continue;
309309
}
310310
if (FullModuleName.empty()) {
311+
// If group name is given and the decl does not belong to the group, skip it.
312+
if (GroupName && (!D->getGroupName() ||
313+
D->getGroupName().getValue() != GroupName.getValue()))
314+
continue;
311315
// Add Swift decls if we are printing the top-level module.
312316
SwiftDecls.push_back(D);
313317
}
@@ -344,9 +348,15 @@ void swift::ide::printSubmoduleInterface(
344348
});
345349

346350
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
347-
[](Decl *LHS, Decl *RHS) -> bool {
351+
[&](Decl *LHS, Decl *RHS) -> bool {
348352
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
349353
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
354+
355+
// If group is specified, we order the decls by their source order.
356+
if (GroupName && LHS->getSourceOrder() && RHS->getSourceOrder()) {
357+
return LHS->getSourceOrder().getValue() < RHS->getSourceOrder().getValue();
358+
}
359+
350360
if (LHSValue && RHSValue) {
351361
StringRef LHSName = LHSValue->getName().str();
352362
StringRef RHSName = RHSValue->getName().str();
@@ -368,10 +378,6 @@ void swift::ide::printSubmoduleInterface(
368378

369379
auto PrintDecl = [&](Decl *D) -> bool {
370380
ASTPrinter &Printer = *PrinterToUse;
371-
if (GroupName && (!D->getGroupName() ||
372-
D->getGroupName().getValue() != GroupName.getValue()))
373-
return false;
374-
375381
if (!shouldPrint(D, AdjustedOptions)) {
376382
Printer.avoidPrintDeclPost(D);
377383
return false;

0 commit comments

Comments
 (0)