[clang-tools-extra] r360039 - [clangd] Expose whether no-compile completion was used.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 05:03:27 PDT 2019


Author: sammccall
Date: Mon May  6 05:03:26 2019
New Revision: 360039

URL: http://llvm.org/viewvc/llvm-project?rev=360039&view=rev
Log:
[clangd] Expose whether no-compile completion was used.

Summary: Embedding clients want to experiment with showing such results in e.g. a different color.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61588

Modified:
    clang-tools-extra/trunk/clangd/CodeComplete.cpp
    clang-tools-extra/trunk/clangd/CodeComplete.h
    clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=360039&r1=360038&r2=360039&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon May  6 05:03:26 2019
@@ -1380,6 +1380,7 @@ public:
 
     CodeCompleteResult Output = toCodeCompleteResult(mergeResults(
         /*SemaResults=*/{}, IndexResults, IdentifierResults));
+    Output.RanParser = false;
     logResults(Output, Tracer);
     return Output;
   }

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=360039&r1=360038&r2=360039&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Mon May  6 05:03:26 2019
@@ -207,6 +207,9 @@ struct CodeCompleteResult {
   std::vector<CodeCompletion> Completions;
   bool HasMore = false;
   CodeCompletionContext::Kind Context = CodeCompletionContext::CCC_Other;
+  // Usually the source will be parsed with a real C++ parser.
+  // But heuristics may be used instead if e.g. the preamble is not ready.
+  bool RanParser = true;
 };
 raw_ostream &operator<<(raw_ostream &, const CodeCompleteResult &);
 

Modified: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp?rev=360039&r1=360038&r2=360039&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp Mon May  6 05:03:26 2019
@@ -235,6 +235,7 @@ void TestAfterDotCompletion(clangd::Code
       )cpp",
       {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
+  EXPECT_TRUE(Results.RanParser);
   // Class members. The only items that must be present in after-dot
   // completion.
   EXPECT_THAT(Results.Completions,
@@ -284,6 +285,7 @@ void TestGlobalScopeCompletion(clangd::C
       )cpp",
       {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
+  EXPECT_TRUE(Results.RanParser);
   // Class members. Should never be present in global completions.
   EXPECT_THAT(Results.Completions,
               Not(AnyOf(Has("method"), Has("method()"), Has("field"))));
@@ -2459,6 +2461,7 @@ TEST(NoCompileCompletionTest, Basic) {
       ^
     }
   )cpp");
+  EXPECT_FALSE(Results.RanParser);
   EXPECT_THAT(Results.Completions,
               UnorderedElementsAre(Named("void"), Named("func"), Named("int"),
                                    Named("xyz"), Named("abc")));




More information about the cfe-commits mailing list