forked from VimPlug/jedi-vim
Merge pull request #454 from davidhalter/smart-import-mapping
Smart import mapping Closes https://github.com/davidhalter/jedi-vim/pull/453. Closes https://github.com/davidhalter/jedi-vim/pull/454.
This commit is contained in:
@@ -32,7 +32,8 @@ let s:default_settings = {
|
||||
\ 'popup_select_first': 1,
|
||||
\ 'quickfix_window_height': 10,
|
||||
\ 'completions_enabled': 1,
|
||||
\ 'force_py_version': "'auto'"
|
||||
\ 'force_py_version': "'auto'",
|
||||
\ 'smart_auto_mappings': 1
|
||||
\ }
|
||||
|
||||
for [key, val] in items(s:deprecations)
|
||||
@@ -422,6 +423,16 @@ function! jedi#complete_opened(is_popup_on_dot)
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#smart_auto_mappings()
|
||||
" Auto put import statement after from module.name<space> and complete
|
||||
if search('\<from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
|
||||
" Enter character and start completion.
|
||||
return "\<space>import \<C-x>\<C-o>\<C-r>=jedi#complete_opened(1)\<CR>"
|
||||
endif
|
||||
return "\<space>"
|
||||
endfunction
|
||||
|
||||
|
||||
"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)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ Contents *jedi-vim-contents*
|
||||
6.9. completions_enabled |g:jedi#completions_enabled|
|
||||
6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
||||
6.11. force_py_version |g:jedi#force_py_version|
|
||||
6.12. smart_auto_mappings |g:jedi#smart_auto_mappings|
|
||||
7. Testing |jedi-vim-testing|
|
||||
8. Contributing |jedi-vim-contributing|
|
||||
9. License |jedi-vim-license|
|
||||
@@ -481,6 +482,18 @@ Function: `jedi#force_py_version(py_version)`
|
||||
|
||||
Options: 2 or 3
|
||||
Default: "auto" (will use sys.version_info from "python" in your $PATH)
|
||||
------------------------------------------------------------------------------
|
||||
6.12. `g:jedi#smart_auto_mappings` *g:jedi#smart_auto_mappings*
|
||||
|
||||
When you start typing `from module.name<space>` jedi-vim automatically
|
||||
adds the "import" statement and displays the autocomplete popup.
|
||||
|
||||
This option can be disabled in the .vimrc:
|
||||
|
||||
`let g:jedi#smart_auto_mappings = 0`
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (enabled by default)
|
||||
|
||||
==============================================================================
|
||||
7. Testing *jedi-vim-testing*
|
||||
|
||||
@@ -37,6 +37,10 @@ if g:jedi#auto_initialization
|
||||
inoremap <silent> <buffer> . .<C-R>=jedi#complete_string(1)<CR>
|
||||
endif
|
||||
|
||||
if g:jedi#smart_auto_mappings == 1
|
||||
inoremap <buffer> <space> <C-R>=jedi#smart_auto_mappings()<CR>
|
||||
end
|
||||
|
||||
if g:jedi#auto_close_doc
|
||||
" close preview if its still open after insert
|
||||
autocmd InsertLeave <buffer> if pumvisible() == 0|pclose|endif
|
||||
|
||||
@@ -11,6 +11,17 @@ describe 'completions'
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'smart import'
|
||||
exec "normal ifrom os "
|
||||
Expect getline('.') == 'from os import '
|
||||
end
|
||||
|
||||
it 'no smart import after space'
|
||||
exec "normal! ifrom os "
|
||||
exec "normal a "
|
||||
Expect getline('.') == 'from os '
|
||||
end
|
||||
|
||||
it 'import'
|
||||
" X is the completion command
|
||||
normal oimporX
|
||||
|
||||
Reference in New Issue
Block a user