Currently the way that most AI assisted code editing systems work is they send the complete source code of the file being edited to the LLM and request that the LLM reply with the complete code file back with the modifications made. This works fine for very small code files but breaks down rather quickly as the amount of source code in the file grows.
To solve this problem I implemented the snipSplicer npm package.
This library allows you to pass the content of an original code file with a properly formatted snippet and return the file modified applying the code from the snippet.
It works by parsing the original code and the snippet in to an AST and then uses a deterministic process to surgically replace existing functions or class methods with the ones in the snippet.
It also handles cases where the function or method dose not currently exist by either appending the function to the code file or inserting any new methods in to the proper class if it exists.
This approach is extremely reliable and consumes significantly fewer output tokens.
I am very interested in feedback and the possibility of supporting more languages in the future. Every thing is open source and I am happy to accept pull requests from the community to support more languages.
To solve this problem I implemented the snipSplicer npm package.
This library allows you to pass the content of an original code file with a properly formatted snippet and return the file modified applying the code from the snippet.
It works by parsing the original code and the snippet in to an AST and then uses a deterministic process to surgically replace existing functions or class methods with the ones in the snippet.
It also handles cases where the function or method dose not currently exist by either appending the function to the code file or inserting any new methods in to the proper class if it exists.
This approach is extremely reliable and consumes significantly fewer output tokens.
Here is a slide deck that discusses this approach and how it was implemented. https://docs.google.com/presentation/d/1xdX09ELgW7lMU1E9KWIr...
I am very interested in feedback and the possibility of supporting more languages in the future. Every thing is open source and I am happy to accept pull requests from the community to support more languages.
https://www.npmjs.com/package/snipsplicer https://github.com/mmiscool/snipsplicer