lua: Change CompletionRequested handler to use an event table. (#5280)

This commit is contained in:
Mm2PL
2024-03-30 15:23:02 +01:00
committed by GitHub
parent b35f10fa54
commit d4b8feac7d
8 changed files with 62 additions and 15 deletions
+8 -6
View File
@@ -75,6 +75,13 @@ declare module c2 {
handler: (ctx: CommandContext) => void
): boolean;
class CompletionEvent {
query: string;
full_text_content: string;
cursor_position: number;
is_first_word: boolean;
}
class CompletionList {
values: String[];
hide_others: boolean;
@@ -84,12 +91,7 @@ declare module c2 {
CompletionRequested = "CompletionRequested",
}
type CbFuncCompletionsRequested = (
query: string,
full_text_content: string,
cursor_position: number,
is_first_word: boolean
) => CompletionList;
type CbFuncCompletionsRequested = (ev: CompletionEvent) => CompletionList;
type CbFunc<T> = T extends EventType.CompletionRequested
? CbFuncCompletionsRequested
: never;
+3 -3
View File
@@ -167,7 +167,7 @@ Limitations/known issues:
#### `register_callback("CompletionRequested", handler)`
Registers a callback (`handler`) to process completions. The callback gets the following parameters:
Registers a callback (`handler`) to process completions. The callback takes a single table with the following entries:
- `query`: The queried word.
- `full_text_content`: The whole input.
@@ -190,8 +190,8 @@ end
c2.register_callback(
"CompletionRequested",
function(query, full_text_content, cursor_position, is_first_word)
if ("!join"):startswith(query) then
function(event)
if ("!join"):startswith(event.query) then
---@type CompletionList
return { hide_others = true, values = { "!join" } }
end