[PATCH] D38083: [clangd] Skip informative qualifier chunks.
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 20 08:08:01 PDT 2017
ilya-biryukov created this revision.
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.
https://reviews.llvm.org/D38083
Files:
clangd/ClangdUnit.cpp
test/clangd/completion-qualifiers.test
Index: test/clangd/completion-qualifiers.test
===================================================================
--- /dev/null
+++ test/clangd/completion-qualifiers.test
@@ -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":[
+# CHEKC-DAG: {"label":"foo() const","kind":2,"detail":"int","sortText":"00035foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
+# CHEKC-DAG: {"label":"bar() const","kind":2,"detail":"int","sortText":"00037bar","filterText":"bar","insertText":"bar","insertTextFormat":1}
+# CHEKC-DAG: {"label":"Foo::foo() const","kind":2,"detail":"int","sortText":"00037foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
+# CHECK: ]}
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -383,6 +383,11 @@
}; // CompletionItemsCollector
+bool isInformativeQualifierChunk(CodeCompletionString::Chunk const &Chunk) {
+ return Chunk.Kind == CodeCompletionString::CK_Informative &&
+ StringRef(Chunk.Text).endswith("::");
+}
+
class PlainTextCompletionItemsCollector final
: public CompletionItemsCollector {
@@ -395,6 +400,11 @@
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.
@@ -427,6 +437,11 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38083.116001.patch
Type: text/x-patch
Size: 2884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170920/8f7386c4/attachment.bin>
More information about the cfe-commits
mailing list