chore: Generate our own node ids instead of reusing tree-sitter's #393
No reviewers
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#393
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wetneb/mergiraf:own_node_ids"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is in preparation for mixing up nodes coming from different tree-sitter trees (for #5), which could potentially share ids as they would come from different parsing calls.
This also has the benefit of making those node ids more predictable and visually shorter, which should generally help in debugging.
With this change in place, maybe we could expand this test a little?
5d4b5787c6/src/visualizer.rs (L200)
5d4b5787c6
to0d190294a9
@ -179,3 +188,3 @@
field_name: None,
byte_range: start_position..start_position + trimmed.len(),
id: 2 * start_position + 1, // start_position is known to be unique among virtual lines
id: *next_node_id,
this looks like something we might accidentally mess up in a future refactoring... is it okay if I add a couple of tests for the whole id incrementing logic?
Sure, of course!
@ -199,2 +199,3 @@
fs::read_to_string(&target_path).expect("Could not read the generated graph.dot file");
assert!(contents.contains("subgraph ")); // yes, not a very great assertion… but node ids are all unstable!
let expected_contents = r##"graph matching {
the raw string thing is very handy!
While working on the test, I noticed that the description of the
id
field is now outdated. Could you please update it?So I made a test, not sure that we'll use it exactly as it is now. But while working on it, I made this:
One can see that the resulting tree structure ended up being a bit weird, but the ASCII tree kind of shows why that is:
so one level of nesting is created because the grammar splits the string on the escape sentence, and another we create ourselves, when splitting the second
string_content
, which corresponds toline 2\nline3
, into multiple lines. This can be something to keep in mind when working on improved handling of multiline string literals, since even though we don't splitline 1
into a separate line ourselves, it's still ends up effectively split away by the grammar.That aside, here's the more normal-looking version of the test:
As can be seen, removing the
\
made the whole tree a bit more understandable.The reason I wasn't sure we want to keep the test like is that the particular mapping of ids to nodes doesn't feel like something we want to guarantee. Since we're only really interested in the ids being unique, I think this much simpler test would be enough:
the
max
thing would be just to ensure that we actually use all 13 (=len
) available ids, not skipping anything -- but even that requirement is not strictly necessaryGreat! My preference goes to the second test, because I agree what matters here is the uniqueness of the ids, not their particular values. I wouldn't mind having the other one too, as long as we feel empowered to change or remove it later on if needed.
Are you able to commit them on my branch already or should I do it?
Well not commit directly, but I'll open a PR, one sec