weareunderdesign / rnbw

design. develop. ship.
https://rnbw.dev
GNU General Public License v3.0
57 stars 13 forks source link

Improve the HTML parser implementation #303

Closed atulbhatt-system32 closed 12 months ago

atulbhatt-system32 commented 1 year ago

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.

atulbhatt-system32 commented 1 year ago

Today I tried multiple approaches to find a good technique that can help us achieve codeview sync. Here are following steps I did:

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

atulbhatt-system32 commented 12 months ago

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.