mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[InterfacePrinting] Add a print option to specify whether members of a decl should be separated by empty new lines.
By doing so, SourceKit can print Swift intefaces in the same fashion of what Xcode conventionally does. rdar://21710381 Swift SVN r30430
This commit is contained in:
@@ -144,6 +144,9 @@ struct PrintOptions {
|
||||
/// Whether we are printing part of SIL body.
|
||||
bool PrintInSILBody = false;
|
||||
|
||||
/// Whether to use an empty line to separate two members in a single decl.
|
||||
bool EmptyLineBetweenMembers = false;
|
||||
|
||||
enum class ArgAndParamPrintingMode {
|
||||
ArgumentOnly,
|
||||
MatchSource,
|
||||
|
||||
@@ -222,7 +222,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
|
||||
if (RC.isEmpty())
|
||||
return;
|
||||
|
||||
Printer.printNewline();
|
||||
indent();
|
||||
|
||||
SmallVector<StringRef, 8> Lines;
|
||||
@@ -885,6 +884,8 @@ void PrintAST::printMembers(DeclRange members, bool needComma) {
|
||||
if (!member->shouldPrintInContext(Options))
|
||||
continue;
|
||||
|
||||
if (Options.EmptyLineBetweenMembers)
|
||||
Printer.printNewline();
|
||||
indent();
|
||||
visit(member);
|
||||
if (needComma && std::next(i) != iEnd)
|
||||
@@ -1691,7 +1692,6 @@ void PrintAST::visitEnumCaseDecl(EnumCaseDecl *decl) {
|
||||
void PrintAST::visitEnumElementDecl(EnumElementDecl *decl) {
|
||||
if (!decl->shouldPrintInContext(Options))
|
||||
return;
|
||||
|
||||
printDocumentationComment(decl);
|
||||
// In cases where there is no parent EnumCaseDecl (such as imported or
|
||||
// deserialized elements), print the element independently.
|
||||
|
||||
@@ -1390,16 +1390,12 @@ void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
|
||||
for (auto decl : Decls) {
|
||||
if (!decl->shouldPrintInContext(PO))
|
||||
continue;
|
||||
|
||||
if(decl->print(Printer, PO)) {
|
||||
// For a major decl, we print an empty line before it.
|
||||
if (MajorDeclKinds.find(decl->getKind()) != MajorDeclKinds.end())
|
||||
Printer << "\n";
|
||||
|
||||
// For a major decl, we print an empty line after it.
|
||||
if (MajorDeclKinds.find(decl->getKind()) != MajorDeclKinds.end()) {
|
||||
if(decl->print(Printer, PO))
|
||||
Printer << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceFile::addImports(
|
||||
|
||||
@@ -20,14 +20,12 @@ protocol BarProtocol {
|
||||
func instanceFunc()
|
||||
}
|
||||
|
||||
|
||||
/// FooSwiftStruct Aaa.
|
||||
/**
|
||||
* Bbb.
|
||||
* Ccc.
|
||||
*/
|
||||
struct FooSwiftStruct {
|
||||
|
||||
/// fooInstanceFunc Aaa.
|
||||
/**
|
||||
* Bbb
|
||||
@@ -39,10 +37,8 @@ struct FooSwiftStruct {
|
||||
init()
|
||||
}
|
||||
|
||||
|
||||
/// rdar://18457785
|
||||
enum MyQuickLookObject {
|
||||
|
||||
/// A rectangle.
|
||||
///
|
||||
/// Uses explicit coordinates to avoid coupling a particular Cocoa type.
|
||||
|
||||
Reference in New Issue
Block a user