[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

llvm-svn: 304980
This commit is contained in:
Krasimir Georgiev 2017-06-08 15:11:51 +00:00
parent 2ab6ee0dc4
commit e6035a51f7
2 changed files with 23 additions and 12 deletions

View File

@ -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));

View File

@ -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