diff --git a/bin/benchmarks/matcher.lua b/bin/benchmarks/matcher.lua index bc7c6e3f..e9e17180 100755 --- a/bin/benchmarks/matcher.lua +++ b/bin/benchmarks/matcher.lua @@ -42,14 +42,14 @@ benchmark({ local input = '' for letter in query:gmatch('.') do local matches = lib.matcher_run(matcher, input) - for k = 0, matches.count - 1 do + for k = 0, matches.match_count - 1 do local str = matches.matches[k] ffi.string(str.contents, str.length) end input = input .. letter end local matches = lib.matcher_run(matcher, input) - for k = 0, matches.count - 1 do + for k = 0, matches.match_count - 1 do local str = matches.matches[k] ffi.string(str.contents, str.length) end diff --git a/lua/wincent/commandt/lib/matcher.c b/lua/wincent/commandt/lib/matcher.c index 32c44063..7c004e7d 100644 --- a/lua/wincent/commandt/lib/matcher.c +++ b/lua/wincent/commandt/lib/matcher.c @@ -236,11 +236,12 @@ result_t *commandt_matcher_run(matcher_t *matcher, const char *needle) { result_t *results = xmalloc(sizeof(result_t)); unsigned count = matches_count > limit ? limit : matches_count; results->matches = xmalloc(count * sizeof(const char *)); - results->count = 0; + results->match_count = 0; + results->candidate_count = candidate_count; - for (long i = 0; i < count && results->count <= limit; i++) { + for (long i = 0; i < count && results->match_count <= limit; i++) { if (matches[i]->score > 0.0f) { - results->matches[results->count++] = matches[i]->candidate; + results->matches[results->match_count++] = matches[i]->candidate; } } diff --git a/lua/wincent/commandt/lib/matcher.h b/lua/wincent/commandt/lib/matcher.h index 48bfd834..932987db 100644 --- a/lua/wincent/commandt/lib/matcher.h +++ b/lua/wincent/commandt/lib/matcher.h @@ -14,7 +14,8 @@ // TODO: may later want to return highlight positions as well typedef struct { str_t **matches; - unsigned count; + unsigned match_count; + unsigned candidate_count; } result_t; /** diff --git a/lua/wincent/commandt/private/finders/command.lua b/lua/wincent/commandt/private/finders/command.lua index 4bc0b7e5..8604f303 100644 --- a/lua/wincent/commandt/private/finders/command.lua +++ b/lua/wincent/commandt/private/finders/command.lua @@ -15,11 +15,11 @@ return function(directory, command, options) finder.run = function(query) local results = lib.matcher_run(finder.matcher, query) local strings = {} - for i = 0, results.count - 1 do + for i = 0, results.match_count - 1 do local str = results.matches[i] table.insert(strings, ffi.string(str.contents, str.length)) end - return strings + return strings, results.candidate_count end finder.open = options.open return finder diff --git a/lua/wincent/commandt/private/finders/file.lua b/lua/wincent/commandt/private/finders/file.lua index f5512c20..8b444d4c 100644 --- a/lua/wincent/commandt/private/finders/file.lua +++ b/lua/wincent/commandt/private/finders/file.lua @@ -13,11 +13,11 @@ return function(directory, options) finder.run = function(query) local results = lib.matcher_run(finder.matcher, query) local strings = {} - for i = 0, results.count - 1 do + for i = 0, results.match_count - 1 do local str = results.matches[i] table.insert(strings, ffi.string(str.contents, str.length)) end - return strings + return strings, results.candidate_count end finder.open = options.open return finder diff --git a/lua/wincent/commandt/private/finders/list.lua b/lua/wincent/commandt/private/finders/list.lua index 2a33d2fd..3c3e00ac 100644 --- a/lua/wincent/commandt/private/finders/list.lua +++ b/lua/wincent/commandt/private/finders/list.lua @@ -17,11 +17,11 @@ return function(directory, candidates, options) finder.run = function(query) local results = lib.matcher_run(finder.matcher, query) local strings = {} - for i = 0, results.count - 1 do + for i = 0, results.match_count - 1 do local str = results.matches[i] table.insert(strings, ffi.string(str.contents, str.length)) end - return strings + return strings, results.candidate_count end finder.open = options.open return finder diff --git a/lua/wincent/commandt/private/finders/watchman.lua b/lua/wincent/commandt/private/finders/watchman.lua index 96f42502..a7d9d3e3 100644 --- a/lua/wincent/commandt/private/finders/watchman.lua +++ b/lua/wincent/commandt/private/finders/watchman.lua @@ -14,11 +14,11 @@ return function(directory, options) finder.run = function(query) local results = lib.matcher_run(finder.matcher, query) local strings = {} - for i = 0, results.count - 1 do + for i = 0, results.match_count - 1 do local str = results.matches[i] table.insert(strings, ffi.string(str.contents, str.length)) end - return strings + return strings, results.candidate_count end finder.open = options.open return finder diff --git a/lua/wincent/commandt/private/lib.lua b/lua/wincent/commandt/private/lib.lua index 09b7717e..d45f21bd 100644 --- a/lua/wincent/commandt/private/lib.lua +++ b/lua/wincent/commandt/private/lib.lua @@ -56,7 +56,8 @@ setmetatable(c, { typedef struct { str_t **matches; - unsigned count; + unsigned match_count; + unsigned candidate_count; } result_t; typedef struct { diff --git a/lua/wincent/commandt/private/ui.lua b/lua/wincent/commandt/private/ui.lua index 1285b1c2..93d5f13c 100644 --- a/lua/wincent/commandt/private/ui.lua +++ b/lua/wincent/commandt/private/ui.lua @@ -6,6 +6,7 @@ local ui = {} local MatchListing = require('wincent.commandt.private.match_listing').MatchListing local Prompt = require('wincent.commandt.private.prompt').Prompt +local candidate_count = nil local cmdline_enter_autocmd = nil local current_finder = nil -- Reference to avoid premature garbage collection. local current_window = nil @@ -94,8 +95,8 @@ ui.show = function(finder, options) margin = options.margin, name = options.name, on_change = function(query) - results = current_finder.run(query) - if #results > 0 then + results, candidate_count = current_finder.run(query) + if #results > 0 or candidate_count > 0 then -- Once we've proved a finder works, we don't ever want to use fallback. current_finder.fallback = nil elseif current_finder.fallback then diff --git a/lua/wincent/commandt/test/matcher.lua b/lua/wincent/commandt/test/matcher.lua index a7aab2a3..81d3cfa8 100644 --- a/lua/wincent/commandt/test/matcher.lua +++ b/lua/wincent/commandt/test/matcher.lua @@ -14,7 +14,7 @@ describe('matcher.c', function() match = function(query) local results = lib.matcher_run(matcher, query) local strings = {} - for k = 0, results.count - 1 do + for k = 0, results.match_count - 1 do local str = results.matches[k] table.insert(strings, ffi.string(str.contents, str.length)) end