<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""><div class="">As a follow-up to discussion about destructor return type in code completion [1] I investigated status quo of constructor and destructor code completion in clangd.</div></div><div class=""><br class=""></div><div class="">I was using this trivial lit-test case:</div><div class=""><br class=""></div><div class=""><div class="">{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}</div><div class="">---</div><div class="">{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"<a href="test:///main.cpp" class="">test:///main.cpp</a>","languageId":"cpp","version":1,"text":"struct foo { bool b; }; void f() { foo a; a."}}}</div><div class="">---</div><div class="">{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"<a href="test:///main.cpp" class="">test:///main.cpp</a>"},"position":{"line":0,"character":44}}}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">These are my observations.</div><div class=""><br class=""></div><div class="">1. We currently skip constructors and destructors in code completion after . and -> member access in clangd.</div><div class=""><br class=""></div><div class="">struct foo { bool b; }; void f() { foo a; a.^</div><div class="">// produces single result - bool b</div><div class=""><br class=""></div><div class="">This seems fine.</div><div class=""><br class=""></div><div class="">2. We currently skip constructors but include destructors, assignment operators and struct/class name after double colon.</div><div class=""><br class=""></div><div class="">struct foo {}; foo::^</div><div class="">// produces 4 results - struct foo itself, copy assignment, move assignment, destructor</div><div class=""><br class=""></div><div class=""><div class="">- It seems to me that by including struct/class name we effectively include constructor code completion which makes sense in this situation but we shouldn’t put it’s kind as struct/class.</div><div class="">- What seems odd to me in this context is that we use void as return type of destructor (and had we not skipped constructor, it’s return type might be unexpected too). We previously discussed destructor return type with Sam in [1] and I agreed that it’s fine under false impression that we aren’t displaying destructors anyway (off-by-one error in my test case).</div><div class=""><br class=""></div><div class="">I suggest that we don’t include struct/class name but include both constructor (without any return type == no “detail” in LSP) and destructor (without any return type == no “detail” in LSP) when code completion context is "struct/class name followed by double colon".</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">3. We currently skip both constructors and destructors but include struct/class name after double colon and tilde but also include lot of other results.</div><div class=""><br class=""></div><div class="">struct foo {}; foo::~^</div><div class="">// produces 66 results - including keywords and probably built-in macros and struct/class name but not constructor or destructor</div><div class=""><br class=""></div><div class="">This seems wrong to me. I suggest we skip unrelated keywords and struct/class name but we should include destructor (with proper insertText to not repeat the leading tilde).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I’d like to know other people’s thoughts on this before I work on patches. I just created one WIP patch when I was investigating why we don’t skip destructor in double colon case - anyone interested please see [2].</div><div class=""><br class=""></div><div class="">Thank you.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Jan</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">[1] <a href="https://reviews.llvm.org/D52308" class="">https://reviews.llvm.org/D52308</a> [Sema][CodeCompletion] Fix return type of C++ destructors in code completion</div><div class=""><br class=""></div><div class="">[2] <a href="https://reviews.llvm.org/D52495" class="">https://reviews.llvm.org/D52495</a> [WIP][Sema][CodeCompletion] Add base type for double colon member completion results</div></body></html>