WIP: First pass at terminal-mode completions #665
Draft
+196
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi :)
Following #305 I thought I'd have a crack at terminal-mode completions. This is very much at proof-of-concept stage, but I've enjoyed tinkering with it so far so would be happy to keep working on it if you don't mind feeding back on current progress and advising about design for next steps.
Key things to note:
I created
cmp/lib/term_events.lua
to listen for edits in the terminal. I usedvim.on_key()
to achieve this as there's no terminal equivalent for theInsertCharPre
event. I was pretty torn about simply lifting the code fromcmp/lib/cmdline_events.lua
, but decided against this as there's a few things there I didn't quite understand, e.g. the use of timers and everything being accomplished byon_cursor_moved()
. If you don't mind explaining what these are doing I'll be happy to add equivalent functionality if needed :)AFAIK Neovim doesn't provide a convenient API for inserting text into the terminal prompt, so I had to cobble something together using
vim.feedkeys()
. I also experimented withvim.paste()
, but the results didn't feel good.Still to do:
Autocompletion immediately triggers after accepting a suggestion. It looks like after accepting a suggestion like
Bla
, the final character in the accepted text, in this casea
, is once again used to trigger a completion. Unfortunately I couldn't work out how this is avoided in cmdline/insert mode, so very grateful for any pointers here. My guess is that this has something to do with my omission ofon_cursor_moved()
, but playing with this functionality hasn't (yet) led me to a fix.I haven't added any user-facing configuration for terminal mode. I can imagine this is something most users will want quite fine-grained control over, so I thought I'd seek some pointers on this before diving in.
Thanks in advance for review!