Skip to content

[SourceKit] Adjust newlines between decls #72553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Mar 25, 2024

Previously, generated interface for Clang modules didn't have empty lines between top-level decls. This was inconsistent with Swift modules.

Comment on lines -1137 to 1138
// We want to print a newline before doc comments. Swift code already
// handles this, but we need to insert it for clang doc comments when not
// printing other clang comments. Do it now so the printDeclPre callback
// happens after the newline.
if (Options.PrintDocumentationComments && D->hasClangNode()) {
auto clangNode = D->getClangNode();
auto clangDecl = clangNode.getAsDecl();
if (clangDecl &&
clangDecl->getASTContext().getRawCommentForAnyRedecl(clangDecl)) {
Printer.printNewline();
indent();
}
}

Printer.callPrintDeclPre(D, Options.BracketOptions);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was leftover from generated interface printing normal comments between decls, which was hooking "PrintDeclPre". Not needed.

if (D->print(Printer, Options)) {
if (Options.BracketOptions.shouldCloseNominal(D))
Printer << "\n";
Printer.printNewline();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.printNewline() instead of << "\n" because that's ASTPrinter's style.

Comment on lines 697 to +700
for (auto CM : ClangModules) {
for (auto DeclAndLoc : ClangDecls[CM.first])
PrintDecl(DeclAndLoc.first);
if (PrintDecl(DeclAndLoc.first) && Options.EmptyLineBetweenDecls)
Printer.printNewline();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change of this PR. Newline after printing a decl just like Swift decls few lines below

if (PrintDecl(D))
Printer << "\n";
if (PrintDecl(D) && Options.EmptyLineBetweenDecls)
Printer.printNewline();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes swift-ide-test -print-interface NOT print newlines between top-level decls.
Currently EmptyLineBetweenDecls (formerly EmptyLineBetweenMembers) is enabled in generated-interface only.

@rintaro
Copy link
Member Author

rintaro commented Mar 25, 2024

@swift-ci Please smoke test

Previously, Clang modules didn't have empty lines between top-level
decls. This was inconsistent with Swift module.
@rintaro rintaro force-pushed the sourcekit-iterfacegen-newline branch from 72d7e8f to 7b3738d Compare March 25, 2024 13:08
@rintaro
Copy link
Member Author

rintaro commented Mar 25, 2024

@swift-ci Please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants