mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Convert priority to a string properly for sortText
Cast the number to a char directly sometimes results in a invalid UTF-8 string, which is not good for some clients.
This commit is contained in:
parent
77ccee10ce
commit
93fb746992
@ -27,10 +27,12 @@ unsigned Flags() {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCompletionPriority(const CXCompletionString& str,
|
unsigned GetCompletionPriority(const CXCompletionString& str,
|
||||||
CXCursorKind result_kind,
|
CXCursorKind result_kind,
|
||||||
const std::string& label) {
|
const std::string& label) {
|
||||||
int priority = clang_getCompletionPriority(str);
|
unsigned priority = clang_getCompletionPriority(str);
|
||||||
|
|
||||||
|
// XXX: What happens if priority overflows?
|
||||||
if (result_kind == CXCursor_Destructor) {
|
if (result_kind == CXCursor_Destructor) {
|
||||||
priority *= 100;
|
priority *= 100;
|
||||||
}
|
}
|
||||||
@ -44,6 +46,20 @@ int GetCompletionPriority(const CXCompletionString& str,
|
|||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
char *tofixedbase64(T input, char *out) {
|
||||||
|
const char *digits = "./0123456789"
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz";
|
||||||
|
int len = (sizeof(T)*8-1)/6+1;
|
||||||
|
for (int i = len-1; i >= 0; i--) {
|
||||||
|
out[i] = digits[input%64];
|
||||||
|
input /= 64;
|
||||||
|
}
|
||||||
|
out[len] = '\0';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool IsCallKind(CXCursorKind kind) {
|
bool IsCallKind(CXCursorKind kind) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
@ -431,10 +447,12 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
|
|||||||
|
|
||||||
ls_completion_item.documentation = ToString(
|
ls_completion_item.documentation = ToString(
|
||||||
clang_getCompletionBriefComment(result.CompletionString));
|
clang_getCompletionBriefComment(result.CompletionString));
|
||||||
|
|
||||||
|
char buf[16];
|
||||||
ls_completion_item.sortText =
|
ls_completion_item.sortText =
|
||||||
(const char)uint64_t(GetCompletionPriority(
|
tofixedbase64(GetCompletionPriority(
|
||||||
result.CompletionString, result.CursorKind,
|
result.CompletionString, result.CursorKind,
|
||||||
ls_completion_item.label));
|
ls_completion_item.label), buf);
|
||||||
|
|
||||||
ls_result.push_back(ls_completion_item);
|
ls_result.push_back(ls_completion_item);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user