aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2017-07-27 17:43:07 +0000
committerIlya Biryukov <ibiryukov@google.com>2017-07-27 17:43:07 +0000
commitde46274d7bb41dcd9195d3436dc585fd64326ec0 (patch)
tree369145fa5d57a38207063e29b784990f0df47bb4
parent0d8b5d6f6997066cd243a06f0a7181de966c8cef (diff)
[clangd] Don't reverse priorities of completion items.
Summary: Current algorithm incorrectly provides completion results in a reverse order. Reviewers: krasimir, bkramer Reviewed By: krasimir Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D35950 llvm-svn: 309295
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp8
-rw-r--r--clang-tools-extra/test/clangd/authority-less-uri.test4
-rw-r--r--clang-tools-extra/test/clangd/completion.test28
3 files changed, 18 insertions, 22 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index 35765b7823ba..7b2a45a39946 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -370,15 +370,11 @@ public:
assert(CCS->getTypedText());
Item.kind = getKind(Result.CursorKind);
// 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());
+ llvm::raw_string_ostream(Item.sortText)
+ << llvm::format("%05d%s", CCS->getPriority(), CCS->getTypedText());
Item.insertText = Item.filterText = CCS->getTypedText();
if (CCS->getBriefComment())
Item.documentation = CCS->getBriefComment();
diff --git a/clang-tools-extra/test/clangd/authority-less-uri.test b/clang-tools-extra/test/clangd/authority-less-uri.test
index f52f0ea173bb..6e55976e4fb5 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":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","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":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","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 f99c33bc1c2c..4d24a34a31b6 100644
--- a/clang-tools-extra/test/clangd/completion.test
+++ b/clang-tools-extra/test/clangd/completion.test
@@ -12,16 +12,16 @@ Content-Length: 246
Content-Length: 148
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
-# The order of results returned by ASTUnit CodeComplete seems to be
+# The order of results returned by codeComplete seems to be
# nondeterministic, so we check regardless of order.
#
# CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# 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-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","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":"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-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","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":"99965func","filterText":"func","insertText":"func"}
+# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"00034func","filterText":"func","insertText":"func"}
# CHECK: ]}
Content-Length: 44