summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--autoload/vim_ai.vim9
-rw-r--r--plugin/vim-ai.vim10
-rw-r--r--py/roles.py16
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}')