summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-06-15 09:11:57 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-06-15 09:11:57 +0000
commita1de3c91e5d7079d87a80f71ce90a8407b37d583 (patch)
tree0f1f5127ea4787792dcbc459b598d8364b740086
parent9a102b09244b0caf56040122ab9caa64aca08705 (diff)
downloadbcm5719-llvm-a1de3c91e5d7079d87a80f71ce90a8407b37d583.tar.gz
bcm5719-llvm-a1de3c91e5d7079d87a80f71ce90a8407b37d583.zip
[clangd] Add priority to completion item sort text
Summary: This patch adds the priority of a completion item to the sort text of the returned LSP result. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34137 llvm-svn: 305454
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp13
-rw-r--r--clang-tools-extra/test/clangd/authority-less-uri.test4
-rw-r--r--clang-tools-extra/test/clangd/completion.test26
3 files changed, 27 insertions, 16 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index 9fc9a7ccda0..218b2c75be2 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -13,6 +13,7 @@
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/Utils.h"
#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/Format.h"
using namespace clang::clangd;
using namespace clang;
@@ -153,7 +154,17 @@ public:
}
assert(CCS->getTypedText());
Item.kind = getKind(Result.CursorKind);
- Item.insertText = Item.sortText = Item.filterText = CCS->getTypedText();
+ // Priority is a 16-bit integer, hence at most 5 digits.
+ // Since identifiers with higher priority need to come first,
+ // we subtract the priority from 99999.
+ // For example, the sort text of the identifier 'a' with priority 35
+ // is 99964a.
+ assert(CCS->getPriority() < 99999 && "Expecting code completion result "
+ "priority to have at most "
+ "5-digits");
+ llvm::raw_string_ostream(Item.sortText) << llvm::format(
+ "%05d%s", 99999 - CCS->getPriority(), CCS->getTypedText());
+ Item.insertText = Item.filterText = CCS->getTypedText();
if (CCS->getBriefComment())
Item.documentation = CCS->getBriefComment();
Items->push_back(std::move(Item));
diff --git a/clang-tools-extra/test/clangd/authority-less-uri.test b/clang-tools-extra/test/clangd/authority-less-uri.test
index 94f7e96261a..f52f0ea173b 100644
--- a/clang-tools-extra/test/clangd/authority-less-uri.test
+++ b/clang-tools-extra/test/clangd/authority-less-uri.test
@@ -16,7 +16,7 @@ Content-Length: 146
# Test authority-less URI
#
# CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
# CHECK: ]}
Content-Length: 172
@@ -25,7 +25,7 @@ Content-Length: 172
# Test params parsing in the presence of a 1.x-compatible client (inlined "uri")
#
# CHECK: {"jsonrpc":"2.0","id":2,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
# CHECK: ]}
Content-Length: 44
diff --git a/clang-tools-extra/test/clangd/completion.test b/clang-tools-extra/test/clangd/completion.test
index 628706b415d..f99c33bc1c2 100644
--- a/clang-tools-extra/test/clangd/completion.test
+++ b/clang-tools-extra/test/clangd/completion.test
@@ -16,12 +16,12 @@ Content-Length: 148
# nondeterministic, so we check regardless of order.
#
# CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"99964ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"99965operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"99965~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"99964f","filterText":"f","insertText":"f"}
# CHECK: ]}
Content-Length: 148
@@ -29,12 +29,12 @@ Content-Length: 148
# Repeat the completion request, expect the same results.
#
# CHECK: {"jsonrpc":"2.0","id":2,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"99964ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"99965operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"99965~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"99964f","filterText":"f","insertText":"f"}
# CHECK: ]}
# Update the source file and check for completions again.
Content-Length: 226
@@ -47,7 +47,7 @@ Content-Length: 148
# Repeat the completion request, expect the same results.
#
# CHECK: {"jsonrpc":"2.0","id":3,"result":[
-# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"func","filterText":"func","insertText":"func"}
+# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"99965func","filterText":"func","insertText":"func"}
# CHECK: ]}
Content-Length: 44
OpenPOWER on IntegriCloud