5 ms·
I added next-edit-prediction to my neovim plugin. This was pretty interesting to implement! - I used an [lsp server](https://github.com/dlants/magenta.nvim/pu
by anonymid 1y ago
I added next-edit-prediction to my neovim plugin.
This was pretty interesting to implement!
- I used an [lsp server](https://github.com/dlants/magenta.nvim/pull/162/files#diff-395b9b79c8fe674e7bec94a8eb94932c68b2db8986966fe5939c8f6cf26a3e57R224 https://github.com/dlants/magenta.nvim/pull/162/files#diff-3...) to track opened files and aggregate text changes to get a stream of diffs.
- I then feed that along with the [context surrounding the cursor](https://github.com/dlants/magenta.nvim/pull/162/files#diff-1f8dad660a61513bd12e337121880a700072723e28ea0abb14015514b2161391R509 https://github.com/dlants/magenta.nvim/pull/162/files#diff-1...), and a [system prompt](https://github.com/dlants/magenta.nvim/pull/162/files#diff-a235f14a480d8482676e8a6e9bc95d7b694b205397ac8e7947481e95cd0f0fe3R305 https://github.com/dlants/magenta.nvim/pull/162/files#diff-a...) into an LLM, [forcing a tool use for a find/replace within the context window](https://github.com/dlants/magenta.nvim/pull/162/files#diff-1f8dad660a61513bd12e337121880a700072723e28ea0abb14015514b2161391R895 https://github.com/dlants/magenta.nvim/pull/162/files#diff-1...)
- Finally, I show the find/replace in the buffer using [virtual text extmarks](https://github.com/dlants/magenta.nvim/pull/162/files#diff-1f8dad660a61513bd12e337121880a700072723e28ea0abb14015514b2161391R423 https://github.com/dlants/magenta.nvim/pull/162/files#diff-1...), applying a comment effect to the added sections, and a strikethrough to the removed sections
One thing that is interesting about this is that I wasn't able to get good results from smaller/faster models like claude haiku, so I opted to use a larger model instead. I found that the small delay of about a second was worth it for more consistent results.
I also opted to have this be manually triggered (Shift-Ctrl-l by default in insert or normal mode). This is a lot [less distracting](https://unstable.systems/@sop/114898566686215926 https://unstable.systems/@sop/114898566686215926).
One cool thing is that you can use a plugin parameter, or a project-level parameter to [append to the system prompt](https://github.com/dlants/magenta.nvim/blob/main/node/options.ts#L92 https://github.com/dlants/magenta.nvim/blob/main/node/option...). I think by providing additional [examples of how you want it to behave](https://github.com/dlants/magenta.nvim/blob/main/node/providers/system-prompt.ts#L310 https://github.com/dlants/magenta.nvim/blob/main/node/provid...), you can have it be a lot more useful for your specific use-case.
- anonymid 1y agoYou can see a gif of it in the readme https://github.com/dlants/magenta.nvim?tab=readme-ov-file https://github.com/dlants/magenta.nvim?tab=readme-ov-file