Closed atulbhatt-system32 closed 12 months ago
Today I tried multiple approaches to find a good technique that can help us achieve codeview sync. Here are following steps I did:
We are already sorted out with parser but we don't have a proper diffing solution. The current implementation that we are improving on which is based on the previous implementation isn't doing the diffing but rather using the concept of focused node (which doesn't exist on phcode) to determin where to perform changes.
There are differences in the phcode works and rnbw works is because:
Based on this, today I tried to achieve updating the stage with parsing entire code, which has to be done nevertheless even for diffing. The important part is updating the dom based on changes for better performance. I tried to use innerHTML to prevent rerender of stage but it had 2 issues:
Next I tried to use some diffing libraries.
What is diifing? Diffing gives us information about what exact part of the code has to be changed to convert an existing DOM into new DOM
Finally, the diffing has been implemented and codeview sync is great. There are some other issues which this change has brought in, or which can now be checked as the code changes from codeview are now reflected.
When we load our project in rnbw and pick a html file (or index.html by default as initial file), it is parsed to create a HTML nodetree.
But while we create this node tree, we don't have access to monaco instance as it is not loaded by that time. Due to this reason, we first create the tree and add start and end index for each node provided by parser to each node data.
Now, when everytime we select a node we have to do calculation based on start and endIndex of the code segment belonging to a particular node to find out where does our code for a particular node lies in codeview(editor).
In this issue we focus on resolving this and get a tree that already has data based on where our code is in the vs code, while we build the tree.
This has 2 benefits:
Currently, we have two methods to parse the HTML code. One that parses the entire file, and the other that parses the part of the HTML code that changes.
In this we also aim to make them one.
Added Bonus: Less code, Less Bugs.
PS: It will help in zero-sync as for codeview we are solving the position calculation of nodes in the codeview when they change. And it's related to the position part of it.