Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/extern/isocline/src/completions.h
2727 views
1
/* ----------------------------------------------------------------------------
2
Copyright (c) 2021, Daan Leijen
3
This is free software; you can redistribute it and/or modify it
4
under the terms of the MIT License. A copy of the license can be
5
found in the "LICENSE" file at the root of this distribution.
6
-----------------------------------------------------------------------------*/
7
#pragma once
8
#ifndef IC_COMPLETIONS_H
9
#define IC_COMPLETIONS_H
10
11
#include "common.h"
12
#include "stringbuf.h"
13
14
15
//-------------------------------------------------------------
16
// Completions
17
//-------------------------------------------------------------
18
#define IC_MAX_COMPLETIONS_TO_SHOW (1000)
19
#define IC_MAX_COMPLETIONS_TO_TRY (IC_MAX_COMPLETIONS_TO_SHOW/4)
20
21
typedef struct completions_s completions_t;
22
23
ic_private completions_t* completions_new(alloc_t* mem);
24
ic_private void completions_free(completions_t* cms);
25
ic_private void completions_clear(completions_t* cms);
26
ic_private bool completions_add(completions_t* cms , const char* replacement, const char* display, const char* help, ssize_t delete_before, ssize_t delete_after);
27
ic_private ssize_t completions_count(completions_t* cms);
28
ic_private ssize_t completions_generate(struct ic_env_s* env, completions_t* cms , const char* input, ssize_t pos, ssize_t max);
29
ic_private void completions_sort(completions_t* cms);
30
ic_private void completions_set_completer(completions_t* cms, ic_completer_fun_t* completer, void* arg);
31
ic_private const char* completions_get_display(completions_t* cms , ssize_t index, const char** help);
32
ic_private const char* completions_get_hint(completions_t* cms, ssize_t index, const char** help);
33
ic_private void completions_get_completer(completions_t* cms, ic_completer_fun_t** completer, void** arg);
34
35
ic_private ssize_t completions_apply(completions_t* cms, ssize_t index, stringbuf_t* sbuf, ssize_t pos);
36
ic_private ssize_t completions_apply_longest_prefix(completions_t* cms, stringbuf_t* sbuf, ssize_t pos);
37
38
//-------------------------------------------------------------
39
// Completion environment
40
//-------------------------------------------------------------
41
typedef bool (ic_completion_fun_t)( ic_env_t* env, void* funenv, const char* replacement, const char* display, const char* help, long delete_before, long delete_after );
42
43
struct ic_completion_env_s {
44
ic_env_t* env; // the isocline environment
45
const char* input; // current full input
46
long cursor; // current cursor position
47
void* arg; // argument given to `ic_set_completer`
48
void* closure; // free variables for function composition
49
ic_completion_fun_t* complete; // function that adds a completion
50
};
51
52
#endif // IC_COMPLETIONS_H
53
54