Index: clangd/ClangdUnit.cpp =================================================================== --- clangd/ClangdUnit.cpp +++ clangd/ClangdUnit.cpp @@ -115,6 +115,7 @@ } } + class CompletionItemsCollector : public CodeCompleteConsumer { std::vector *Items; std::shared_ptr Allocator; @@ -138,9 +139,19 @@ CodeCompleteOpts.IncludeBriefComments); if (CCS) { CompletionItem Item; + for (CodeCompletionString::Chunk C : *CCS) { + switch (C.Kind) { + case CodeCompletionString::CK_ResultType: + Item.detail = C.Text; + 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)); @@ -151,6 +162,9 @@ GlobalCodeCompletionAllocator &getAllocator() override { return *Allocator; } CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; } + +private: + bool isInformative(CodeCompletionString::ChunkKind) const; }; } // namespace Index: test/clangd/completion.test =================================================================== --- test/clangd/completion.test +++ test/clangd/completion.test @@ -16,9 +16,11 @@ # 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: ]} Content-Length: 146 @@ -26,9 +28,7 @@ # 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 @@ -37,9 +37,7 @@ # 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