From c80a08d9835565bb8988d6314dfec616f70c53da Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 8 Dec 2019 17:26:24 +0100 Subject: [PATCH] Fix invalidating cache with `jedi#show_call_signatures` (#968) --- autoload/jedi.vim | 11 ++++++----- test/vspec/signatures.vim | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index c31804f..e106b47 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -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 diff --git a/test/vspec/signatures.vim b/test/vspec/signatures.vim index ca4248e..22bfb73 100644 --- a/test/vspec/signatures.vim +++ b/test/vspec/signatures.vim @@ -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()