1
0
mirror of https://github.com/amix/vimrc synced 2025-07-13 06:35:01 +08:00

jedi for python

This commit is contained in:
liushouda
2015-07-24 19:34:08 +08:00
parent 2a8d620b8a
commit d931023720
27 changed files with 2517 additions and 0 deletions

View File

@ -0,0 +1,52 @@
let g:jedi#completions_command = 'X'
source plugin/jedi.vim
describe 'completions'
before
new
set filetype=python
end
after
bd!
end
it 'import'
" X is the completion command
normal oimporX
Expect getline('.') == 'import'
normal a subproX
Expect getline('.') == 'import subprocess'
end
it 'exception'
normal oIndentationErrX
Expect getline('.') == 'IndentationError'
normal a().filenaX
Expect getline('.') == 'IndentationError().filename'
end
it 'dot_open'
normal oraisX ImpXErrX()
Expect getline('.') == 'raise ImportError()'
end
it 'cycling through entries'
" testing select_first doesn't seem to work in ex mode
execute "normal oraise impX\<C-n>\<C-n>\<C-n>"
Expect getline('.') == 'raise ImportWarning'
let g:jedi#popup_select_first = 0
execute "normal oraise impX\<C-n>\<C-n>\<C-n>"
Expect getline('.') == 'raise ImportWarning'
let g:jedi#popup_select_first = 1
" -longest completes the first one
set completeopt -=longest
execute "normal oraise baseX"
Expect getline('.') == 'raise BaseException'
set completeopt +=longest
end
end
" vim: et:ts=4:sw=4

View File

@ -0,0 +1,21 @@
let g:jedi#completions_command = 'X'
let g:jedi#completions_enabled = 0
source plugin/jedi.vim
describe 'completions_disabled'
before
new
set filetype=python
end
after
bd!
end
it 'typing'
normal oraise ImportErrX
Expect getline('.') == 'raise ImportErrX'
end
end
" vim: et:ts=4:sw=4

View File

@ -0,0 +1,31 @@
source plugin/jedi.vim
describe 'documentation docstrings'
before
set filetype=python
end
after
bd!
bd!
end
it 'simple'
put = 'ImportError'
normal GK
Expect bufname('%') == "'__doc__'"
Expect &filetype == 'rst'
let content = join(getline(1,'$'), "\n")
Expect stridx(content, "Import can't find module") > 0
normal K
Expect bufname('%') == ''
end
it 'no documentation'
put = 'x = 2'
normal o<ESC>GK
Expect bufname('%') == ''
end
end
" vim: et:ts=4:sw=4

View File

@ -0,0 +1,180 @@
let mapleader = '\'
source plugin/jedi.vim
source test/utils.vim
describe 'goto_simple'
before
new " open a new split
set filetype=python
put =[
\ 'def a(): pass',
\ 'b = a',
\ 'c = b',
\ ]
normal! ggdd
normal! G$
Expect line('.') == 3
end
after
bd!
end
it 'goto_definitions'
silent normal \d
Expect line('.') == 1
"Expect col('.') == 5 " not working yet.
end
it 'goto_assignments'
silent normal \g
Expect line('.') == 2
Expect col('.') == 1
" cursor before `=` means that it stays there.
silent normal \g
Expect line('.') == 2
Expect col('.') == 1
" going to the last line changes it.
normal! $
silent normal \g
Expect line('.') == 1
Expect col('.') == 5
end
end
describe 'goto_with_tabs'
before
set filetype=python
let g:jedi#use_tabs_not_buffers = 1
end
after
bd!
bd!
end
it 'follow_import'
put = ['import subprocess', 'subprocess']
silent normal G\g
Expect getline('.') == 'import subprocess'
Expect line('.') == 2
Expect col('.') == 8
silent normal G\d
Expect CurrentBufferIsModule('subprocess') == 1
Expect line('.') == 1
Expect col('.') == 1
Expect tabpagenr('$') == 2
Expect winnr('$') == 1
tabprevious
Expect bufname('%') == ''
end
it 'multi_definitions'
" This used to behave differently. Now we don't have any real multi
" definitions.
" put = ['import tokenize']
" silent normal G$\d
" Expect CurrentBufferIsModule('tokenize') == 1
" Expect CurrentBufferIsModule('token') == 0
" execute "normal \<CR>"
" Expect tabpagenr('$') == 2
" Expect winnr('$') == 1
" Expect CurrentBufferIsModule('token') == 1
" bd
" silent normal G$\d
" execute "normal j\<CR>"
" Expect tabpagenr('$') == 2
" Expect winnr('$') == 1
" Expect CurrentBufferIsModule('tokenize') == 1
end
end
describe 'goto_with_buffers'
before
set filetype=python
let g:jedi#use_tabs_not_buffers = 0
end
after
bd!
bd!
set nohidden
end
it 'no_new_tabs'
put = ['import os']
normal G$
call jedi#goto_assignments()
python jedi_vim.goto()
Expect CurrentBufferIsModule('os') == 0
" Without hidden, it's not possible to open a new buffer, when the old
" one is not saved.
set hidden
call jedi#goto_assignments()
Expect CurrentBufferIsModule('os') == 1
Expect winnr('$') == 1
Expect tabpagenr('$') == 1
Expect line('.') == 1
Expect col('.') == 1
end
it 'multi_definitions'
" set hidden
" put = ['import tokenize']
" silent normal G$\d
" Expect CurrentBufferIsModule('tokenize') == 0
" Expect CurrentBufferIsModule('token') == 0
" execute "normal \<CR>"
" Expect tabpagenr('$') == 1
" Expect winnr('$') == 1
" Expect CurrentBufferIsModule('token') == 1
" bd
" silent normal G$\d
" execute "normal j\<CR>"
" Expect tabpagenr('$') == 1
" Expect winnr('$') == 1
" Expect CurrentBufferIsModule('tokenize') == 1
end
end
describe 'goto_with_splits'
before
set filetype=python
let g:jedi#use_splits_not_buffers = 'left'
end
after
bd!
bd!
end
it 'follow_import'
put = ['import subprocess', 'subprocess']
silent normal G\g
Expect getline('.') == 'import subprocess'
Expect line('.') == 2
Expect col('.') == 8
silent normal G\d
Expect CurrentBufferIsModule('subprocess') == 1
Expect line('.') == 1
Expect col('.') == 1
Expect winnr('$') == 2
wincmd l
Expect bufname('%') == ''
end
end
" vim: et:ts=4:sw=4

