Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion autoload/ollama/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ let s:buf = -1
" avoid starting a 2nd edit job while one is in progress
let g:edit_in_progress = 0

if !exists('g:ollama_embedded_python') || g:ollama_embedded_python == 0
Comment thread
scarbajali marked this conversation as resolved.
Outdated
function! ollama#edit#EditCodeDone(status) abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#DialogCallback(id, result) abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#UpdateProgress(popup) abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#EditCode(request) abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#EditPrompt() abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#AcceptAll() abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
function! ollama#edit#RejectAll() abort
echoerr "OllamaEdit features require Vim compiled with +python3 support."
endfunction
finish
endif

" Define the VimScript callback function
" This will be called from python when to operations is 'done'
" or aborted with 'error'
Expand Down Expand Up @@ -212,4 +237,3 @@ finally:
pass
EOF
endfunction

34 changes: 20 additions & 14 deletions autoload/ollama/setup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ function! ollama#setup#EnsureVenv() abort
endfunction

" Loads the plugin's python modules

if g:ollama_embedded_python
Comment thread
scarbajali marked this conversation as resolved.
Outdated
function! s:LoadPluginPyModules() abort
python3 << EOF
import os
Expand All @@ -391,17 +393,19 @@ if plugin_python_path not in sys.path:
sys.path.append(plugin_python_path)

try:
# Import your CodeEditor module
# Import plugin modules
import CodeEditor
import VimHelper
except ImportError as e:
print(f'Error importing CodeEditor module:\n{e}')
EOF
endfunction
endif

" Initializes venv for python.
" This must be done before loading the plugin's py modules,
" to ensure the plugin's python requirements are available.
if g:ollama_embedded_python
function! s:SetupPyVEnv() abort
python3 << EOF
import os
Expand All @@ -412,25 +416,23 @@ use_venv = vim.eval('g:ollama_use_venv') or 0

# Should we use a venv?
if use_venv:
# Create default venv path
venv_path = os.path.join(os.environ['HOME'], '.vim', 'venv', 'ollama')
# Check if the venv path exists
if os.path.exists(venv_path):
#print('Found venv:', venv_path)

venv_bin = os.path.join(venv_path, 'bin', 'python3')
venv_site_packages = os.path.join(venv_path, 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages')

# Ensure the virtual environment's site-packages is in sys.path
venv_site_packages = os.path.join(
venv_path,
'lib', f'python{sys.version_info.major}.{sys.version_info.minor}',
'site-packages'
)
Comment on lines +427 to +431
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor

If you are switching to vertical formatting, maybe format all the argument vertically:

Suggested change
venv_site_packages = os.path.join(
venv_path,
'lib', f'python{sys.version_info.major}.{sys.version_info.minor}',
'site-packages'
)
venv_site_packages = os.path.join(
venv_path,
'lib',
f'python{sys.version_info.major}.{sys.version_info.minor}',
'site-packages'
)

if venv_site_packages not in sys.path:
#print(f'Adding venv site-packages to path: {venv_site_packages}')
sys.path.insert(0, venv_site_packages)
else:
print('Venv not found: '. venv_path)
print('Venv not found: ' + venv_path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor

This has been fixed already.
It seems that this project uses merges for PRs, so maybe it does not matter much.
But if you rebase this minor fix should disappear.

else:
print('Venv disabled')
EOF
endfunction
endif

function! ollama#setup#Init() abort
let l:ollama_config = expand('$HOME/.vim/config/ollama.vim')
Expand All @@ -453,21 +455,25 @@ function! ollama#setup#Init() abort
endif
echon "\n"

if g:ollama_use_venv
if g:ollama_use_venv && g:ollama_embedded_python
Comment thread
scarbajali marked this conversation as resolved.
Outdated
" Ensure venv and dependencies are set up
call ollama#setup#EnsureVenv()
call s:SetupPyVEnv()
endif
call ollama#setup#Setup()
call s:LoadPluginPyModules()
if g:ollama_embedded_python
call s:LoadPluginPyModules()
endif
else
" load the config file
execute 'source' l:ollama_config
if g:ollama_use_venv
if g:ollama_use_venv && g:ollama_embedded_python
Comment thread
scarbajali marked this conversation as resolved.
Outdated
" Ensure venv and dependencies are set up
call ollama#setup#EnsureVenv()
call s:SetupPyVEnv()
endif
call s:LoadPluginPyModules()
if g:ollama_embedded_python
call s:LoadPluginPyModules()
endif
endif
endfunction
9 changes: 4 additions & 5 deletions plugin/ollama.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ if has('nvim')
endif

if has('python3') || has('python3_dynamic')
" Use system's python3 by default (can be changed by venv)
let g:ollama_python_interpreter = 'python3'
let g:ollama_embedded_python = 1
else
let g:ollama_enabled = 0
echom "warning: your Vim version does not support python3. Vim-ollama is disabled."
finish
let g:ollama_embedded_python = 0
endif
" Use system's python3 by default (can be changed by venv)
let g:ollama_python_interpreter = 'python3'

" Default settings
if !exists('g:ollama_enabled')
Expand Down