Skip to content

Commit

Permalink
feat: allow to use callback for command completion
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Mar 13, 2023
1 parent 4b06111 commit 72e30c2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"externs"
],
"description": "Create neovim plugins using Haxe",
"version": "0.2.0",
"version": "0.2.1",
"classPath": "src/",
"releasenote": "properly working as a lib",
"contributors": [
Expand Down
32 changes: 30 additions & 2 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ function main() {
}
);

vim.Api.nvim_create_user_command_complete_cb("HaxeCmdCompletion", (args) -> {
Vim.print(args);
final spellRes = Spell.check("Hello bru! Hau are you?");
Vim.print(spellRes[1].first());
vim.Ui.select(t(["a"]), {prompt: "Pick one sexy option"}, (choice, _) -> Vim.print(choice));
}, {
desc: "Testing from haxe for completion callback",
force: true,
bang: true,
nargs: ExactlyOne,
range: WholeFile,
complete: (lead:String, full:String, x:Int) -> {
Vim.print(lead, full, x);
return t(["afa", "bea", lead + "bro"]);
}
});

Vimx.autocmd('HaxeEvent', [BufWritePost], "*.hx", "Created from haxe", () -> {
var filename = Vim.expand(ExpandString.plus(CurentFile, FullPath));
Vim.print('Hello from axe', filename);
Expand Down Expand Up @@ -95,7 +112,12 @@ function runGh(args):Null< lua.Table< Int, String > > {
function openInGh(?line) {
final currentFile = vim.Fn.expand(CurentFile);
final curentBranch = get_branch();
runGh(["browse", currentFile + line, "--branch", curentBranch[1]]);
runGh([
"browse",
currentFile + line,
"--branch",
curentBranch[1]
]);
}

function get_branch() {
Expand Down Expand Up @@ -126,7 +148,13 @@ function nexTab() {
function copyGhUrl(?line) {
final currentFile = vim.Fn.expand(new ExpandString(CurentFile) + RelativePath);
final curentBranch = get_branch();
var lines = runGh(["browse", currentFile + line, "--no-browser", "--branch", curentBranch[1]]);
var lines = runGh([
"browse",
currentFile + line,
"--no-browser",
"--branch",
curentBranch[1]
]);
switch (lines) {
case null:
Vim.print("No URL");
Expand Down
25 changes: 25 additions & 0 deletions src/vim/Api.hx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ extern class Api {
?range:CmdRange,
} >
):Void;

/**
Same as create user command, but this is specifically typed
for completion callbacks.
Completion callback should take the following arguments:
ArgLead, CmdLine, CursorPos
Where:
ArgLead: The current value of the argument being completed
CmdLine: The full command line text
CursorPos: The current cursor position in the command line
*/
@:native('nvim_create_user_command')
static function nvim_create_user_command_complete_cb(
command_name:String,
command:LuaObj< CommandCallbackArgs > -> Void,
opts:TableWrapper< {
desc:String,
force:Bool,
complete:(String, String, Int) -> lua.Table< Int, String >,
nargs:Nargs,
?bang:Bool,
?range:CmdRange,
} >
):Void;

static inline function create_user_command_completion(
command_name:String,
command:LuaObj< CommandCallbackArgs > -> Void,
Expand Down

0 comments on commit 72e30c2

Please sign in to comment.