[PATCH] D69961: [clangd] Fix a regression of not showing documentation from forward declarations.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 8 01:37:08 PST 2019


hokein updated this revision to Diff 228380.
hokein marked 2 inline comments as done.
hokein added a comment.

- include union type;
- add testcase for non-class symbols;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69961/new/

https://reviews.llvm.org/D69961

Files:
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp


Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -411,10 +411,13 @@
   Symbol L, R;
   L.ID = R.ID = SymbolID("x");
   L.Definition.FileURI = "file:/x.h";
+  L.SymInfo.Kind = index::SymbolKind::Class;
   R.Documentation = "Forward declarations because x.h is too big to include";
+  EXPECT_EQ( mergeSymbol(L, R).Documentation, "");
 
-  Symbol M = mergeSymbol(L, R);
-  EXPECT_EQ(M.Documentation, "");
+  L.SymInfo.Kind = index::SymbolKind::Function;
+  R.Documentation = "Documentation from non-class symbols should be included";
+  EXPECT_EQ(mergeSymbol(L, R).Documentation, R.Documentation);
 }
 
 MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
Index: clang-tools-extra/clangd/index/Merge.cpp
===================================================================
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -186,11 +186,17 @@
     S.Signature = O.Signature;
   if (S.CompletionSnippetSuffix == "")
     S.CompletionSnippetSuffix = O.CompletionSnippetSuffix;
-  // Don't accept documentation from bare forward declarations, if there is a
-  // definition and it didn't provide one. S is often an undocumented class,
-  // and O is a non-canonical forward decl preceded by an irrelevant comment.
-  if (S.Documentation == "" && !S.Definition)
-    S.Documentation = O.Documentation;
+  if (S.Documentation == "") {
+    // Don't accept documentation from bare forward class declarations, if there
+    // is a definition and it didn't provide one. S is often an undocumented
+    // class, and O is a non-canonical forward decl preceded by an irrelevant
+    // comment.
+    bool IsClass = S.SymInfo.Kind == index::SymbolKind::Class ||
+                   S.SymInfo.Kind == index::SymbolKind::Struct ||
+                   S.SymInfo.Kind == index::SymbolKind::Union;
+    if (!IsClass || !S.Definition)
+      S.Documentation = O.Documentation;
+  }
   if (S.ReturnType == "")
     S.ReturnType = O.ReturnType;
   if (S.Type == "")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69961.228380.patch
Type: text/x-patch
Size: 2187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191108/293a1fe5/attachment.bin>


More information about the cfe-commits mailing list