From 99930623efd65e542481294b5f09f9295559d0e7 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 11 Apr 2019 22:26:07 -0700 Subject: [PATCH] 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 --- src/indexer.cc | 4 ++-- src/messages/textDocument_hover.cc | 7 ++++--- src/sema_manager.cc | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 59135710..066fc9f1 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1238,8 +1238,8 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, ok = false; // -fparse-all-comments enables documentation in the indexer and in // code completion. - if (g_config->index.comments > 1) - CI->getLangOpts()->CommentOpts.ParseAllComments = true; + CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1; + CI->getLangOpts()->RetainCommentsFromSystemHeaders = true; std::string buf = wfiles->GetContent(main); std::vector> Bufs; if (buf.size()) diff --git a/src/messages/textDocument_hover.cc b/src/messages/textDocument_hover.cc index a67a9272..1e9781af 100644 --- a/src/messages/textDocument_hover.cc +++ b/src/messages/textDocument_hover.cc @@ -60,8 +60,11 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) { std::optional ls_comments, hover; WithEntity(db, sym, [&](const auto &entity) { for (auto &d : entity.def) { + if (!comments && d.comments[0]) + comments = d.comments; if (d.spell) { - comments = d.comments[0] ? d.comments : nullptr; + if (d.comments[0]) + comments = d.comments; if (const char *s = d.hover[0] ? d.hover : 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()) { auto &d = entity.def[0]; - if (d.comments[0]) - comments = d.comments; hover = {LanguageIdentifier(lang)}; if (d.hover[0]) hover->value = d.hover; diff --git a/src/sema_manager.cc b/src/sema_manager.cc index 096f2c16..d8e7608e 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -363,6 +363,7 @@ void BuildPreamble(Session &session, CompilerInvocation &CI, CI.getDiagnosticOpts().IgnoreWarnings = false; CI.getFrontendOpts().SkipFunctionBodies = true; CI.getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1; + CI.getLangOpts()->RetainCommentsFromSystemHeaders = true; StoreDiags DC(task.path); IntrusiveRefCntPtr DE =