hotpxl / company-irony-c-headers

Company mode backend for C/C++ header files with Irony
GNU General Public License v3.0
30 stars 3 forks source link

Sorting order is confusing sometimes #13

Open ddovod opened 8 years ago

ddovod commented 8 years ago

Hello. Assume we have some files: SomeClass.h SomeClass.cpp main.cpp

I would like to unclude SomeClass.h into main.cpp, so: main.cpp:

include "Some|

SomeClass.cpp
SomeClass.h

First candidate is .cpp file, but in 99% cases I would like to include .h, .hpp, .inl and other files, but not .cpp. I think this is due to 'sort' function, and 'c' is smaller than 'h', right? Is there any way to customize sorting behavior? Thank you a lot!

hotpxl commented 8 years ago

Yes currently I use string< to sort. SomeClass.h and SomeClass.cpp usually stick together and a single M-n will get you to the right choice. I don't want to complicate the sorting function for now. It's hard to come up with a general rule for sorting.

ddovod commented 8 years ago

Ok, thank you for response! Maybe you can implement the ability to set custom comparator for sorting algo which can be set manually? So anybody would have instrument to tweak behavior a bit without bloody patching of original code?

ddovod commented 8 years ago

I have no many experience in elisp, but I can try to implement such thing and create a PR, don't you mind?

hotpxl commented 8 years ago

I can defvar a some kind of post completion hook and I'll hand you all the candidates. You can do reordering or filtering or whatever you want. Does this look good to you?

ddovod commented 8 years ago

Yes, sounds good!

hotpxl commented 8 years ago

I added a post completion hook and tried to reverse the list myself. It worked on my side. But after I returned those results to company, looks like company has sorted them again. I wonder if there anything on company side that prevents me from specifying a specific order.

ddovod commented 8 years ago

company.el:

(defun company--preprocess-candidates (candidates)
  (cl-assert (cl-every #'stringp candidates))
  (unless (company-call-backend 'sorted)
    (setq candidates (sort candidates 'string<)))
  (when (company-call-backend 'duplicates)
    (company--strip-duplicates candidates))
  candidates)

Maybe I should create issue in the company-mode github repo = ( But your addition will be helpful no matter what. Thank you again!

hotpxl commented 8 years ago

Strangely I already set 'sorted to t, but it's still doing a sort for me somehow.