View File

@ -0,0 +1,32 @@
source plugin/jedi.vim
source test/utils.vim
describe 'pyimport'
before
let g:jedi#use_tabs_not_buffers = 1
end
after
bd!
bd!
end
it 'open_tab'
Pyimport os
Expect CurrentBufferIsModule('os') == 1
Pyimport subprocess
Expect CurrentBufferIsModule('subprocess') == 1
" the empty tab is sometimes also a tab
Expect tabpagenr('$') >= 2
end
it 'completion'
" don't know how to test this directly
"execute "Pyimport subproc\<Tab>"
"Expect CurrentBufferIsModule('subprocess') == 1
Expect jedi#py_import_completions('subproc', 0, 0) == 'subprocess'
Expect jedi#py_import_completions('subprocess', 0, 0) == 'subprocess'
Expect jedi#py_import_completions('zip', 0, 0) == "zipfile\nzipimport"
end
end

View File

@ -0,0 +1,66 @@
source plugin/jedi.vim
describe 'signatures'
before
set filetype=python
end
after
bd!
bd!
end
it 'simple'
normal oabs(
" equals doautocmd CursorMovedI
Python jedi_vim.show_call_signatures()
Expect getline(1) == '=`=jedi=0, =`= (*_*number*_*) =`=jedi=`='
doautocmd InsertLeave
Expect getline(1) == ''
end
it 'no signature'
normal ostr
Python jedi_vim.show_call_signatures()
Expect getline(1, '$') == ['', 'str ']
end
it 'signatures disabled'
let g:jedi#show_call_signatures = 0
normal ostr(
Python jedi_vim.show_call_signatures()
Expect getline(1, '$') == ['', 'str( ']
let g:jedi#show_call_signatures = 1
end
it 'command line simple'
let g:jedi#show_call_signatures = 2
call jedi#configure_call_signatures()
normal oabs(
redir => msg
Python jedi_vim.show_call_signatures()
redir END
Expect msg == "\nabs(number)"
redir => msg
doautocmd InsertLeave
redir END
Expect msg == "\n\n"
end
it 'command line no signature'
let g:jedi#show_call_signatures = 2
call jedi#configure_call_signatures()
normal ostr
redir => msg
Python jedi_vim.show_call_signatures()
redir END
Expect msg == "\n"
end
end

View File

@ -0,0 +1,11 @@
function! CurrentBufferIsModule(module_name)
return EndsWith(bufname('%'), a:module_name.'.py')
endfunction
function EndsWith(string, end)
let l:should = len(a:string) - strlen(a:end)
return l:should == stridx(a:string, a:end, should)
endfunction
" vim: et:ts=4:sw=4