[clang-tools-extra] r314445 - [clangd] Skip informative qualifier chunks.
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 28 11:39:59 PDT 2017
Author: ibiryukov
Date: Thu Sep 28 11:39:59 2017
New Revision: 314445
URL: http://llvm.org/viewvc/llvm-project?rev=314445&view=rev
Log:
[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
Added:
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=314445&r1=314444&r2=314445&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Sep 28 11:39:59 2017
@@ -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
Added: clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-qualifiers.test?rev=314445&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/completion-qualifiers.test (added)
+++ clang-tools-extra/trunk/test/clangd/completion-qualifiers.test Thu Sep 28 11:39:59 2017
@@ -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"}
More information about the cfe-commits
mailing list