summaryrefslogtreecommitdiff
path: root/src/insert_completer.cc
AgeCommit message (Collapse)Author
2025-04-02Tweak ranked match behaviour to consider the number of full wordsMaxime Coste
Tracking the number of query words that appear as full words in the candidate seems to fix a few cases where the existing fuzzy matching algorithm was not great. I have been running with this for a while and did not notice any annoyances, the whole RankedMatch code probably deserves more attention but this seems to go in the right direction.
2024-09-02Explicitely call try_accept on InsertCompleterMaxime Coste
Calling it as part of the insert method was error prone and often led to slightly surprising behaviour, such as the <c-r><esc> hiding the menu on <esc>.
2024-08-16include headers cleanupAdrià Arrufat
2024-08-12Move debug utils to debug.hh/debug.ccMaxime Coste
Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times.
2024-07-22Handle word completion when recording macrosMaxime Coste
Make last insert and macro recording closer together, paving the way towards moving last insert to a register. Use a FunctionRef for insert completer key insertion support.
2024-04-12Introduce "local" scope in evaluate-commandsMaxime Coste
When using `eval` a new scope named 'local' gets pushed for the whole evaluation, this makes it possible to temporarily set an option/hook/alias... Local scopes nest so nested evals do work as expected. Remove the now trivial with-option command
2024-03-23Refactor last insert recording logicMaxime Coste
Only record non-synthetized insertions, removing the need to re-record on replay and fixing the last replay getting dropped by macro execution. Fixes #5122
2023-12-02ranked match: prefer input order over alphabetical order for user-specified ↵Johannes Altmanninger
completions When using either of set-option g completers option=my_option prompt -shell-script-candidates ... While the search text is empty, the completions will be sorted alphabetically. This is bad because it means the most important entries are not listed first, making them harder to select or even spot. Let's apply input order before resorting to sorting alphabetically. In theory there is a more elegant solution: sort candidates (except if they're user input) before passing them to RankedMatch, and then always use stable sort. However that doesn't work because we use a heap which doesn't support stable sort. Closes #1709, #4813
2023-12-02Reuse for_n_best when sorting values from complete optionsJohannes Altmanninger
While at it, remove a needless reserve() call and reserve an extra slot because "InsertCompleter::try_complete" might add one more element.
2023-11-03Use explicit target types for gather calls to bypass clang regressionMaxime Coste
Since clang-16 there has been a regression in the P0522R0 support. (Bug report at https://github.com/llvm/llvm-project/issue/63281) Closes #4892
2022-12-21This commit attempts to fix a crash with -f. Specifically when kakounepotatoalienof13
is run as > ./kak -f '2oK.k<c-n><ret><c-n>' /dev/null The crash occurs because when <c-n> is pressed for the second time, it attempts to use m_completions from the first press of <c-n>. This only happens when kakoune is run with -f, because when this is done interactively, there is a client, which means that m_completions gets reset. This removes the check that causes that difference. I am not *completely* sure that this is the best way to solve the problem, since I am not completely sure why that check was put there in the first place.
2022-11-28Fix pasting after when selections are overlappingMaxime Coste
With overlapping selections, pasting after breaks assumption of SelectionList::for_each as our changes are no longer happening in increasing locations. We hence cannot rely on the ForwardChangeTracker in that case and have to rely on the more general (and more costly) ranges update logic. This interacts poorly with paste linewise pastes and we try to preserve the current behaviour by tracking the last paste position. Overall, this change really begs for overlapping selections to be removed, but we will fix them like that for now. Fixes #4779
2022-06-04Code style cleanups around insert completerMaxime Coste
2022-05-29Run InsertCompletionHide hook before insertions that close completion menuJohannes Altmanninger
Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: https://github.com/mawww/kakoune/issues/2898 [snippets]: https://github.com/kak-lsp/kak-lsp/pull/616#discussion_r883208858 [LSP text edits]: https://github.com/kak-lsp/kak-lsp/issues/40
2022-02-15Merge remote-tracking branch 'krobelus/c-n-autocomplete'Maxime Coste
2022-02-11Filter duplicate completions only if they have the same select cmdJohannes Altmanninger
Given a completer option with two applicable completions text|select-cmd1|menu-text1 text|select-cmd2|menu-text2 Kakoune will only show one of them, because they will insert the same text. Some language servers send completions like this, for example if two different importable modules provide the same name. This can be reproduced using intelephense in this PHP file (cursor is %()) <?php namespace namespace1; class sometype {} ?> <?php namespace namespace2; class sometype {} ?> <?php namespace test; some%() ?> Both completions insert "sometype". The import statement will be added in an InsertCompletionHide hook by kak-lsp (it uses select-cmd to determine which completion was selected). To support this use case, refine the duplicate detection to not filter out completions with different select-cmd values.
2022-02-07Make <c-n> show completion menu again when autocomplete is offJohannes Altmanninger
As pointed out in [1], when insert mode autocomplete is disabled, <c-n> could be used to activate insert mode completions temporarily [2]. This regressed in 6f7c5aed (Do not show custom completions when autocomplete is off, 2022-01-03). Fix this by enabling completions on <c-n>/<c-p>. This allows us to remove a special case for explicit completers. Alternative behavior (future?): make <c-n> toggle completion like <c-o>. This can be done today, as suggested by Screwtape on IRC: map global insert <c-n> %{<c-o><c-n><a-;>:toggle-ctrl-n<ret>} define-command toggle-ctrl-n %{ hook global InsertCompletionShow .* %{ map window insert <c-n> <c-n> } hook global InsertCompletionHide .* %{ unmap window insert <c-n> <c-n> } } [1] https://github.com/mawww/kakoune/pull/4493#issuecomment-1031189823 [2] <c-n> completion only lives for the lifetime of the completion menu, whereas <c-o> lasts until you exit insert mode. This means that autocompletion is much more convenient than <c-n> or <c-x>f, because those require an explicit completion request for each path component.
2022-01-09Do not show custom completions when autocomplete is offJohannes Altmanninger
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
2021-12-11Fix explicit line completionMaxime Coste
trim_indent call was incorrect, trim_indent is intended to work on multi-line strings and trims trailing whitespace as well (could benefit from a better name). Fixes #4378
2021-04-11fix line completion with prefixTw
There's a bug in current line completion, fix it. Signed-off-by: Tw <tw19881113@gmail.com>
2020-12-22remove unused variable changes_trackerJean Abed
2020-11-20Ignore indent when completing linesAndrew Vos
When doing line completion, we previously used to not complete the line if it had different indent to the potential completion. This commit changes the behaviour to ignore indentation when completing lines.
2020-11-07Fix performance issue with word completionMaxime Coste
When pasting many words with <a-p> we can end-up with a huge concatenated word and many selections, the previous code ended up iterating from each selection cursor to that word start and end to find the word under the cursor. This could lead to performance issue as each selection would trigger iteration on that huge word. This is unnecessary as word completion has a word length limit, so we now take it into account to avoid iterating to far from the cursor position.
2020-10-12Code cleanup in insert completerMaxime Coste
2020-08-30Trigger InsertCompletionHide hook when switching to explicit completionMaxime Coste
Previously we would just bypass that hook making it impossible to act on the inserted text when triggering an explicit completion after inserting text from the previous completer.
2020-08-18Clear inserted_ranges after updating insert completions candidatesMaxime Coste
They were getting out-of-sync with the stored timestamp, leading to invalid ranges being computed and crashes. Fixes #3666 Fixes #3571
2020-06-27Refactor how InsetCompletionHide hook parameter is computedMaxime Coste
Keep track of inserted ranges instead of trying to re-derive them. Fixes #3556
2020-03-14Fix invalid access to deleted line when updating insert completionMaxime Coste
The computation of the completion end position was taking place too early, before we checked if the buffer did get modified. Fixes #3349
2020-01-08Update inserted range when generating InsertCompletionHide hook paramMaxime Coste
The buffer might have been mutated in the mean time. Fixes #3270
2019-12-01Pass inserted text ranges in InsertCompletionHide hook parameterMaxime Coste
Fixes #2898
2019-11-09Add static or const where usefulJason Felice
2019-10-17Limit word completion menu filename lengthMaxime Coste
2019-10-17Slight code style changeMaxime Coste
2019-07-09Filter non-extra_word_chars completion candidates using CodepointsMaxime Coste
Fixes #3010
2019-04-26Fix crash when finishing insert completion with no completion candidatesMaxime Coste
2019-04-17Remove InsertCompletionSelect hookMaxime Coste
2019-04-17Change completions option docstring element to be an arbitrary commandMaxime Coste
We can have the previous behaviour by just passing the docstring to `info -placement menu`.
2019-04-16Pass selected completion text to InsertCompletionHideMaxime Coste
2018-10-23Refactor Hook management to have a well defined list of hooksMaxime Coste
Hooks are now an enum class instead of passing strings around.
2018-07-15Fix manual insert completion menu not getting automatically hiddenMaxime Coste
Fixes #2208
2018-05-27Refactor option_from_string to return directly the option valueMaxime Coste
2018-05-26Do not expose C++ typeid().name to user facing errors on wrong option typeMaxime Coste
Fixes #2079
2018-05-03Add support for explicit menu selection from the UIMaxime Coste
the JsonUI now supports a "menu_select(int)" RPC call that should trigger explicit selection of the provided item index. As discussed for issue #2019.
2018-04-29Remove implicit conversion from String to DisplayAtom/DisplayLineMaxime Coste
2018-04-19Move get_word_db to word_db.ccMaxime Coste
2018-04-19Extract a for_n_best algorithm from completion functionMaxime Coste
Provide the heap based n-best algorithm through a nice interface.
2018-04-07Make FaceRegistry scopedMaxime Coste
set-face now takes a scope argument, and faces can be overridden on a buffer or window basis. colorscheme apply on global scope, which should be good enough for now. Fixes #1411
2018-03-25Avoid visiting the same directory multiple times in insert filename completionMaxime Coste
2018-03-25Allow explicit filename completion with empty prefixMaxime Coste
2018-03-25Remove contains_that and use any_of to be closer to the c++ stdlibMaxime Coste