Skip to content

Commit

Permalink
libclang.py: Introduce option sorting=none
Browse files Browse the repository at this point in the history
0.34 -> 0.28 sec completion time on (examples/boost.cpp)

This was compared to soring=alpha

No sorting makes sense as vim will automatically sort the results as
soon as we type the first character. So spending a lot of time on
sorting may not be worth it.

In later patches I will try to speed up our own sorting, such that it
becomes less an issue. clang already provides a c function for this.
Though at the moment this function does not work for me (it crashes).
  • Loading branch information
tobiasgrosser committed Feb 2, 2012
1 parent acbd61f commit f31fbca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/clang_complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ Default: ""

*clang_complete-sort_algo*
*g:clang_sort_algo*
How results are sorted (alpha, priority). Currently only works with libclang.
How results are sorted (alpha, priority, none). Currently only works with
libclang.
Default: "priority"

*clang_complete-complete_macros*
Expand Down
2 changes: 1 addition & 1 deletion examples/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

int main()
{
boost:
boost::matc
// ^ Code complete here by typing ":"
}
6 changes: 3 additions & 3 deletions plugin/libclang.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def WarmupCache():
def getCurrentCompletions(base):
global debug
debug = int(vim.eval("g:clang_debug")) == 1
priority = vim.eval("g:clang_sort_algo") == 'priority'
sorting = vim.eval("g:clang_sort_algo")
line = int(vim.eval("line('.')"))
column = int(vim.eval("b:col"))

Expand All @@ -278,10 +278,10 @@ def getCurrentCompletions(base):
regexp = re.compile("^" + base)
results = filter(lambda x: regexp.match(getAbbr(x.string)), results)

if priority:
if sorting == 'priority':
getPriority = lambda x: x.string.priority
results = sorted(results, None, getPriority)
else:
if sorting == 'alpha':
getAbbrevation = lambda x: getAbbr(x.string).lower()
results = sorted(results, None, getAbbrevation)

Expand Down

0 comments on commit f31fbca

Please sign in to comment.