From 6f7c5aed107c183565661336ae840998a73e783f Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 3 Jan 2022 22:43:04 +0100 Subject: [PATCH] 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 --- src/insert_completer.cc | 6 ++++-- src/insert_completer.hh | 1 + test/regression/0-autocomplete-overrules-completers/in | 3 +++ .../regression/0-autocomplete-overrules-completers/out | 3 +++ test/regression/0-autocomplete-overrules-completers/rc | 6 ++++++ .../0-autocomplete-overrules-completers/script | 10 ++++++++++ 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/regression/0-autocomplete-overrules-completers/in create mode 100644 test/regression/0-autocomplete-overrules-completers/out create mode 100644 test/regression/0-autocomplete-overrules-completers/rc create mode 100644 test/regression/0-autocomplete-overrules-completers/script diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 54792052..f32b35ca 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -461,12 +461,12 @@ void InsertCompleter::select(int index, bool relative, Vector& keystrokes) void InsertCompleter::update(bool allow_implicit) { + m_enabled = allow_implicit or m_explicit_completer; if (m_explicit_completer and try_complete(m_explicit_completer)) return; reset(); - if (allow_implicit) - setup_ifn(); + setup_ifn(); } auto& get_first(BufferRange& range) { return range.begin; } @@ -500,6 +500,8 @@ void InsertCompleter::reset() bool InsertCompleter::setup_ifn() { + if (!m_enabled) + return false; using namespace std::placeholders; if (not m_completions.is_valid()) { diff --git a/src/insert_completer.hh b/src/insert_completer.hh index b3c7480d..1d68be86 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -107,6 +107,7 @@ private: InsertCompletion m_completions; Vector m_inserted_ranges; int m_current_candidate = -1; + bool m_enabled = true; using CompleteFunc = InsertCompletion (const SelectionList& sels, const OptionManager& options, diff --git a/test/regression/0-autocomplete-overrules-completers/in b/test/regression/0-autocomplete-overrules-completers/in new file mode 100644 index 00000000..b28b04f6 --- /dev/null +++ b/test/regression/0-autocomplete-overrules-completers/in @@ -0,0 +1,3 @@ + + + diff --git a/test/regression/0-autocomplete-overrules-completers/out b/test/regression/0-autocomplete-overrules-completers/out new file mode 100644 index 00000000..ee504471 --- /dev/null +++ b/test/regression/0-autocomplete-overrules-completers/out @@ -0,0 +1,3 @@ + +a2 +./ui-in diff --git a/test/regression/0-autocomplete-overrules-completers/rc b/test/regression/0-autocomplete-overrules-completers/rc new file mode 100644 index 00000000..a3c831f3 --- /dev/null +++ b/test/regression/0-autocomplete-overrules-completers/rc @@ -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" diff --git a/test/regression/0-autocomplete-overrules-completers/script b/test/regression/0-autocomplete-overrules-completers/script new file mode 100644 index 00000000..5a4d2aaf --- /dev/null +++ b/test/regression/0-autocomplete-overrules-completers/script @@ -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": [ "" ] }' +# Implicit completion can be toggled. +ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji" ] }' +# Explicit completion still works. +ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji./ui-f" ] }' +