forked from OSchip/llvm-project
[clangd] Skip informative qualifier chunks.
Summary: Completion results look much nicer without them. Informative qualifiers are stored for every method from a base class, even when calling those methods does not require any qualifiers. For example, struct Foo { int foo(); }; struct Bar : Foo { }; void test() { Bar(). // Completion item label was 'Foo::foo' before, // but inserted text was simply 'foo'. // We now simply show 'foo' in completion item label. They effectively cluttered the completion list without providing much value. Reviewers: bkramer, krasimir, rwols Reviewed By: rwols Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D38083 llvm-svn: 314445
This commit is contained in:
parent
1787f81221
commit
686ff9a880
|
@ -409,6 +409,11 @@ private:
|
|||
|
||||
}; // CompletionItemsCollector
|
||||
|
||||
bool isInformativeQualifierChunk(CodeCompletionString::Chunk const &Chunk) {
|
||||
return Chunk.Kind == CodeCompletionString::CK_Informative &&
|
||||
StringRef(Chunk.Text).endswith("::");
|
||||
}
|
||||
|
||||
class PlainTextCompletionItemsCollector final
|
||||
: public CompletionItemsCollector {
|
||||
|
||||
|
@ -421,6 +426,11 @@ private:
|
|||
void ProcessChunks(const CodeCompletionString &CCS,
|
||||
CompletionItem &Item) const override {
|
||||
for (const auto &Chunk : CCS) {
|
||||
// Informative qualifier chunks only clutter completion results, skip
|
||||
// them.
|
||||
if (isInformativeQualifierChunk(Chunk))
|
||||
continue;
|
||||
|
||||
switch (Chunk.Kind) {
|
||||
case CodeCompletionString::CK_TypedText:
|
||||
// There's always exactly one CK_TypedText chunk.
|
||||
|
@ -453,6 +463,11 @@ private:
|
|||
CompletionItem &Item) const override {
|
||||
unsigned ArgCount = 0;
|
||||
for (const auto &Chunk : CCS) {
|
||||
// Informative qualifier chunks only clutter completion results, skip
|
||||
// them.
|
||||
if (isInformativeQualifierChunk(Chunk))
|
||||
continue;
|
||||
|
||||
switch (Chunk.Kind) {
|
||||
case CodeCompletionString::CK_TypedText:
|
||||
// The piece of text that the user is expected to type to match
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# RUN: clangd -run-synchronously < %s | FileCheck %s
|
||||
Content-Length: 125
|
||||
|
||||
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
|
||||
Content-Length: 297
|
||||
|
||||
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"class Foo {\n public:\n int foo() const;\n int bar() const;\n};\n\nclass Bar : public Foo {\n int foo() const;\n};\n\nvoid test() {\n Bar().\n}"}}}
|
||||
Content-Length: 151
|
||||
|
||||
{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":11,"character":8}}}
|
||||
# CHECK: {"jsonrpc":"2.0","id":2,"result":[
|
||||
# CHECK-DAG: {"label":"foo() const","kind":2,"detail":"int","sortText":"200035foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
|
||||
# CHECK-DAG: {"label":"bar() const","kind":2,"detail":"int","sortText":"000037bar","filterText":"bar","insertText":"bar","insertTextFormat":1}
|
||||
# CHECK-DAG: {"label":"Foo::foo() const","kind":2,"detail":"int","sortText":"000037foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
|
||||
# CHECK: ]}
|
||||
Content-Length: 44
|
||||
|
||||
{"jsonrpc":"2.0","id":4,"method":"shutdown"}
|
Loading…
Reference in New Issue