[clang-tools-extra] r304980 - [clangd] Add parameter and return type information to completion results

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 8 08:11:51 PDT 2017


Author: krasimir
Date: Thu Jun  8 10:11:51 2017
New Revision: 304980

URL: http://llvm.org/viewvc/llvm-project?rev=304980&view=rev
Log:
[clangd] Add parameter and return type information to completion results

Summary:
This patch adds information about the parameters and return types of completion
candidates.
Previously, for the following code:
```
struct S {
  int func(int a, double b) const;
};
```
the completer would only return the label of the candidate `func`.
Now it will also return the return type `int` and will format the label for the
candidate as `func(int a, double b) const`.

Reviewers: bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

Modified:
    clang-tools-extra/trunk/clangd/ClangdUnit.cpp
    clang-tools-extra/trunk/test/clangd/completion.test

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=304980&r1=304979&r2=304980&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Jun  8 10:11:51 2017
@@ -138,9 +138,21 @@ public:
           CodeCompleteOpts.IncludeBriefComments);
       if (CCS) {
         CompletionItem Item;
+        for (CodeCompletionString::Chunk C : *CCS) {
+          switch (C.Kind) {
+          case CodeCompletionString::CK_ResultType:
+            Item.detail = C.Text;
+            break;
+          case CodeCompletionString::CK_Optional:
+            break;
+          default:
+            Item.label += C.Text;
+            break;
+          }
+        }
         assert(CCS->getTypedText());
-        Item.label = CCS->getTypedText();
         Item.kind = getKind(Result.CursorKind);
+        Item.insertText = Item.sortText = Item.filterText = CCS->getTypedText();
         if (CCS->getBriefComment())
           Item.documentation = CCS->getBriefComment();
         Items->push_back(std::move(Item));

Modified: clang-tools-extra/trunk/test/clangd/completion.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion.test?rev=304980&r1=304979&r2=304980&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/completion.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion.test Thu Jun  8 10:11:51 2017
@@ -5,9 +5,9 @@ Content-Length: 125
 
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
 
 Content-Length: 148
 
@@ -16,9 +16,12 @@ Content-Length: 148
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 Content-Length: 146
 
@@ -26,9 +29,7 @@ Content-Length: 146
 # Test authority-less URI
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 
 Content-Length: 172
@@ -37,9 +38,7 @@ Content-Length: 172
 # Test params parsing in the presence of a 1.x-compatible client (inlined "uri")
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 Content-Length: 44
 




More information about the cfe-commits mailing list