diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2024-03-09 19:08:34 +0100 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2024-03-09 19:08:34 +0100 |
| commit | 9db190c977d1f76e2f574882e4edde062eecbb0d (patch) | |
| tree | 72f75b29fe406f6ddebf8419e966d77cc8a7ad31 | |
| parent | bdd1069562967bd07921e75873d54eb75d62144d (diff) | |
| download | vim-ai-9db190c977d1f76e2f574882e4edde062eecbb0d.tar.gz | |
roles completion
| -rw-r--r-- | autoload/vim_ai.vim | 9 | ||||
| -rw-r--r-- | plugin/vim-ai.vim | 10 | ||||
| -rw-r--r-- | py/roles.py | 16 |
3 files changed, 30 insertions, 5 deletions
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index 74515d4..302ef1d 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -1,8 +1,10 @@ call vim_ai_config#load() + let s:plugin_root = expand('<sfile>:p:h:h') let s:complete_py = s:plugin_root . "/py/complete.py" let s:chat_py = s:plugin_root . "/py/chat.py" +let s:roles_py = s:plugin_root . "/py/roles.py" " remembers last command parameters to be used in AIRedoRun let s:last_is_selection = 0 @@ -249,3 +251,10 @@ function! vim_ai#AIRedoRun() call vim_ai#AIChatRun(0, s:last_config) endif endfunction + +function! vim_ai#RoleCompletion(A,L,P) abort + execute "py3file " . s:roles_py + call map(l:role_list, '"/" . v:val') + echom a:A + return filter(l:role_list, 'v:val =~ "^' . a:A . '"') +endfunction diff --git a/plugin/vim-ai.vim b/plugin/vim-ai.vim index 0e4957f..1ed5326 100644 --- a/plugin/vim-ai.vim +++ b/plugin/vim-ai.vim @@ -12,11 +12,11 @@ augroup vim_ai \ let g:vim_ai_is_selection_pending = mode() =~# "^[vV\<C-v>]" augroup END -command! -range -nargs=? AI <line1>,<line2>call vim_ai#AIRun({}, <q-args>) -command! -range -nargs=? AIEdit <line1>,<line2>call vim_ai#AIEditRun({}, <q-args>) +command! -range -nargs=? -complete=customlist,vim_ai#RoleCompletion AI <line1>,<line2>call vim_ai#AIRun({}, <q-args>) +command! -range -nargs=? -complete=customlist,vim_ai#RoleCompletion AIEdit <line1>,<line2>call vim_ai#AIEditRun({}, <q-args>) " Whereas AI and AIEdit default to passing the current line as range " AIChat defaults to passing nothing which is achieved by -range=0 and passing " <count> as described at https://stackoverflow.com/a/20133772 -command! -range=0 -nargs=? AIChat <line1>,<line2>call vim_ai#AIChatRun(<count>, {}, <q-args>) -command! -nargs=? AINewChat call vim_ai#AINewChatRun(<f-args>) -command! AIRedo call vim_ai#AIRedoRun() +command! -range=0 -nargs=? -complete=customlist,vim_ai#RoleCompletion AIChat <line1>,<line2>call vim_ai#AIChatRun(<count>, {}, <q-args>) +command! -nargs=? AINewChat call vim_ai#AINewChatRun(<f-args>) +command! AIRedo call vim_ai#AIRedoRun() diff --git a/py/roles.py b/py/roles.py new file mode 100644 index 0000000..8f7f161 --- /dev/null +++ b/py/roles.py @@ -0,0 +1,16 @@ +import vim +import os +import configparser + +roles_config_path = os.path.expanduser('~/.vim/roles.ini') # TODO configure +roles = configparser.ConfigParser() +roles.read(roles_config_path) + +role_names = [name for name in roles.sections() if not '.' in name] + +role_list = [f'"{name}"' for name in role_names] +role_list = ", ".join(role_list) + +role_list = f"[{role_list}]" + +vim.command(f'let l:role_list = {role_list}') |