Skip to content

[6.0][SourceKit] Stop printing normal comments in clang generated interface #72574

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ struct PrintOptions {
bool PrintInSILBody = false;

/// Whether to use an empty line to separate two members in a single decl.
bool EmptyLineBetweenMembers = false;
bool EmptyLineBetweenDecls = false;

/// Whether to print empty members of a declaration on a single line, e.g.:
/// ```
Expand Down Expand Up @@ -502,9 +502,6 @@ struct PrintOptions {
/// (e.g. the overridden method in the superclass) if such comment is found.
bool PrintDocumentationComments = false;

/// Whether to print regular comments from clang module headers.
bool PrintRegularClangComments = false;

/// When true, printing interface from a source file will print the original
/// source text for applicable declarations, in order to preserve the
/// formatting.
Expand Down Expand Up @@ -645,7 +642,6 @@ struct PrintOptions {
result.TypeDefinitions = true;
result.VarInitializers = true;
result.PrintDocumentationComments = true;
result.PrintRegularClangComments = true;
result.PrintLongAttrsOnSeparateLines = true;
result.AlwaysTryPrintParameterLabels = true;
return result;
Expand Down Expand Up @@ -696,7 +692,7 @@ struct PrintOptions {
result.SkipUnderscoredStdlibProtocols = true;
result.SkipUnsafeCXXMethods = true;
result.SkipDeinit = true;
result.EmptyLineBetweenMembers = true;
result.EmptyLineBetweenDecls = true;
result.CascadeDocComment = true;
result.ShouldQualifyNestedDeclarations =
QualifyNestedDeclarations::Always;
Expand Down Expand Up @@ -759,7 +755,7 @@ struct PrintOptions {
static PrintOptions printSwiftFileInterface(bool printFullConvention) {
PrintOptions result = printInterface(printFullConvention);
result.AccessFilter = AccessLevel::Internal;
result.EmptyLineBetweenMembers = true;
result.EmptyLineBetweenDecls = true;
return result;
}

Expand Down
20 changes: 2 additions & 18 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
StringRef RawText =
RC->getRawText(ClangContext.getSourceManager()).rtrim("\n\r");
trimLeadingWhitespaceFromLines(RawText, WhitespaceToTrim, Lines);
indent();
bool FirstLine = true;
for (auto Line : Lines) {
if (FirstLine)
Expand Down Expand Up @@ -1134,23 +1135,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
Printer.setSynthesizedTarget(Options.TransformContext->getDecl());
}

// 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 &&
!Options.PrintRegularClangComments &&
D->hasClangNode()) {
auto clangNode = D->getClangNode();
auto clangDecl = clangNode.getAsDecl();
if (clangDecl &&
clangDecl->getASTContext().getRawCommentForAnyRedecl(clangDecl)) {
Printer.printNewline();
indent();
}
}


Printer.callPrintDeclPre(D, Options.BracketOptions);

if (Options.PrintCompatibilityFeatureChecks) {
Expand Down Expand Up @@ -2727,7 +2711,7 @@ void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
if (!member->shouldPrintInContext(Options))
continue;

if (Options.EmptyLineBetweenMembers)
if (Options.EmptyLineBetweenDecls)
Printer.printNewline();
indent();
visit(member);
Expand Down
1 change: 0 additions & 1 deletion lib/IDE/IDETypeChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ PrintOptions PrintOptions::printDocInterface() {
result.ArgAndParamPrinting =
PrintOptions::ArgAndParamPrintingMode::BothAlways;
result.PrintDocumentationComments = false;
result.PrintRegularClangComments = false;
result.PrintFunctionRepresentationAttrs =
PrintOptions::FunctionRepresentationMode::None;
return result;
Expand Down
Loading