This revision was automatically updated to reflect the committed changes. Closed by commit rL304980: [clangd] Add parameter and return type information to completion results (authored by krasimir).
Changed prior to commit: https://reviews.llvm.org/D34033?vs=101921&id=101925#toc Repository: rL LLVM https://reviews.llvm.org/D34033 Files: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/test/clangd/completion.test Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp +++ clang-tools-extra/trunk/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 = Item.sortText = Item.filterText = CCS->getTypedText(); if (CCS->getBriefComment()) Item.documentation = CCS->getBriefComment(); Items->push_back(std::move(Item)); Index: clang-tools-extra/trunk/test/clangd/completion.test =================================================================== --- clang-tools-extra/trunk/test/clangd/completion.test +++ clang-tools-extra/trunk/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","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 {"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","sortText":"a","filterText":"a","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","sortText":"a","filterText":"a","insertText":"a"} # CHECK: ]} Content-Length: 44
Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp +++ clang-tools-extra/trunk/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 = Item.sortText = Item.filterText = CCS->getTypedText(); if (CCS->getBriefComment()) Item.documentation = CCS->getBriefComment(); Items->push_back(std::move(Item)); Index: clang-tools-extra/trunk/test/clangd/completion.test =================================================================== --- clang-tools-extra/trunk/test/clangd/completion.test +++ clang-tools-extra/trunk/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","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 {"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","sortText":"a","filterText":"a","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","sortText":"a","filterText":"a","insertText":"a"} # CHECK: ]} Content-Length: 44
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits