[PATCH] D34033: [clangd] Add parameter and return type information to completion results
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 8 07:41:48 PDT 2017
krasimir updated this revision to Diff 101919.
krasimir added a comment.
- Remove optional chunks. They might contain control characters
https://reviews.llvm.org/D34033
Files:
clangd/ClangdUnit.cpp
test/clangd/completion.test
Index: test/clangd/completion.test
===================================================================
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -5,41 +5,40 @@
{"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
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
# The order of results returned by ASTUnit CodeComplete seems to be
# 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","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","insertText":"f"}
# CHECK: ]}
Content-Length: 146
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:/main.cpp"},"position":{"line":3,"character":5}}}
# 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","insertText":"a"}
# CHECK: ]}
Content-Length: 172
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
# 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","insertText":"a"}
# CHECK: ]}
Content-Length: 44
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -138,9 +138,21 @@
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 = CCS->getTypedText();
if (CCS->getBriefComment())
Item.documentation = CCS->getBriefComment();
Items->push_back(std::move(Item));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34033.101919.patch
Type: text/x-patch
Size: 3772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170608/1d487ff0/attachment-0001.bin>
More information about the cfe-commits
mailing list