Skip to content

Commit

Permalink
feat: add demo() function
Browse files Browse the repository at this point in the history
Use like this:

   :lua require('wincent.commandt').demo()

And witness the marvellous results:

   zsh: segmentation fault (core dumped)  nvim

Will continue working on this tomorrow.
  • Loading branch information
wincent committed Jul 1, 2022
1 parent 7dfb47c commit 0b5d3eb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
47 changes: 42 additions & 5 deletions lua/wincent/commandt/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ local load = function ()
float score;
} haystack_t;

typedef struct {
const char **candidates;
long count;
unsigned version;
} scanner_t;

typedef struct {
scanner_t *scanner;
bool always_show_dot_files;
bool case_sensitive;
bool ignore_spaces;
bool never_show_dot_files;
bool recurse;
bool sort;
unsigned limit;
int threads;
const char *last_needle;
unsigned long last_needle_length;
} matcher_t;

//typedef struct {
// size_t count;
// const char **matches;
//} matches_t;

typedef struct {
long count;
long *indices;
} result_t;

result_t *commandt_matcher_run(matcher_t *matcher, const char *needle);

result_t *commandt_temporary_demo_function();

float commandt_calculate_match(
haystack_t *haystack,
const char *needle,
Expand All @@ -42,12 +76,9 @@ local load = function ()
long needle_bitmask
);

typedef struct {
size_t count;
const char **matches;
} matches_t;
void commandt_result_free(result_t *result);

matches_t commandt_sorted_matches_for(const char *needle);
//matches_t commandt_sorted_matches_for(const char *needle);
]]
-- TODO: avoid this; prefer to call destructor instead with ffi.gc and let
-- C-side code do the freeing...
Expand Down Expand Up @@ -242,6 +273,12 @@ commandt.cmdline_leave = function()
tear_down_mappings()
end

commandt.demo = function()
local l = load()
local result = l.commandt_temporary_demo_function()
print(vim.inspect(result))
end

commandt.file_finder = function(arg)
local directory = vim.trim(arg)

Expand Down
14 changes: 14 additions & 0 deletions lua/wincent/commandt/matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ void commandt_result_free(result_t *result) {
free(result);
}

result_t *commandt_temporary_demo_function() {
scanner_t *scanner = xmalloc(sizeof(scanner_t));
scanner->candidates = xmalloc(5 * sizeof(void *));
scanner->count = 5;
scanner->version = 0;
scanner->candidates[0] = "thing";
scanner->candidates[1] = "foo";
scanner->candidates[2] = "a longer string";
scanner->candidates[3] = "some stuff like this";
scanner->candidates[4] = "and some s t u f f like that";
matcher_t *matcher = commandt_matcher_new(scanner, true, false);
return commandt_matcher_run(matcher, "stuff");
}

static long calculate_bitmask(const char *str) {
unsigned long len = strlen(str);
unsigned long i;
Expand Down

0 comments on commit 0b5d3eb

Please sign in to comment.