diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-04-15 12:35:06 +0200 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-04-15 12:35:06 +0200 |
| commit | eb07c3615b926ce667bc273c03e8cbc8b85c6505 (patch) | |
| tree | 1b31488e65c2714cfb1c8ed568de7772cf8bf87c | |
| parent | d559f97bd3e6b3f30c5603466cbcbff162f847fe (diff) | |
| download | vim-ai-eb07c3615b926ce667bc273c03e8cbc8b85c6505.tar.gz | |
using scoped variables
Diffstat (limited to '')
| -rw-r--r-- | autoload/vim_ai.vim | 59 | ||||
| -rw-r--r-- | py/chat.py | 4 | ||||
| -rw-r--r-- | py/complete.py | 6 |
3 files changed, 34 insertions, 35 deletions
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index 502b601..451c2df 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -43,28 +43,27 @@ function! vim_ai#MakeScratchWindow() endfunction function! MakePrompt(is_selection, lines, instruction) - let lines = trim(join(a:lines, "\n")) - let instruction = trim(a:instruction) - let delimiter = instruction != "" && a:is_selection ? ":\n" : "" - let selection = a:is_selection || instruction == "" ? lines : "" - let prompt = join([instruction, delimiter, selection], "") - return prompt + let l:lines = trim(join(a:lines, "\n")) + let l:instruction = trim(a:instruction) + let l:delimiter = l:instruction != "" && a:is_selection ? ":\n" : "" + let l:selection = a:is_selection || l:instruction == "" ? l:lines : "" + return join([l:instruction, l:delimiter, l:selection], "") endfunction function! vim_ai#AIRun(is_selection, ...) range - let instruction = a:0 ? a:1 : "" - let lines = getline(a:firstline, a:lastline) - let prompt = MakePrompt(a:is_selection, lines, instruction) + let l:instruction = a:0 ? a:1 : "" + let l:lines = getline(a:firstline, a:lastline) + let l:prompt = MakePrompt(a:is_selection, l:lines, l:instruction) let s:last_command = "complete" - let s:last_instruction = instruction + let s:last_instruction = l:instruction let s:last_is_selection = a:is_selection - let engine = g:vim_ai_complete['engine'] - let options = g:vim_ai_complete['options'] - let cursor_on_empty_line = trim(join(lines, "\n")) == "" + let l:engine = g:vim_ai_complete['engine'] + let l:options = g:vim_ai_complete['options'] + let l:cursor_on_empty_line = trim(join(l:lines, "\n")) == "" set paste - if cursor_on_empty_line + if l:cursor_on_empty_line execute "normal! " . a:lastline . "GA" else execute "normal! " . a:lastline . "Go" @@ -75,15 +74,15 @@ function! vim_ai#AIRun(is_selection, ...) range endfunction function! vim_ai#AIEditRun(is_selection, ...) range - let instruction = a:0 ? a:1 : "" - let prompt = MakePrompt(a:is_selection, getline(a:firstline, a:lastline), instruction) + let l:instruction = a:0 ? a:1 : "" + let l:prompt = MakePrompt(a:is_selection, getline(a:firstline, a:lastline), l:instruction) let s:last_command = "edit" - let s:last_instruction = instruction + let s:last_instruction = l:instruction let s:last_is_selection = a:is_selection - let engine = g:vim_ai_edit['engine'] - let options = g:vim_ai_edit['options'] + let l:engine = g:vim_ai_edit['engine'] + let l:options = g:vim_ai_edit['options'] set paste execute "normal! " . a:firstline . "GV" . a:lastline . "Gc" execute "py3file " . s:complete_py @@ -91,27 +90,27 @@ function! vim_ai#AIEditRun(is_selection, ...) range endfunction function! vim_ai#AIChatRun(is_selection, ...) range - let instruction = "" - let lines = getline(a:firstline, a:lastline) + let l:instruction = "" + let l:lines = getline(a:firstline, a:lastline) set paste - let is_outside_of_chat_window = search('^>>> user$', 'nw') == 0 - if is_outside_of_chat_window + let l:is_outside_of_chat_window = search('^>>> user$', 'nw') == 0 + if l:is_outside_of_chat_window " open chat window execute g:vim_ai_chat['ui']['open_chat_command'] - let prompt = "" + let l:prompt = "" if a:0 || a:is_selection - let instruction = a:0 ? a:1 : "" - let prompt = MakePrompt(a:is_selection, lines, instruction) + let l:instruction = a:0 ? a:1 : "" + let l:prompt = MakePrompt(a:is_selection, l:lines, l:instruction) endif - execute "normal! Gi" . prompt + execute "normal! Gi" . l:prompt endif let s:last_command = "chat" - let s:last_instruction = instruction + let s:last_instruction = l:instruction let s:last_is_selection = a:is_selection - let options = g:vim_ai_chat['options'] - let ui = g:vim_ai_chat['ui'] + let l:options = g:vim_ai_chat['options'] + let l:ui = g:vim_ai_chat['ui'] execute "py3file " . s:chat_py set nopaste endfunction @@ -2,8 +2,8 @@ plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") -config_options = vim.eval("options") -config_ui = vim.eval("ui") +config_options = vim.eval("l:options") +config_ui = vim.eval("l:ui") def initialize_chat_window(): lines = vim.eval('getline(1, "$")') diff --git a/py/complete.py b/py/complete.py index 29eb760..669ef98 100644 --- a/py/complete.py +++ b/py/complete.py @@ -2,11 +2,11 @@ plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") -engine = vim.eval("engine") -config_options = vim.eval("options") +engine = vim.eval("l:engine") +config_options = vim.eval("l:options") request_options = make_request_options(config_options) -prompt = vim.eval("prompt").strip() +prompt = vim.eval("l:prompt").strip() def complete_engine(prompt): request = { |