break: streamlining of some function returns in the c library (#58)

breaking changes for c ABI. unrelated for lua users.

- `get_positions` can now return NULL for an empty pattern input
- `get_score` will now return 1 for an empty pattern input. previously handled in the telescope lua part of the code. Now its moved to c
This commit is contained in:
Simon Hauser
2022-02-18 20:51:18 +01:00
committed by GitHub
parent cce2db6b13
commit 1b5d0cba81
3 changed files with 16 additions and 4 deletions

View File

@@ -49,6 +49,10 @@ end
fzf.get_pos = function(input, pattern_struct, slab)
local pos = native.fzf_get_positions(input, pattern_struct, slab)
if pos == nil then
return
end
local res = {}
for i = 1, tonumber(pos.size) do
res[i] = pos.data[i - 1] + 1

View File

@@ -90,10 +90,6 @@ local get_fzf_sorter = function(opts)
discard = true,
scoring_function = function(self, prompt, line)
local obj = get_struct(self, prompt)
if obj.size == 0 then
return 1
end
local score = fzf.get_score(line, obj, self.state.slab)
if score == 0 then
return -1

View File

@@ -1200,6 +1200,12 @@ void fzf_free_pattern(fzf_pattern_t *pattern) {
int32_t fzf_get_score(const char *text, fzf_pattern_t *pattern,
fzf_slab_t *slab) {
// If the pattern is an empty string then pattern->ptr will be NULL and we
// basically don't want to filter. Return 1 for telescope
if (pattern->ptr == NULL) {
return 1;
}
fzf_string_t input = {.data = text, .size = strlen(text)};
if (pattern->only_inv) {
@@ -1244,6 +1250,12 @@ int32_t fzf_get_score(const char *text, fzf_pattern_t *pattern,
fzf_position_t *fzf_get_positions(const char *text, fzf_pattern_t *pattern,
fzf_slab_t *slab) {
// If the pattern is an empty string then pattern->ptr will be NULL and we
// basically don't want to filter. Return 1 for telescope
if (pattern->ptr == NULL) {
return NULL;
}
fzf_string_t input = {.data = text, .size = strlen(text)};
fzf_position_t *all_pos = pos_array(true, 1);