lua: Change CompletionRequested handler to use an event table. (#5280)
This commit is contained in:
Vendored
+8
-6
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user