Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Improve call signatures setup #652

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
15dcbe7
Add jedi#setup_call_signatures, moving code from after/syntax/python.vim
blueyed Jan 7, 2017
b464fc7
call signatures: move setup into configure_call_signatures
blueyed Jan 7, 2017
95c2326
Init first_col with show_call_signatures == 2
blueyed Jan 7, 2017
8fbf3fa
Improve clear_call_signatures: restore orig lines
blueyed Jan 7, 2017
b00e1ff
Clear call signatures immediately when changing lines
blueyed Jan 7, 2017
c10836b
Use timers for show_call_signatures_delay
blueyed Jan 7, 2017
96fb99d
Add support for call signatures in normal mode
blueyed Jan 7, 2017
90f5b6c
fixup! Use timers for show_call_signatures_delay
blueyed Jan 26, 2017
67882dd
fixup! Use timers for show_call_signatures_delay
blueyed Jan 26, 2017
2f9da85
jedi_vim.completions: do not clear signatures for a:findstart
blueyed Jan 26, 2017
9a7133c
fixup! Add support for call signatures in normal mode
blueyed Jan 26, 2017
33c3e3e
fixup! fixup! Add support for call signatures in normal mode
blueyed Feb 2, 2017
89acff1
fixup! fixup! fixup! Add support for call signatures in normal mode
blueyed Feb 2, 2017
2aaf894
clear/show callsigs on BufWritePre/BufWritePost
blueyed Mar 7, 2017
5b77cb5
g:jedi#show_call_signatures: remove ignore
blueyed May 12, 2017
52bc68c
fixup! fixup! fixup! Add support for call signatures in normal mode
blueyed May 14, 2017
54ef8df
fixup! g:jedi#show_call_signatures: remove ignore
blueyed May 14, 2017
5929097
show_call_signatures: simplify regexp/tup
blueyed May 14, 2017
e4f2b0a
jedi#configure_call_signatures: hook into InsertEnter/InsertLeave for…
blueyed May 14, 2017
55821ac
doc
blueyed Jul 16, 2018
c5a34e7
Remove unnecessary check in jedi_vim.show_call_signatures
blueyed Jul 16, 2018
8369729
Pass in mode to jedi_vim.show_call_signatures
blueyed Jul 16, 2018
8f55d86
fix tests (simple)
blueyed Jul 25, 2018
f8a8b19
fix tests (nasty)
blueyed Jan 2, 2021
3a43a7a
doc: jedi#configure_call_signatures
blueyed Jul 25, 2018
43e930e
completions: fix call to show_call_signatures when restoring
blueyed Aug 19, 2019
efcc7a2
WIP: use floating / popup windows for call signatures
blueyed Sep 16, 2019
c4979e8
no trailing space
blueyed Sep 18, 2019
767651f
add missing ./syntax/jedi_signature.vim
blueyed Nov 10, 2019
fc39910
doc: _show_call_signatures_mode: 3=floatwin
blueyed Dec 5, 2019
63c8883
align code for clear_call_signatures with concealing
blueyed Dec 5, 2019
5192d0d
Fixes for popupwin in Vim, revisit above/below
blueyed Dec 5, 2019
cf2bb9f
revisit prefer_below: winline/winheight, check for whitespace above
blueyed Dec 6, 2019
d61ba46
handle space_{above_below} <= 0, fix min height/offset for putting above
blueyed Dec 6, 2019
f103084
call_signatures_floatwin: replace leading whitespace after \n
blueyed Feb 24, 2020
2861a3b
fix(call_signatures_floatwin): use noautocmd=True with neovim
blueyed Jun 22, 2021
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
29 changes: 1 addition & 28 deletions after/syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,6 @@ if !jedi#init_python()
finish
endif

if g:jedi#show_call_signatures > 0 && has('conceal')
" +conceal is the default for vim >= 7.3

let s:e = g:jedi#call_signature_escape
let s:full = s:e.'jedi=.\{-}'.s:e.'.\{-}'.s:e.'jedi'.s:e
let s:ignore = s:e.'jedi.\{-}'.s:e
exe 'syn match jediIgnore "'.s:ignore.'" contained conceal'
setlocal conceallevel=2
syn match jediFatSymbol "\*_\*" contained conceal
syn match jediFat "\*_\*.\{-}\*_\*" contained contains=jediFatSymbol
syn match jediSpace "\v[ ]+( )@=" contained
exe 'syn match jediFunction "'.s:full.'" keepend extend '
\ .' contains=jediIgnore,jediFat,jediSpace'
\ .' containedin=pythonComment,pythonString,pythonRawString'
unlet! s:e s:full s:ignore

hi def link jediIgnore Ignore
hi def link jediFatSymbol Ignore
hi def link jediSpace Normal

if exists('g:colors_name')
hi def link jediFunction CursorLine
hi def link jediFat TabLine
else
hi def jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
hi def jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
endif
endif
call jedi#configure_call_signatures()

