Style fixes (via vint) (#662)

This also adds a augroup for `jedi#add_goto_window`.
This commit is contained in:
Daniel Hahler
2017-01-29 11:55:55 +01:00
committed by Dave Halter
parent f100ffad4d
commit eba90e615d
5 changed files with 110 additions and 87 deletions

View File

@@ -1,7 +1,25 @@
sudo: false sudo: false
language: python language: python
env:
matrix:
- ENV=test
- ENV=check
matrix:
allow_failures:
# Needs to be fixed!
- env: ENV=test
install: install:
- pip install pytest - |
if [ "$ENV" = "check" ]; then
pip install vim-vint
else
pip install pytest
fi
script: script:
- vim --version - vim --version
- py.test - |
if [ "$ENV" = "check" ]; then
vint after autoload ftplugin plugin
else
pytest
fi

View File

@@ -9,15 +9,15 @@ if g:jedi#auto_initialization
setlocal omnifunc=jedi#completions setlocal omnifunc=jedi#completions
" map ctrl+space for autocompletion " map ctrl+space for autocompletion
if g:jedi#completions_command == "<C-Space>" if g:jedi#completions_command ==# '<C-Space>'
" In terminals, <C-Space> sometimes equals <Nul>. " In terminals, <C-Space> sometimes equals <Nul>.
imap <buffer> <Nul> <C-Space> imap <buffer> <Nul> <C-Space>
smap <buffer> <Nul> <C-Space> smap <buffer> <Nul> <C-Space>
endif endif
if g:jedi#completions_command != "" if len(g:jedi#completions_command)
execute "inoremap <expr> <buffer> ".g:jedi#completions_command." jedi#complete_string(0)" execute 'inoremap <expr> <buffer> '.g:jedi#completions_command.' jedi#complete_string(0)'
" A separate mapping for select mode: deletes and completes. " A separate mapping for select mode: deletes and completes.
execute "snoremap <expr> <buffer> ".g:jedi#completions_command." '\<C-g>c'.jedi#complete_string(0)" execute 'snoremap <expr> <buffer> '.g:jedi#completions_command." '\<C-g>c'.jedi#complete_string(0)"
endif endif
endif endif
endif endif

View File

@@ -57,13 +57,13 @@ endfor
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
let s:script_path = fnameescape(expand('<sfile>:p:h:h')) let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
function! s:init_python() function! s:init_python() abort
if g:jedi#force_py_version != 'auto' if g:jedi#force_py_version !=# 'auto'
" Always use the user supplied version. " Always use the user supplied version.
try try
return jedi#force_py_version(g:jedi#force_py_version) return jedi#force_py_version(g:jedi#force_py_version)
catch catch
throw "Could not setup g:jedi#force_py_version: ".v:exception throw 'Could not setup g:jedi#force_py_version: '.v:exception
endtry endtry
endif endif
@@ -75,15 +75,15 @@ function! s:init_python()
" Get default python version from interpreter in $PATH. " 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]))')) 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 v:shell_error != 0 || !len(s:def_py)
if !exists("g:jedi#squelch_py_warning") if !exists('g:jedi#squelch_py_warning')
echohl WarningMsg echohl WarningMsg
echom "Warning: jedi-vim failed to get Python version from sys.version_info: " . s:def_py echom 'Warning: jedi-vim failed to get Python version from sys.version_info: ' . s:def_py
echom "Falling back to version 2." echom 'Falling back to version 2.'
echohl None echohl None
endif endif
let s:def_py = 2 let s:def_py = 2
elseif &verbose elseif &verbose
echom "jedi-vim: auto-detected Python: ".s:def_py echom 'jedi-vim: auto-detected Python: '.s:def_py
endif endif
" Make sure that the auto-detected version is available in Vim. " 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. " usually because of a missing neovim module in a VIRTUAL_ENV.
if has('nvim') if has('nvim')
echohl WarningMsg echohl WarningMsg
echom "jedi-vim: the detected Python version (".s:def_py.")" echom 'jedi-vim: the detected Python version ('.s:def_py.')'
\ "is not functional." \ 'is not functional.'
\ "Is the 'neovim' module installed?" \ 'Is the "neovim" module installed?'
\ "While jedi-vim will work, it might not use the" \ 'While jedi-vim will work, it might not use the'
\ "expected Python path." \ 'expected Python path.'
echohl None echohl None
endif endif
endif endif
@@ -109,28 +109,28 @@ function! s:init_python()
elseif has('python3') elseif has('python3')
call jedi#setup_py_version(3) call jedi#setup_py_version(3)
else 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 endif
return 1 return 1
endfunction endfunction
function! jedi#reinit_python() function! jedi#reinit_python() abort
unlet! s:_init_python unlet! s:_init_python
call jedi#init_python() call jedi#init_python()
endfunction endfunction
let s:_init_python = -1 let s:_init_python = -1
function! jedi#init_python() function! jedi#init_python() abort
if s:_init_python == -1 if s:_init_python == -1
try try
let s:_init_python = s:init_python() let s:_init_python = s:init_python()
catch catch
let s:_init_python = 0 let s:_init_python = 0
if !exists("g:jedi#squelch_py_warning") if !exists('g:jedi#squelch_py_warning')
echoerr "Error: jedi-vim failed to initialize Python: " echoerr 'Error: jedi-vim failed to initialize Python: '
\ .v:exception." (in ".v:throwpoint.")" \ .v:exception.' (in '.v:throwpoint.')'
endif endif
endtry endtry
endif endif
@@ -139,7 +139,7 @@ endfunction
let s:python_version = 'null' 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 if a:py_version == 2
let cmd_init = 'pyfile' let cmd_init = 'pyfile'
let cmd_exec = 'python' let cmd_exec = 'python'
@@ -149,20 +149,20 @@ function! jedi#setup_py_version(py_version)
let cmd_exec = 'python3' let cmd_exec = 'python3'
let s:python_version = 3 let s:python_version = 3
else else
throw "jedi#setup_py_version: invalid py_version: ".a:py_version throw 'jedi#setup_py_version: invalid py_version: '.a:py_version
endif endif
try try
execute cmd_init.' '.s:script_path.'/initialize.py' execute cmd_init.' '.s:script_path.'/initialize.py'
catch catch
throw "jedi#setup_py_version: ".v:exception throw 'jedi#setup_py_version: '.v:exception
endtry endtry
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>' execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
return 1 return 1
endfunction endfunction
function! jedi#debug_info() function! jedi#debug_info() abort
if s:python_version ==# 'null' if s:python_version ==# 'null'
call s:init_python() call s:init_python()
endif endif
@@ -195,34 +195,36 @@ function! jedi#debug_info()
for [k, V] in items(filter(copy(g:), "v:key =~# '\\v^jedi#'")) for [k, V] in items(filter(copy(g:), "v:key =~# '\\v^jedi#'"))
let k = substitute(k, '\v^jedi#', '', '') let k = substitute(k, '\v^jedi#', '', '')
exe 'let default = '.get(s:default_settings, k, "'-'") exe 'let default = '.get(s:default_settings, k, "'-'")
" vint: -ProhibitUsingUndeclaredVariable
if default !=# V if default !=# V
echo printf('g:%s = %s (default: %s)', k, string(V), string(default)) echo printf('g:%s = %s (default: %s)', k, string(V), string(default))
unlet! V " Fix variable type mismatch with Vim 7.3. unlet! V " Fix variable type mismatch with Vim 7.3.
endif endif
" vint: +ProhibitUsingUndeclaredVariable
endfor endfor
echo '```' echo '```'
endfunction 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 let g:jedi#force_py_version = a:py_version
return jedi#setup_py_version(a:py_version) return jedi#setup_py_version(a:py_version)
endfunction endfunction
function! jedi#force_py_version_switch() function! jedi#force_py_version_switch() abort
if g:jedi#force_py_version == 2 if g:jedi#force_py_version == 2
call jedi#force_py_version(3) call jedi#force_py_version(3)
elseif g:jedi#force_py_version == 3 elseif g:jedi#force_py_version == 3
call jedi#force_py_version(2) call jedi#force_py_version(2)
else 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 endif
endfunction endfunction
" Helper function instead of `python vim.eval()`, and `.command()` because " Helper function instead of `python vim.eval()`, and `.command()` because
" these also return error definitions. " these also return error definitions.
function! jedi#_vim_exceptions(str, is_eval) function! jedi#_vim_exceptions(str, is_eval) abort
let l:result = {} let l:result = {}
try try
if a:is_eval if a:is_eval
@@ -243,55 +245,55 @@ call jedi#init_python() " Might throw an error.
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
" functions that call python code " functions that call python code
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
function! jedi#goto() function! jedi#goto() abort
PythonJedi jedi_vim.goto(mode="goto") PythonJedi jedi_vim.goto(mode="goto")
endfunction endfunction
function! jedi#goto_assignments() function! jedi#goto_assignments() abort
PythonJedi jedi_vim.goto(mode="assignment") PythonJedi jedi_vim.goto(mode="assignment")
endfunction endfunction
function! jedi#goto_definitions() function! jedi#goto_definitions() abort
PythonJedi jedi_vim.goto(mode="definition") PythonJedi jedi_vim.goto(mode="definition")
endfunction endfunction
function! jedi#usages() function! jedi#usages() abort
PythonJedi jedi_vim.goto(mode="related_name") PythonJedi jedi_vim.goto(mode="related_name")
endfunction endfunction
function! jedi#rename(...) function! jedi#rename(...) abort
PythonJedi jedi_vim.rename() PythonJedi jedi_vim.rename()
endfunction endfunction
function! jedi#rename_visual(...) function! jedi#rename_visual(...) abort
PythonJedi jedi_vim.rename_visual() PythonJedi jedi_vim.rename_visual()
endfunction endfunction
function! jedi#completions(findstart, base) function! jedi#completions(findstart, base) abort
PythonJedi jedi_vim.completions() PythonJedi jedi_vim.completions()
endfunction 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) PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
endfunction endfunction
function! jedi#enable_debugging() function! jedi#enable_debugging() abort
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
endfunction endfunction
function! jedi#disable_debugging() function! jedi#disable_debugging() abort
PythonJedi jedi_vim.jedi.set_debug_function(None) PythonJedi jedi_vim.jedi.set_debug_function(None)
endfunction endfunction
function! jedi#py_import(args) function! jedi#py_import(args) abort
PythonJedi jedi_vim.py_import() PythonJedi jedi_vim.py_import()
endfun endfun
function! jedi#py_import_completions(argl, cmdl, pos) function! jedi#py_import_completions(argl, cmdl, pos) abort
PythonJedi jedi_vim.py_import_completions() PythonJedi jedi_vim.py_import_completions()
endfun endfun
function! jedi#clear_cache(bang) function! jedi#clear_cache(bang) abort
PythonJedi jedi_vim.jedi.cache.clear_time_caches(True) PythonJedi jedi_vim.jedi.cache.clear_time_caches(True)
if a:bang if a:bang
PythonJedi jedi_vim.jedi.parser.utils.ParserPickling.clear_cache() PythonJedi jedi_vim.jedi.parser.utils.ParserPickling.clear_cache()
@@ -302,17 +304,17 @@ endfunction
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
" show_documentation " show_documentation
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
function! jedi#show_documentation() function! jedi#show_documentation() abort
PythonJedi if jedi_vim.show_documentation() is None: vim.command('return') PythonJedi if jedi_vim.show_documentation() is None: vim.command('return')
let bn = bufnr("__doc__") let bn = bufnr('__doc__')
if bn > 0 if bn > 0
let wi=index(tabpagebuflist(tabpagenr()), bn) let wi=index(tabpagebuflist(tabpagenr()), bn)
if wi >= 0 if wi >= 0
" If the __doc__ buffer is open in the current tab, jump to it " If the __doc__ buffer is open in the current tab, jump to it
silent execute (wi+1).'wincmd w' silent execute (wi+1).'wincmd w'
else else
silent execute "sbuffer ".bn silent execute 'sbuffer '.bn
endif endif
else else
split '__doc__' split '__doc__'
@@ -331,11 +333,11 @@ function! jedi#show_documentation()
if l:doc_lines > g:jedi#max_doc_height " max lines for plugin if l:doc_lines > g:jedi#max_doc_height " max lines for plugin
let l:doc_lines = g:jedi#max_doc_height let l:doc_lines = g:jedi#max_doc_height
endif endif
execute "resize ".l:doc_lines execute 'resize '.l:doc_lines
" quit comands " quit comands
nnoremap <buffer> q ZQ nnoremap <buffer> q ZQ
execute "nnoremap <buffer> ".g:jedi#documentation_command." ZQ" execute 'nnoremap <buffer> '.g:jedi#documentation_command.' ZQ'
" highlight python code within rst " highlight python code within rst
unlet! b:current_syntax unlet! b:current_syntax
@@ -344,14 +346,14 @@ function! jedi#show_documentation()
syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript
" >>> python code -> (doctests) " >>> python code -> (doctests)
syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript
let b:current_syntax = "rst" let b:current_syntax = 'rst'
endfunction endfunction
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
" helper functions " helper functions
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
function! jedi#add_goto_window(len) function! jedi#add_goto_window(len) abort
set lazyredraw set lazyredraw
cclose cclose
let height = min([a:len, g:jedi#quickfix_window_height]) 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 if g:jedi#use_tabs_not_buffers == 1
noremap <buffer> <CR> :call jedi#goto_window_on_enter()<CR> noremap <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
endif endif
au WinLeave <buffer> q " automatically leave, if an option is chosen augroup jedi_goto_window
au!
au WinLeave <buffer> q " automatically leave, if an option is chosen
augroup END
redraw! redraw!
endfunction endfunction
function! jedi#goto_window_on_enter() function! jedi#goto_window_on_enter() abort
let l:list = getqflist() let l:list = getqflist()
let l:data = l:list[line('.') - 1] let l:data = l:list[line('.') - 1]
if l:data.bufnr if l:data.bufnr
" close goto_window buffer " close goto_window buffer
normal ZQ normal! ZQ
PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)')) PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
call cursor(l:data.lnum, l:data.col) call cursor(l:data.lnum, l:data.col)
else else
echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None echohl WarningMsg | echo 'Builtin module cannot be opened.' | echohl None
endif endif
endfunction endfunction
function! s:syn_stack() function! s:syn_stack() abort
if !exists("*synstack") if !exists('*synstack')
return [] return []
endif endif
return map(synstack(line('.'), col('.') - 1), 'synIDattr(v:val, "name")') return map(synstack(line('.'), col('.') - 1), "synIDattr(v:val, 'name')")
endfunc endfunc
function! jedi#do_popup_on_dot_in_highlight() function! jedi#do_popup_on_dot_in_highlight() abort
let highlight_groups = s:syn_stack() let highlight_groups = s:syn_stack()
for a in highlight_groups for a in highlight_groups
if a == 'pythonDoctest' if a ==# 'pythonDoctest'
return 1 return 1
endif endif
endfor endfor
@@ -407,7 +412,7 @@ endfunc
let s:show_call_signatures_last = [0, 0, ''] let s:show_call_signatures_last = [0, 0, '']
function! jedi#show_call_signatures() function! jedi#show_call_signatures() abort
if s:_init_python == 0 if s:_init_python == 0
return 1 return 1
endif endif
@@ -437,7 +442,7 @@ function! jedi#show_call_signatures()
endfunction endfunction
function! jedi#clear_call_signatures() function! jedi#clear_call_signatures() abort
if s:_init_python == 0 if s:_init_python == 0
return 1 return 1
endif endif
@@ -447,7 +452,7 @@ function! jedi#clear_call_signatures()
endfunction endfunction
function! jedi#configure_call_signatures() function! jedi#configure_call_signatures() abort
augroup jedi_call_signatures augroup jedi_call_signatures
autocmd! * <buffer> autocmd! * <buffer>
if g:jedi#show_call_signatures == 2 " Command line call signatures 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 " Determine where the current window is on the screen for displaying call
" signatures in the correct column. " signatures in the correct column.
function! s:save_first_col() function! s:save_first_col() abort
if bufname('%') ==# '[Command Line]' || winnr('$') == 1 if bufname('%') ==# '[Command Line]' || winnr('$') == 1
return 0 return 0
endif endif
@@ -514,11 +519,9 @@ function! s:save_first_col()
endfunction 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()) if a:is_popup_on_dot && !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
return '' return ''
endif endif
if pumvisible() && !a:is_popup_on_dot if pumvisible() && !a:is_popup_on_dot
return "\<C-n>" return "\<C-n>"
@@ -528,7 +531,7 @@ function! jedi#complete_string(is_popup_on_dot)
endfunction endfunction
function! jedi#complete_opened(is_popup_on_dot) function! jedi#complete_opened(is_popup_on_dot) abort
if pumvisible() if pumvisible()
" Only go down if it is visible, user-enabled and the longest " Only go down if it is visible, user-enabled and the longest
" option is set. " option is set.
@@ -536,17 +539,17 @@ function! jedi#complete_opened(is_popup_on_dot)
return "\<Down>" return "\<Down>"
endif endif
if a:is_popup_on_dot if a:is_popup_on_dot
if &completeopt !~ '\(noinsert\|noselect\)' if &completeopt !~# '\(noinsert\|noselect\)'
" Prevent completion of the first entry with dot completion. " Prevent completion of the first entry with dot completion.
return "\<C-p>" return "\<C-p>"
endif endif
endif endif
endif endif
return "" return
endfunction endfunction
function! jedi#smart_auto_mappings() function! jedi#smart_auto_mappings() abort
" Auto put import statement after from module.name<space> and complete " Auto put import statement after from module.name<space> and complete
if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.')) if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
" Enter character and start completion. " Enter character and start completion.

