diff --git a/.travis.yml b/.travis.yml index 4acafd6..48023f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,25 @@ sudo: false language: python +env: + matrix: + - ENV=test + - ENV=check +matrix: + allow_failures: + # Needs to be fixed! + - env: ENV=test install: - - pip install pytest + - | + if [ "$ENV" = "check" ]; then + pip install vim-vint + else + pip install pytest + fi script: - - vim --version - - py.test + - vim --version + - | + if [ "$ENV" = "check" ]; then + vint after autoload ftplugin plugin + else + pytest + fi diff --git a/after/ftplugin/python/jedi.vim b/after/ftplugin/python/jedi.vim index 591f100..2798207 100644 --- a/after/ftplugin/python/jedi.vim +++ b/after/ftplugin/python/jedi.vim @@ -9,15 +9,15 @@ if g:jedi#auto_initialization setlocal omnifunc=jedi#completions " map ctrl+space for autocompletion - if g:jedi#completions_command == "" + if g:jedi#completions_command ==# '' " In terminals, sometimes equals . imap smap endif - if g:jedi#completions_command != "" - execute "inoremap ".g:jedi#completions_command." jedi#complete_string(0)" + if len(g:jedi#completions_command) + execute 'inoremap '.g:jedi#completions_command.' jedi#complete_string(0)' " A separate mapping for select mode: deletes and completes. - execute "snoremap ".g:jedi#completions_command." '\c'.jedi#complete_string(0)" + execute 'snoremap '.g:jedi#completions_command." '\c'.jedi#complete_string(0)" endif endif endif diff --git a/autoload/jedi.vim b/autoload/jedi.vim index e4c02b9..a0fe5db 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -57,13 +57,13 @@ endfor " ------------------------------------------------------------------------ let s:script_path = fnameescape(expand(':p:h:h')) -function! s:init_python() - if g:jedi#force_py_version != 'auto' +function! s:init_python() abort + if g:jedi#force_py_version !=# 'auto' " Always use the user supplied version. try return jedi#force_py_version(g:jedi#force_py_version) catch - throw "Could not setup g:jedi#force_py_version: ".v:exception + throw 'Could not setup g:jedi#force_py_version: '.v:exception endtry endif @@ -75,15 +75,15 @@ function! s:init_python() " Get default python version from interpreter in $PATH. let s:def_py = system('python -c '.shellescape('import sys; sys.stdout.write(str(sys.version_info[0]))')) if v:shell_error != 0 || !len(s:def_py) - if !exists("g:jedi#squelch_py_warning") + if !exists('g:jedi#squelch_py_warning') echohl WarningMsg - echom "Warning: jedi-vim failed to get Python version from sys.version_info: " . s:def_py - echom "Falling back to version 2." + echom 'Warning: jedi-vim failed to get Python version from sys.version_info: ' . s:def_py + echom 'Falling back to version 2.' echohl None endif let s:def_py = 2 elseif &verbose - echom "jedi-vim: auto-detected Python: ".s:def_py + echom 'jedi-vim: auto-detected Python: '.s:def_py endif " Make sure that the auto-detected version is available in Vim. @@ -95,11 +95,11 @@ function! s:init_python() " usually because of a missing neovim module in a VIRTUAL_ENV. if has('nvim') echohl WarningMsg - echom "jedi-vim: the detected Python version (".s:def_py.")" - \ "is not functional." - \ "Is the 'neovim' module installed?" - \ "While jedi-vim will work, it might not use the" - \ "expected Python path." + echom 'jedi-vim: the detected Python version ('.s:def_py.')' + \ 'is not functional.' + \ 'Is the "neovim" module installed?' + \ 'While jedi-vim will work, it might not use the' + \ 'expected Python path.' echohl None endif endif @@ -109,28 +109,28 @@ function! s:init_python() elseif has('python3') call jedi#setup_py_version(3) else - throw "jedi-vim requires Vim with support for Python 2 or 3." + throw 'jedi-vim requires Vim with support for Python 2 or 3.' endif return 1 endfunction -function! jedi#reinit_python() +function! jedi#reinit_python() abort unlet! s:_init_python call jedi#init_python() endfunction let s:_init_python = -1 -function! jedi#init_python() +function! jedi#init_python() abort if s:_init_python == -1 try let s:_init_python = s:init_python() catch let s:_init_python = 0 - if !exists("g:jedi#squelch_py_warning") - echoerr "Error: jedi-vim failed to initialize Python: " - \ .v:exception." (in ".v:throwpoint.")" + if !exists('g:jedi#squelch_py_warning') + echoerr 'Error: jedi-vim failed to initialize Python: ' + \ .v:exception.' (in '.v:throwpoint.')' endif endtry endif @@ -139,7 +139,7 @@ endfunction let s:python_version = 'null' -function! jedi#setup_py_version(py_version) +function! jedi#setup_py_version(py_version) abort if a:py_version == 2 let cmd_init = 'pyfile' let cmd_exec = 'python' @@ -149,20 +149,20 @@ function! jedi#setup_py_version(py_version) let cmd_exec = 'python3' let s:python_version = 3 else - throw "jedi#setup_py_version: invalid py_version: ".a:py_version + throw 'jedi#setup_py_version: invalid py_version: '.a:py_version endif try execute cmd_init.' '.s:script_path.'/initialize.py' catch - throw "jedi#setup_py_version: ".v:exception + throw 'jedi#setup_py_version: '.v:exception endtry execute 'command! -nargs=1 PythonJedi '.cmd_exec.' ' return 1 endfunction -function! jedi#debug_info() +function! jedi#debug_info() abort if s:python_version ==# 'null' call s:init_python() endif @@ -195,34 +195,36 @@ function! jedi#debug_info() for [k, V] in items(filter(copy(g:), "v:key =~# '\\v^jedi#'")) let k = substitute(k, '\v^jedi#', '', '') exe 'let default = '.get(s:default_settings, k, "'-'") + " vint: -ProhibitUsingUndeclaredVariable if default !=# V echo printf('g:%s = %s (default: %s)', k, string(V), string(default)) unlet! V " Fix variable type mismatch with Vim 7.3. endif + " vint: +ProhibitUsingUndeclaredVariable endfor echo '```' endfunction -function! jedi#force_py_version(py_version) +function! jedi#force_py_version(py_version) abort let g:jedi#force_py_version = a:py_version return jedi#setup_py_version(a:py_version) endfunction -function! jedi#force_py_version_switch() +function! jedi#force_py_version_switch() abort if g:jedi#force_py_version == 2 call jedi#force_py_version(3) elseif g:jedi#force_py_version == 3 call jedi#force_py_version(2) else - throw "Don't know how to switch from ".g:jedi#force_py_version."!" + throw "Don't know how to switch from ".g:jedi#force_py_version.'!' endif endfunction " Helper function instead of `python vim.eval()`, and `.command()` because " these also return error definitions. -function! jedi#_vim_exceptions(str, is_eval) +function! jedi#_vim_exceptions(str, is_eval) abort let l:result = {} try if a:is_eval @@ -243,55 +245,55 @@ call jedi#init_python() " Might throw an error. " ------------------------------------------------------------------------ " functions that call python code " ------------------------------------------------------------------------ -function! jedi#goto() +function! jedi#goto() abort PythonJedi jedi_vim.goto(mode="goto") endfunction -function! jedi#goto_assignments() +function! jedi#goto_assignments() abort PythonJedi jedi_vim.goto(mode="assignment") endfunction -function! jedi#goto_definitions() +function! jedi#goto_definitions() abort PythonJedi jedi_vim.goto(mode="definition") endfunction -function! jedi#usages() +function! jedi#usages() abort PythonJedi jedi_vim.goto(mode="related_name") endfunction -function! jedi#rename(...) +function! jedi#rename(...) abort PythonJedi jedi_vim.rename() endfunction -function! jedi#rename_visual(...) +function! jedi#rename_visual(...) abort PythonJedi jedi_vim.rename_visual() endfunction -function! jedi#completions(findstart, base) +function! jedi#completions(findstart, base) abort PythonJedi jedi_vim.completions() endfunction -function! jedi#enable_speed_debugging() +function! jedi#enable_speed_debugging() abort PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) endfunction -function! jedi#enable_debugging() +function! jedi#enable_debugging() abort PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) endfunction -function! jedi#disable_debugging() +function! jedi#disable_debugging() abort PythonJedi jedi_vim.jedi.set_debug_function(None) endfunction -function! jedi#py_import(args) +function! jedi#py_import(args) abort PythonJedi jedi_vim.py_import() endfun -function! jedi#py_import_completions(argl, cmdl, pos) +function! jedi#py_import_completions(argl, cmdl, pos) abort PythonJedi jedi_vim.py_import_completions() endfun -function! jedi#clear_cache(bang) +function! jedi#clear_cache(bang) abort PythonJedi jedi_vim.jedi.cache.clear_time_caches(True) if a:bang PythonJedi jedi_vim.jedi.parser.utils.ParserPickling.clear_cache() @@ -302,17 +304,17 @@ endfunction " ------------------------------------------------------------------------ " show_documentation " ------------------------------------------------------------------------ -function! jedi#show_documentation() +function! jedi#show_documentation() abort PythonJedi if jedi_vim.show_documentation() is None: vim.command('return') - let bn = bufnr("__doc__") + let bn = bufnr('__doc__') if bn > 0 let wi=index(tabpagebuflist(tabpagenr()), bn) if wi >= 0 " If the __doc__ buffer is open in the current tab, jump to it silent execute (wi+1).'wincmd w' else - silent execute "sbuffer ".bn + silent execute 'sbuffer '.bn endif else split '__doc__' @@ -331,11 +333,11 @@ function! jedi#show_documentation() if l:doc_lines > g:jedi#max_doc_height " max lines for plugin let l:doc_lines = g:jedi#max_doc_height endif - execute "resize ".l:doc_lines + execute 'resize '.l:doc_lines " quit comands nnoremap q ZQ - execute "nnoremap ".g:jedi#documentation_command." ZQ" + execute 'nnoremap '.g:jedi#documentation_command.' ZQ' " highlight python code within rst unlet! b:current_syntax @@ -344,14 +346,14 @@ function! jedi#show_documentation() syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript " >>> python code -> (doctests) syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript - let b:current_syntax = "rst" + let b:current_syntax = 'rst' endfunction " ------------------------------------------------------------------------ " helper functions " ------------------------------------------------------------------------ -function! jedi#add_goto_window(len) +function! jedi#add_goto_window(len) abort set lazyredraw cclose let height = min([a:len, g:jedi#quickfix_window_height]) @@ -360,37 +362,40 @@ function! jedi#add_goto_window(len) if g:jedi#use_tabs_not_buffers == 1 noremap :call jedi#goto_window_on_enter() endif - au WinLeave q " automatically leave, if an option is chosen + augroup jedi_goto_window + au! + au WinLeave q " automatically leave, if an option is chosen + augroup END redraw! endfunction -function! jedi#goto_window_on_enter() +function! jedi#goto_window_on_enter() abort let l:list = getqflist() let l:data = l:list[line('.') - 1] if l:data.bufnr " close goto_window buffer - normal ZQ + normal! ZQ PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)')) call cursor(l:data.lnum, l:data.col) else - echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None + echohl WarningMsg | echo 'Builtin module cannot be opened.' | echohl None endif endfunction -function! s:syn_stack() - if !exists("*synstack") +function! s:syn_stack() abort + if !exists('*synstack') return [] endif - return map(synstack(line('.'), col('.') - 1), 'synIDattr(v:val, "name")') + return map(synstack(line('.'), col('.') - 1), "synIDattr(v:val, 'name')") endfunc -function! jedi#do_popup_on_dot_in_highlight() +function! jedi#do_popup_on_dot_in_highlight() abort let highlight_groups = s:syn_stack() for a in highlight_groups - if a == 'pythonDoctest' + if a ==# 'pythonDoctest' return 1 endif endfor @@ -407,7 +412,7 @@ endfunc let s:show_call_signatures_last = [0, 0, ''] -function! jedi#show_call_signatures() +function! jedi#show_call_signatures() abort if s:_init_python == 0 return 1 endif @@ -437,7 +442,7 @@ function! jedi#show_call_signatures() endfunction -function! jedi#clear_call_signatures() +function! jedi#clear_call_signatures() abort if s:_init_python == 0 return 1 endif @@ -447,7 +452,7 @@ function! jedi#clear_call_signatures() endfunction -function! jedi#configure_call_signatures() +function! jedi#configure_call_signatures() abort augroup jedi_call_signatures autocmd! * if g:jedi#show_call_signatures == 2 " Command line call signatures @@ -472,7 +477,7 @@ endfunction " Determine where the current window is on the screen for displaying call " signatures in the correct column. -function! s:save_first_col() +function! s:save_first_col() abort if bufname('%') ==# '[Command Line]' || winnr('$') == 1 return 0 endif @@ -514,11 +519,9 @@ function! s:save_first_col() endfunction -function! jedi#complete_string(is_popup_on_dot) - +function! jedi#complete_string(is_popup_on_dot) abort if a:is_popup_on_dot && !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight()) return '' - endif if pumvisible() && !a:is_popup_on_dot return "\" @@ -528,7 +531,7 @@ function! jedi#complete_string(is_popup_on_dot) endfunction -function! jedi#complete_opened(is_popup_on_dot) +function! jedi#complete_opened(is_popup_on_dot) abort if pumvisible() " Only go down if it is visible, user-enabled and the longest " option is set. @@ -536,17 +539,17 @@ function! jedi#complete_opened(is_popup_on_dot) return "\" endif if a:is_popup_on_dot - if &completeopt !~ '\(noinsert\|noselect\)' + if &completeopt !~# '\(noinsert\|noselect\)' " Prevent completion of the first entry with dot completion. return "\" endif endif endif - return "" + return endfunction -function! jedi#smart_auto_mappings() +function! jedi#smart_auto_mappings() abort " Auto put import statement after from module.name and complete if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.')) " Enter character and start completion. diff --git a/ftplugin/python/jedi.vim b/ftplugin/python/jedi.vim index 18caa48..158ea1f 100644 --- a/ftplugin/python/jedi.vim +++ b/ftplugin/python/jedi.vim @@ -7,26 +7,26 @@ endif if g:jedi#auto_initialization " goto / get_definition / usages - if g:jedi#goto_command != '' - execute "nnoremap ".g:jedi#goto_command." :call jedi#goto()" + if len(g:jedi#goto_command) + execute 'nnoremap '.g:jedi#goto_command.' :call jedi#goto()' endif - if g:jedi#goto_assignments_command != '' - execute "nnoremap ".g:jedi#goto_assignments_command." :call jedi#goto_assignments()" + if len(g:jedi#goto_assignments_command) + execute 'nnoremap '.g:jedi#goto_assignments_command.' :call jedi#goto_assignments()' endif - if g:jedi#goto_definitions_command != '' - execute "nnoremap ".g:jedi#goto_definitions_command." :call jedi#goto_definitions()" + if len(g:jedi#goto_definitions_command) + execute 'nnoremap '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()' endif - if g:jedi#usages_command != '' - execute "nnoremap ".g:jedi#usages_command." :call jedi#usages()" + if len(g:jedi#usages_command) + execute 'nnoremap '.g:jedi#usages_command.' :call jedi#usages()' endif " rename - if g:jedi#rename_command != '' - execute "nnoremap ".g:jedi#rename_command." :call jedi#rename()" - execute "vnoremap ".g:jedi#rename_command." :call jedi#rename_visual()" + if len(g:jedi#rename_command) + execute 'nnoremap '.g:jedi#rename_command.' :call jedi#rename()' + execute 'vnoremap '.g:jedi#rename_command.' :call jedi#rename_visual()' endif " documentation/pydoc - if g:jedi#documentation_command != '' - execute "nnoremap ".g:jedi#documentation_command." :call jedi#show_documentation()" + if len(g:jedi#documentation_command) + execute 'nnoremap '.g:jedi#documentation_command.' :call jedi#show_documentation()' endif if g:jedi#show_call_signatures > 0 && has('conceal') diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 1dae363..269af1f 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -4,10 +4,12 @@ " This part of the software is just the vim interface. The really big deal is " the Jedi Python library. -if !exists("g:jedi#auto_vim_configuration") || g:jedi#auto_vim_configuration +if get(g:, 'jedi#auto_vim_configuration', 0) " jedi-vim doesn't work in compatible mode (vim script syntax problems) if &compatible + " vint: -ProhibitSetNoCompatible set nocompatible + " vint: +ProhibitSetNoCompatible endif " jedi-vim really needs, otherwise jedi-vim cannot start.