Skip to content

Commit 7f9a32a

Browse files
Add function suggestions
1 parent df1cfba commit 7f9a32a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

myplugin/plugin/myplugin.vim

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,23 @@ for module_name in module_names:
5656
module = importlib.util.module_from_spec(spec)
5757
spec.loader.exec_module(module)
5858
functions = [f for f in dir(module) if callable(getattr(module, f))]
59+
suggestions = str(functions)
5960

6061
command_name = module_name.capitalize()
62+
63+
vim.command(f"""
64+
function! Complete{command_name}(ArgLead, CmdLine, CursorPos) abort
65+
let cmd_parts = split(a:CmdLine)
66+
if len(cmd_parts) == 1
67+
return {suggestions}
68+
else
69+
return []
70+
endif
71+
endfunction
72+
""")
73+
6174
command_string = 'call CallPythonFunction("' + command_name + '", "' + module_name + '", <q-args>)'
62-
command = 'command! -nargs=* ' + command_name + ' :execute \'' + command_string + '\''
63-
print(command)
75+
command = 'command! -nargs=* -complete=customlist,Complete' + command_name + ' ' + command_name + ' :execute \'' + command_string + '\''
6476
vim.command(command)
6577
EOF
6678
endfunction

0 commit comments

Comments
 (0)