I want to build a custom editor following this guide: https://code.visualstudio.com/api/extension-guides/custom-editors
My editor is also backed by JSON, but when studying the example it says
// Just replace the entire document every time for this example extension.
// A more complete extension should compute minimal edits instead.
How do I actually concretely do this?
Since the VSCode settings editor is also a GUI for a JSON file, is there some API to turn JSON changes into document edits?
Or are there JSON parsers that have some sort of red-green tree based structure to relate JSON data back to source location?
2
Answers
I found jsonc-parser which has an API for applying modifications to a JSON document and generating text offsets and such. It is authored by Microsoft and seems widely used within VSCode
To compute minimal edits to a JSON document for a VSCode WorkspaceEdit, you can follow these general steps:
Parse the original JSON document and the desired modified JSON document into their respective data structures.
Compare the two data structures to identify the differences between them. This can be done by recursively traversing the structures and comparing each element.
As you identify differences, keep track of the read more