@@ -635,17 +635,21 @@ bool SymbolCollector::handleDeclOccurrence(
635
635
return true ;
636
636
637
637
const Symbol *BasicSymbol = Symbols.find (ID);
638
- if (isPreferredDeclaration (*OriginalDecl, Roles))
638
+ bool SkipDocCheckInDef = false ;
639
+ if (isPreferredDeclaration (*OriginalDecl, Roles)) {
639
640
// If OriginalDecl is preferred, replace/create the existing canonical
640
641
// declaration (e.g. a class forward declaration). There should be at most
641
642
// one duplicate as we expect to see only one preferred declaration per
642
643
// TU, because in practice they are definitions.
643
644
BasicSymbol = addDeclaration (*OriginalDecl, std::move (ID), IsMainFileOnly);
644
- else if (!BasicSymbol || DeclIsCanonical)
645
+ SkipDocCheckInDef = true ;
646
+ } else if (!BasicSymbol || DeclIsCanonical) {
645
647
BasicSymbol = addDeclaration (*ND, std::move (ID), IsMainFileOnly);
648
+ SkipDocCheckInDef = true ;
649
+ }
646
650
647
651
if (Roles & static_cast <unsigned >(index ::SymbolRole::Definition))
648
- addDefinition (*OriginalDecl, *BasicSymbol);
652
+ addDefinition (*OriginalDecl, *BasicSymbol, SkipDocCheckInDef );
649
653
650
654
return true ;
651
655
}
@@ -1025,16 +1029,28 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
1025
1029
*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
1026
1030
*CompletionTUInfo,
1027
1031
/* IncludeBriefComments*/ false );
1028
- std::string Documentation =
1029
- formatDocumentation (*CCS, getDocComment (Ctx, SymbolCompletion,
1030
- /* CommentsFromHeaders=*/ true ));
1032
+ std::string DocComment;
1033
+ std::string Documentation;
1034
+ bool AlreadyHasDoc = S.Flags & Symbol::HasDocComment;
1035
+ if (!AlreadyHasDoc) {
1036
+ DocComment = getDocComment (Ctx, SymbolCompletion,
1037
+ /* CommentsFromHeaders=*/ true );
1038
+ Documentation = formatDocumentation (*CCS, DocComment);
1039
+ }
1040
+ const auto UpdateDoc = [&] {
1041
+ if (!AlreadyHasDoc) {
1042
+ if (!DocComment.empty ())
1043
+ S.Flags |= Symbol::HasDocComment;
1044
+ S.Documentation = Documentation;
1045
+ }
1046
+ };
1031
1047
if (!(S.Flags & Symbol::IndexedForCodeCompletion)) {
1032
1048
if (Opts.StoreAllDocumentation )
1033
- S. Documentation = Documentation ;
1049
+ UpdateDoc () ;
1034
1050
Symbols.insert (S);
1035
1051
return Symbols.find (S.ID );
1036
1052
}
1037
- S. Documentation = Documentation ;
1053
+ UpdateDoc () ;
1038
1054
std::string Signature;
1039
1055
std::string SnippetSuffix;
1040
1056
getSignature (*CCS, &Signature, &SnippetSuffix, SymbolCompletion.Kind ,
@@ -1058,8 +1074,8 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
1058
1074
return Symbols.find (S.ID );
1059
1075
}
1060
1076
1061
- void SymbolCollector::addDefinition (const NamedDecl &ND,
1062
- const Symbol &DeclSym ) {
1077
+ void SymbolCollector::addDefinition (const NamedDecl &ND, const Symbol &DeclSym,
1078
+ bool SkipDocCheck ) {
1063
1079
if (DeclSym.Definition )
1064
1080
return ;
1065
1081
const auto &SM = ND.getASTContext ().getSourceManager ();
@@ -1074,6 +1090,27 @@ void SymbolCollector::addDefinition(const NamedDecl &ND,
1074
1090
Symbol S = DeclSym;
1075
1091
// FIXME: use the result to filter out symbols.
1076
1092
S.Definition = *DefLoc;
1093
+
1094
+ std::string DocComment;
1095
+ std::string Documentation;
1096
+ if (!SkipDocCheck && !(S.Flags & Symbol::HasDocComment) &&
1097
+ (llvm::isa<FunctionDecl>(ND) || llvm::isa<CXXMethodDecl>(ND))) {
1098
+ CodeCompletionResult SymbolCompletion (&getTemplateOrThis (ND), 0 );
1099
+ const auto *CCS = SymbolCompletion.CreateCodeCompletionString (
1100
+ *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
1101
+ *CompletionTUInfo,
1102
+ /* IncludeBriefComments*/ false );
1103
+ DocComment = getDocComment (ND.getASTContext (), SymbolCompletion,
1104
+ /* CommentsFromHeaders=*/ true );
1105
+ if (!S.Documentation .empty ())
1106
+ Documentation = S.Documentation .str () + ' \n ' + DocComment;
1107
+ else
1108
+ Documentation = formatDocumentation (*CCS, DocComment);
1109
+ if (!DocComment.empty ())
1110
+ S.Flags |= Symbol::HasDocComment;
1111
+ S.Documentation = Documentation;
1112
+ }
1113
+
1077
1114
Symbols.insert (S);
1078
1115
}
1079
1116
0 commit comments