Set RetainCommentsFromSystemHeaders to true

Note with -fretain-comments-from-system-headers, the .gch of bits/stdc++.h becomes larger by 1%, but that is fine.

And improve comment handling in textDocument/hover

Fix #373
This commit is contained in:
Fangrui Song 2019-04-11 22:26:07 -07:00
parent b69f62c2bc
commit 99930623ef
3 changed files with 7 additions and 5 deletions

View File

@ -1238,8 +1238,8 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
ok = false; ok = false;
// -fparse-all-comments enables documentation in the indexer and in // -fparse-all-comments enables documentation in the indexer and in
// code completion. // code completion.
if (g_config->index.comments > 1) CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
CI->getLangOpts()->CommentOpts.ParseAllComments = true; CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;
std::string buf = wfiles->GetContent(main); std::string buf = wfiles->GetContent(main);
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs; std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs;
if (buf.size()) if (buf.size())

View File

@ -60,8 +60,11 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) {
std::optional<MarkedString> ls_comments, hover; std::optional<MarkedString> ls_comments, hover;
WithEntity(db, sym, [&](const auto &entity) { WithEntity(db, sym, [&](const auto &entity) {
for (auto &d : entity.def) { for (auto &d : entity.def) {
if (!comments && d.comments[0])
comments = d.comments;
if (d.spell) { if (d.spell) {
comments = d.comments[0] ? d.comments : nullptr; if (d.comments[0])
comments = d.comments;
if (const char *s = if (const char *s =
d.hover[0] ? d.hover d.hover[0] ? d.hover
: d.detailed_name[0] ? d.detailed_name : nullptr) { : d.detailed_name[0] ? d.detailed_name : nullptr) {
@ -76,8 +79,6 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) {
} }
if (!hover && entity.def.size()) { if (!hover && entity.def.size()) {
auto &d = entity.def[0]; auto &d = entity.def[0];
if (d.comments[0])
comments = d.comments;
hover = {LanguageIdentifier(lang)}; hover = {LanguageIdentifier(lang)};
if (d.hover[0]) if (d.hover[0])
hover->value = d.hover; hover->value = d.hover;

View File

@ -363,6 +363,7 @@ void BuildPreamble(Session &session, CompilerInvocation &CI,
CI.getDiagnosticOpts().IgnoreWarnings = false; CI.getDiagnosticOpts().IgnoreWarnings = false;
CI.getFrontendOpts().SkipFunctionBodies = true; CI.getFrontendOpts().SkipFunctionBodies = true;
CI.getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1; CI.getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
CI.getLangOpts()->RetainCommentsFromSystemHeaders = true;
StoreDiags DC(task.path); StoreDiags DC(task.path);
IntrusiveRefCntPtr<DiagnosticsEngine> DE = IntrusiveRefCntPtr<DiagnosticsEngine> DE =