Fix invalidating cache with jedi#show_call_signatures (#968)

This commit is contained in:
Daniel Hahler
2019-12-08 17:26:24 +01:00
committed by Dave Halter
parent ac6b2f1e3e
commit c80a08d983
2 changed files with 26 additions and 5 deletions

View File

@@ -581,15 +581,16 @@ function! jedi#show_call_signatures() abort
" Caching. On the same line only.
if line == s:show_call_signatures_last[0]
" Check if the number of commas and parenthesis before or after the
" Check if the number of special signs before or after the
" cursor has not changed since the last call, which means that the
" argument position was not changed and we can skip repainting.
let prevcol = s:show_call_signatures_last[1]
let prevline = s:show_call_signatures_last[2]
if substitute(curline[:col-2], '[^,()]', '', 'g')
\ == substitute(prevline[:prevcol-2], '[^,()]', '', 'g')
\ && substitute(curline[(col-2):], '[^,()]', '', 'g')
\ == substitute(prevline[(prevcol-2):], '[^,()]', '', 'g')
let no_special = '[^,()=]'
if substitute(curline[:col-2], no_special, '', 'g')
\ == substitute(prevline[:prevcol-2], no_special, '', 'g')
\ && substitute(curline[(col-2):], no_special, '', 'g')
\ == substitute(prevline[(prevcol-2):], no_special, '', 'g')
let reload_signatures = 0
endif
endif

View File

@@ -44,6 +44,26 @@ describe 'signatures'
Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable*_*) ?!?jedi?!?'
end
it 'highlights correct argument'
if !has('python3')
SKIP 'py2: no signatures with print()'
endif
noautocmd normal o
doautocmd CursorHoldI
noautocmd normal iprint(42, sep="X", )
" Move to "=" - hightlights "sep=...".
noautocmd normal 5h
doautocmd CursorHoldI
Expect getline(1) =~# '\V\^?!?jedi=0, ?!? (*values: object, *_*sep: Text=...*_*'
" Move left to "=" - hightlights first argument ("values").
" NOTE: it is arguable that maybe "sep=..." should be highlighted
" still, but this tests for the cache to be "busted", and that
" fresh results are retrieved from Jedi.
noautocmd normal h
doautocmd CursorHoldI
Expect getline(1) =~# '\V\^?!?jedi=0, ?!? (*_**values: object*_*, sep: Text=...,'
end
it 'no signature'
exe 'normal ostr '
Python jedi_vim.show_call_signatures()