Do not show custom completions when autocomplete is off

As reported in [1], completions provided by "set global completers
option=my_completion" activate insert mode autocompletion, even when
the autocomplete option does not have the insert mode flag.

This happens because InsertCompleter::on_option_changed() calls
InsertCompleter::setup_ifn(), which shows the completion pager.
Fix this by computing whether the completion pager is enabled;
otherwise we can return early from setup_ifn().
The completion pager is enabled if the autocompletion bit is set,
or if the user has requested explicit completion.

[1]: https://github.com/kak-lsp/kak-lsp/issues/585
This commit is contained in:
Johannes Altmanninger 2022-01-03 22:43:04 +01:00
parent 871782faaf
commit 6f7c5aed10
6 changed files with 27 additions and 2 deletions

View File

@ -461,11 +461,11 @@ void InsertCompleter::select(int index, bool relative, Vector<Key>& keystrokes)
void InsertCompleter::update(bool allow_implicit) void InsertCompleter::update(bool allow_implicit)
{ {
m_enabled = allow_implicit or m_explicit_completer;
if (m_explicit_completer and try_complete(m_explicit_completer)) if (m_explicit_completer and try_complete(m_explicit_completer))
return; return;
reset(); reset();
if (allow_implicit)
setup_ifn(); setup_ifn();
} }
@ -500,6 +500,8 @@ void InsertCompleter::reset()
bool InsertCompleter::setup_ifn() bool InsertCompleter::setup_ifn()
{ {
if (!m_enabled)
return false;
using namespace std::placeholders; using namespace std::placeholders;
if (not m_completions.is_valid()) if (not m_completions.is_valid())
{ {

View File

@ -107,6 +107,7 @@ private:
InsertCompletion m_completions; InsertCompletion m_completions;
Vector<BufferRange> m_inserted_ranges; Vector<BufferRange> m_inserted_ranges;
int m_current_candidate = -1; int m_current_candidate = -1;
bool m_enabled = true;
using CompleteFunc = InsertCompletion (const SelectionList& sels, using CompleteFunc = InsertCompletion (const SelectionList& sels,
const OptionManager& options, const OptionManager& options,

View File

@ -0,0 +1,3 @@

View File

@ -0,0 +1,3 @@
a2
./ui-in

View File

@ -0,0 +1,6 @@
set-option global autocomplete prompt
declare-option -hidden completions line1_completions
declare-option -hidden completions line2_completions
set-option global completers option=line1_completions option=line2_completions
set-option global line1_completions "1.1+0@%val(timestamp)" "a1||a1"
set-option global line2_completions "2.1+0@%val(timestamp)" "a2||a2"

View File

@ -0,0 +1,10 @@
ui_out -ignore 4
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "i" ] }'
sleep .2 # trigger insert completion auto update
# Implicit completion is disabled via autocomplete.
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "<c-n><esc>" ] }'
# Implicit completion can be toggled.
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji<c-o><c-n><esc>" ] }'
# Explicit completion still works.
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji./ui-<c-x>f<c-n>" ] }'