View File

@@ -7,26 +7,26 @@ endif
if g:jedi#auto_initialization if g:jedi#auto_initialization
" goto / get_definition / usages " goto / get_definition / usages
if g:jedi#goto_command != '' if len(g:jedi#goto_command)
execute "nnoremap <buffer> ".g:jedi#goto_command." :call jedi#goto()<CR>" execute 'nnoremap <buffer> '.g:jedi#goto_command.' :call jedi#goto()<CR>'
endif endif
if g:jedi#goto_assignments_command != '' if len(g:jedi#goto_assignments_command)
execute "nnoremap <buffer> ".g:jedi#goto_assignments_command." :call jedi#goto_assignments()<CR>" execute 'nnoremap <buffer> '.g:jedi#goto_assignments_command.' :call jedi#goto_assignments()<CR>'
endif endif
if g:jedi#goto_definitions_command != '' if len(g:jedi#goto_definitions_command)
execute "nnoremap <buffer> ".g:jedi#goto_definitions_command." :call jedi#goto_definitions()<CR>" execute 'nnoremap <buffer> '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()<CR>'
endif endif
if g:jedi#usages_command != '' if len(g:jedi#usages_command)
execute "nnoremap <buffer> ".g:jedi#usages_command." :call jedi#usages()<CR>" execute 'nnoremap <buffer> '.g:jedi#usages_command.' :call jedi#usages()<CR>'
endif endif
" rename " rename
if g:jedi#rename_command != '' if len(g:jedi#rename_command)
execute "nnoremap <buffer> ".g:jedi#rename_command." :call jedi#rename()<CR>" execute 'nnoremap <buffer> '.g:jedi#rename_command.' :call jedi#rename()<CR>'
execute "vnoremap <buffer> ".g:jedi#rename_command." :call jedi#rename_visual()<CR>" execute 'vnoremap <buffer> '.g:jedi#rename_command.' :call jedi#rename_visual()<CR>'
endif endif
" documentation/pydoc " documentation/pydoc
if g:jedi#documentation_command != '' if len(g:jedi#documentation_command)
execute "nnoremap <silent> <buffer>".g:jedi#documentation_command." :call jedi#show_documentation()<CR>" execute 'nnoremap <silent> <buffer>'.g:jedi#documentation_command.' :call jedi#show_documentation()<CR>'
endif endif
if g:jedi#show_call_signatures > 0 && has('conceal') if g:jedi#show_call_signatures > 0 && has('conceal')

View File

@@ -4,10 +4,12 @@
" This part of the software is just the vim interface. The really big deal is " This part of the software is just the vim interface. The really big deal is
" the Jedi Python library. " 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) " jedi-vim doesn't work in compatible mode (vim script syntax problems)
if &compatible if &compatible
" vint: -ProhibitSetNoCompatible
set nocompatible set nocompatible
" vint: +ProhibitSetNoCompatible
endif endif
" jedi-vim really needs, otherwise jedi-vim cannot start. " jedi-vim really needs, otherwise jedi-vim cannot start.