val-town / codemirror-codeium

Codeium code completion integration for CodeMirror 6
https://val-town.github.io/codemirror-codeium/
Other
46 stars 3 forks source link

Use decorations instead of inserts? #28

Open tmcw opened 1 month ago

tmcw commented 1 month ago

So right now this plugin works by inserting real code into your text editor. This is basically inherited from the implementation in modeling-app. The pro of this is that the 'ghost text' gets proper syntax coloring and behaves like real code. The con is that when we insert ghost text, it generates real change events, so the actual code in the editor changes when you have ghost text displayed. So you can get into situations like:

  1. You're editing some text
  2. You end a line of text with something
  3. Codeium feels like it has a good suggestion to show you
  4. The suggestion is displayed briefly
  5. You close the tab
  6. When you re-open the tab, the ghost text is shown as "unsaved changes that were recovered" (if you have a recovery system)

This is obviously less than ideal, and ends up with (in our case) having a method exposed like shouldTakeUpdate which lets upstream systems ignore change events. But the whole necessity of that shouldTakeUpdate method is driven just by the fact that ghost text is, surprisingly, real code in your editor.

tmcw commented 1 month ago

Having slept on it, realizing that the extra benefit of the current system is that it works smoothly with multi-line insertions and decorations probably wouldn't.