hi def jediUsage cterm=reverse gui=standout
186 changes: 167 additions & 19 deletions autoload/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let s:default_settings = {
\ 'documentation_command': "'K'",
\ 'show_call_signatures': has('conceal') ? 1 : 2,
\ 'show_call_signatures_delay': 500,
\ 'show_call_signatures_modes': "'i'",
\ 'call_signature_escape': "'?!?'",
\ 'auto_close_doc': 1,
\ 'max_doc_height': 30,
Expand Down Expand Up @@ -569,40 +570,187 @@ function! jedi#show_call_signatures() abort
let s:show_call_signatures_last = [line, col, curline]

if reload_signatures
python3 jedi_vim.show_call_signatures()
exe printf('python3 jedi_vim.show_call_signatures((), %d)',
\ g:jedi#show_call_signatures)
endif
endfunction

function! s:show_call_signatures_delayed_cb(timer) abort
if [getpos('.'), mode()] == s:show_call_signatures_delayed_posmode
call jedi#show_call_signatures()
endif
endfunction

function! jedi#show_call_signatures_delayed(mode) abort
if exists('s:show_call_signatures_timer')
call timer_stop(s:show_call_signatures_timer)
unlet s:show_call_signatures_timer
endif
" Clear call signatures immediately when changing the line.
if line('.') != s:show_call_signatures_last[0]
call jedi#clear_call_signatures()
endif
let s:show_call_signatures_delayed_posmode = [getpos('.'), a:mode]
let s:show_call_signatures_timer = timer_start(
\ g:jedi#show_call_signatures_delay,
\ function('s:show_call_signatures_delayed_cb'))
endfunction


function! jedi#clear_call_signatures() abort
if s:_init_python == 0
return 1
endif

if s:show_call_signatures_last[0] == 0
" No call signature displayed currently.
return
endif
let s:show_call_signatures_last = [0, 0, '']
python3 jedi_vim.clear_call_signatures()
endfunction


function! jedi#configure_call_signatures() abort
augroup jedi_call_signatures
autocmd! * <buffer>
if g:jedi#show_call_signatures == 2 " Command line call signatures
autocmd InsertEnter <buffer> let g:jedi#first_col = s:save_first_col()
endif
autocmd InsertEnter <buffer> let s:show_call_signatures_last = [0, 0, '']
autocmd InsertLeave <buffer> call jedi#clear_call_signatures()
if g:jedi#show_call_signatures_delay > 0
autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
\ | let &updatetime = g:jedi#show_call_signatures_delay
autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
\ | let &updatetime = b:_jedi_orig_updatetime
\ | unlet b:_jedi_orig_updatetime
\ | endif
autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
let s:prev_show_call_signatures = 0
" a:1 (optional): new setting
" a:2 (optional): new mode
function! jedi#configure_call_signatures(...) abort
if a:0
let old = g:jedi#show_call_signatures
let new = a:1
else
autocmd CursorMovedI <buffer> call jedi#show_call_signatures()
let old = s:prev_show_call_signatures
let new = g:jedi#show_call_signatures
endif
if a:0 > 1
let g:jedi#show_call_signatures_modes = a:2
endif

if new == 1 && !has('conceal')
echohl WarningMsg
echom "jedi-vim's show_call_signatures=1 requires the conceal feature."
echohl None
return
endif

let g:jedi#show_call_signatures = new

if s:prev_show_call_signatures
call jedi#clear_call_signatures()
endif
if new != s:prev_show_call_signatures
" Cleanup.
if s:prev_show_call_signatures == 1
syn clear jediIgnore jediFatSymbol jediFat jediSpace jediFunction
setl conceallevel&
endif
endif
let s:prev_show_call_signatures = g:jedi#show_call_signatures

if g:jedi#show_call_signatures == 0
augroup jedi_call_signatures
au!
augroup END
return

elseif g:jedi#show_call_signatures == 1
let e = g:jedi#call_signature_escape
let full = e.'jedi='.e.'.\{-}'.e.'jedi'.e
let ignore = e.'jedi=\='.e
exe 'syn match jediIgnore "'.ignore.'" contained conceal'
setlocal conceallevel=2
syn match jediFatSymbol "\*_\*" contained conceal
syn match jediFat "\*_\*.\{-}\*_\*" contained contains=jediFatSymbol
syn match jediSpace "\v[ ]+( )@=" contained
exe 'syn match jediFunction "'.full.'" keepend extend '
\ .' contains=jediIgnore,jediFat,jediSpace'
\ .' containedin=pythonComment,pythonString,pythonRawString'

hi def link jediIgnore Ignore
hi def link jediFatSymbol Ignore
hi def link jediSpace Normal

if hlexists('CursorLine')
hi def link jediFunction CursorLine
else
hi def jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
endif
if hlexists('TabLine')
hi def link jediFat TabLine
else
hi def jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
endif

elseif g:jedi#show_call_signatures == 2
" Init (from InsertEnter), for when jedi-vim is lazy-loaded on
" InsertEnter.
let s:callsig_cmd_first_col = s:save_first_col()
endif

augroup jedi_call_signatures
autocmd! * <buffer>
if g:jedi#show_call_signatures == 2 " Command line call signatures
autocmd InsertEnter <buffer> let s:callsig_cmd_first_col = s:save_first_col()
elseif g:jedi#show_call_signatures == 1
autocmd ColorScheme <buffer> call jedi#configure_call_signatures()
" autocmd Syntax <buffer> debug call jedi#configure_call_signatures()
endif

if g:jedi#show_call_signatures_modes =~# 'i' && g:jedi#show_call_signatures_modes !~# 'n'
autocmd InsertLeave <buffer> call jedi#clear_call_signatures()
endif

if g:jedi#show_call_signatures_modes =~# 'n'
autocmd BufWritePre <buffer> call jedi#clear_call_signatures()
autocmd BufWritePost <buffer> call jedi#show_call_signatures()
endif

if g:jedi#show_call_signatures_delay > 0
if has('timers')
if g:jedi#show_call_signatures_modes =~# 'n'
autocmd WinEnter,CursorMoved <buffer> call jedi#show_call_signatures_delayed('n')
endif
if g:jedi#show_call_signatures_modes =~# 'i'
autocmd InsertEnter,CursorMovedI <buffer> call jedi#show_call_signatures_delayed('i')
elseif g:jedi#show_call_signatures_modes =~# 'n'
autocmd InsertEnter <buffer> call jedi#clear_call_signatures()
endif
else
autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
\ | let &updatetime = g:jedi#show_call_signatures_delay
autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
\ | let &updatetime = b:_jedi_orig_updatetime
\ | unlet b:_jedi_orig_updatetime
\ | endif

if g:jedi#show_call_signatures_modes =~# 'n'
" Note: does not use g:jedi#show_call_signatures_delay!
autocmd WinEnter,CursorHold <buffer> call jedi#show_call_signatures()
" Clear signatures immediately when changing lines.
autocmd CursorMoved <buffer>
\ if line('.') != s:show_call_signatures_last[0]
\ | call jedi#clear_call_signatures()
\ | endif
endif
if g:jedi#show_call_signatures_modes =~# 'i'
autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
" Clear signatures immediately when changing lines.
autocmd CursorMovedI <buffer>
\ if line('.') != s:show_call_signatures_last[0]
\ | call jedi#clear_call_signatures()
\ | endif
endif
endif
else
if g:jedi#show_call_signatures_modes =~# 'n'
" Note: does not use g:jedi#show_call_signatures_delay!
" Should probably have a warning, at least in the docs about that
" option! (without any delay)
autocmd InsertLeave,CursorMoved <buffer> call jedi#show_call_signatures()
endif
if g:jedi#show_call_signatures_modes =~# 'i'
autocmd InsertEnter,CursorMovedI <buffer> call jedi#show_call_signatures()
endif
endif
augroup END
endfunction

Expand Down
27 changes: 18 additions & 9 deletions doc/jedi-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,15 @@ Default: 1 (Automatically close preview window upon leaving insert mode)
------------------------------------------------------------------------------
6.6. `g:jedi#show_call_signatures` *g:jedi#show_call_signatures*

Jedi-vim can display a small window detailing the arguments of the currently
completed function and highlighting the currently selected argument. This can
be disabled by setting this option to 0. Setting this option to 2 shows call
signatures in the command line instead of a popup window.
Jedi-vim can display call signatures (detailing the arguments) of the
currently completed function and highlight the currently selected argument in
an overlay.
This uses Vim's |conceal| feature, and temporarily changes the buffer, which
can lead to problems.
Use 2 to show call signatures in the command line instead.

Options: 0, 1, or 2
Default: 1 (Show call signatures window)
Default: 1 (Show call signatures overlay)

Note: 'showmode' must be disabled for command line call signatures to be
visible.
Expand All @@ -414,13 +416,20 @@ that case, if you want to see call signatures, you have to set it up
manually by calling a function in your configuration file: >

call jedi#configure_call_signatures()

<
You should also call this function after changing the setting, or use the
function directly to change it: >
call jedi#configure_call_signatures(1)
<
------------------------------------------------------------------------------
6.7. `g:jedi#show_call_signatures_delay` *g:jedi#show_call_signatures_delay*

The delay to be used with |g:jedi#show_call_signatures|. If it is greater
than 0 it will use Vim's |CursorHoldI| event instead of |CursorMovedI|.
It will temporarily set Vim's |'updatetime'| option during insert mode.
The delay to be used with |g:jedi#show_call_signatures|.
If it is greater than 0 it will use Vim's |+timers| feature to delay the
display of the signature, instead of on |CursorMovedI| directly.

(If |+timers| is not available, a fallback through the |CursorHoldI| event is
used, where Vim's |'updatetime'| option is changed while in insert mode)

Options: delay in milliseconds
Default: 500
Expand Down
Loading