@@ -635,17 +635,20 @@ 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
+ }
646
649
647
650
if (Roles & static_cast <unsigned >(index::SymbolRole::Definition))
648
- addDefinition (*OriginalDecl, *BasicSymbol);
651
+ addDefinition (*OriginalDecl, *BasicSymbol, SkipDocCheckInDef );
649
652
650
653
return true ;
651
654
}
@@ -1025,15 +1028,17 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
1025
1028
*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
1026
1029
*CompletionTUInfo,
1027
1030
/* IncludeBriefComments*/ false );
1028
- std::string Documentation =
1029
- formatDocumentation (*CCS, getDocComment (Ctx, SymbolCompletion,
1030
- /* CommentsFromHeaders= */ true ) );
1031
+ std::string DocComment = getDocComment (Ctx, SymbolCompletion,
1032
+ /* CommentsFromHeaders= */ true );
1033
+ std::string Documentation = formatDocumentation (*CCS, DocComment );
1031
1034
if (!(S.Flags & Symbol::IndexedForCodeCompletion)) {
1032
1035
if (Opts.StoreAllDocumentation )
1033
1036
S.Documentation = Documentation;
1034
1037
Symbols.insert (S);
1035
1038
return Symbols.find (S.ID );
1036
1039
}
1040
+ if (!DocComment.empty ())
1041
+ S.Flags |= Symbol::HasDocComment;
1037
1042
S.Documentation = Documentation;
1038
1043
std::string Signature;
1039
1044
std::string SnippetSuffix;
@@ -1058,8 +1063,8 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
1058
1063
return Symbols.find (S.ID );
1059
1064
}
1060
1065
1061
- void SymbolCollector::addDefinition (const NamedDecl &ND,
1062
- const Symbol &DeclSym ) {
1066
+ void SymbolCollector::addDefinition (const NamedDecl &ND, const Symbol &DeclSym,
1067
+ bool SkipDocCheck ) {
1063
1068
if (DeclSym.Definition )
1064
1069
return ;
1065
1070
const auto &SM = ND.getASTContext ().getSourceManager ();
@@ -1074,6 +1079,27 @@ void SymbolCollector::addDefinition(const NamedDecl &ND,
1074
1079
Symbol S = DeclSym;
1075
1080
// FIXME: use the result to filter out symbols.
1076
1081
S.Definition = *DefLoc;
1082
+
1083
+ std::string DocComment;
1084
+ std::string Documentation;
1085
+ if (!SkipDocCheck && !(S.Flags & Symbol::HasDocComment) &&
1086
+ (llvm::isa<FunctionDecl>(ND) || llvm::isa<CXXMethodDecl>(ND))) {
1087
+ CodeCompletionResult SymbolCompletion (&getTemplateOrThis (ND), 0 );
1088
+ const auto *CCS = SymbolCompletion.CreateCodeCompletionString (
1089
+ *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
1090
+ *CompletionTUInfo,
1091
+ /* IncludeBriefComments*/ false );
1092
+ DocComment = getDocComment (ND.getASTContext (), SymbolCompletion,
1093
+ /* CommentsFromHeaders=*/ true );
1094
+ if (!S.Documentation .empty ())
1095
+ Documentation = S.Documentation .str () + ' \n ' + DocComment;
1096
+ else
1097
+ Documentation = formatDocumentation (*CCS, DocComment);
1098
+ if (!DocComment.empty ())
1099
+ S.Flags |= Symbol::HasDocComment;
1100
+ S.Documentation = Documentation;
1101
+ }
1102
+
1077
1103
Symbols.insert (S);
1078
1104
}
1079
1105
0 commit comments