-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting completion candidates based on clang priority #519
base: master
Are you sure you want to change the base?
Conversation
Sorting completion candidates based on clang priority
Hello and thank you for proposing this change! Candidates are currently sorted according to Some frontends may like to sort them that way, e.g. when merging candidates from multiple backends. I do expose the priority to elisp, so that the frontend (e.g. company-irony) can sort accordingly. |
Hello and very nice mode by the way! Keep up the good work! I personally use it mainly for C++ with company-irony, and the reason why I submitted this pull request is that sorting according to libclang priority ( In that case, I think most users would expect to have the Now, sorting according to libclang priority:
I totally agree with you on that point, but I think you'll agree that alphabetical sorting should not prevail on the relevance of the completion. As you see, I could have just removed the call to What do you think ? |
I do think it's a legitimate use case, but I think it can be done in I believe you can wrap this around Do you see what I mean? |
I get what you mean, but I definitely think that sorting should not be done in the front end for obvious performance reasons. More over, it can very easily be disabled by the mean of a Now, I do not see the need for disabling it, as totally ignoring clang priority actually leads up to incorrect completions in my opinion. And as I said above, alphabetical sorting is not put apart, it is just improved by taking into account the clang priority. |
Sorting in C++ could be faster, but sorting in company, assuming the default prefix length of size 3, does not sort all the candidates, but only a subset. Ok for prefix and style-like method, I would accept such PR. |
…ng by the mean of a defcustom variable
@@ -102,7 +102,7 @@ class Irony { | |||
/// Get all the completion candidates. | |||
/// | |||
/// \pre complete() was called. | |||
void candidates(const std::string &prefix, PrefixMatchStyle style) const; | |||
void candidates(const std::string &prefix, PrefixMatchStyle style, const std::string &sorting) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do like PrefixMatchStyle, and make a dedicated enum to represent the possibles values instead of storing it as a string.
@@ -181,7 +181,7 @@ int main(int ac, const char *av[]) { | |||
break; | |||
|
|||
case Command::Candidates: | |||
irony.candidates(c->prefix, c->style); | |||
irony.candidates(c->prefix, c->style, c->sorting); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could make more sense to do this in the complete
command, instead of candidates
.
complete
is called once but candidates many time.
Since the sorting does not depend on the candidates
input, it may be better to do the sorting once, next to the sorting done by clang.
@@ -221,6 +221,7 @@ Command *CommandParser::parse(const std::vector<std::string> &argv) { | |||
case Command::Candidates: | |||
positionalArgs.push_back(StringConverter(&command_.prefix)); | |||
positionalArgs.push_back(PrefixMatchStyleConverter(&command_.style)); | |||
positionalArgs.push_back(StringConverter(&command_.sorting)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to modify Command.def as well, to change the description of the command (which I recommend below to apply to the complete
command, instead of candidates
).
@@ -180,6 +180,17 @@ Larger values can improve performances on large buffers. | |||
If non-nil, `w32-pipe-buffer-size' will be let-bound to this value | |||
during the creation of the irony-server process.") | |||
|
|||
(defcustom irony-candidates-clang-sorting nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of vocabulary, I think I would do something like:
sorting-method: priority
, alphabetical
.
I would not allow nil, but instead produce an error.
nil
seems to imply this is the soundest default value, which I am not yet sure.
A more neutral approach is to have enumeration value, and if one make more sense than the other, the defcustom will be updated accordingly.
I'm mostly thinking about a future 3rd option coming up, that would be the best default value.
Sorting completion candidates based on clang priority