kneasle / sapling

A highly experimental vi-inspired editor where you edit code, not text.
MIT License
720 stars 19 forks source link

Replacing fields results in an invalid tree #78

Open kneasle opened 3 years ago

kneasle commented 3 years ago

Suppose that the cursor is over a field in an object (cursor in <>):

{
     <"key": null>
}

If we type rt at this point will result in the following invalid object:

{
    <true>
}

AFAIK, this is not an easy fix (at least, no easy fix that actually solves the cause of the problem). The main issue is that objects implicitly create fields to contain their children, a very nice UX feature that causes some jank with tree validation.

stokhos commented 3 years ago

https://github.com/kneasle/sapling/blob/b5ec298c38552244d0ba61152febb3737885244e/src/editor/dag.rs#L412-L415

I'm working on this one, and I'm not sure why do you think it is not feasible ?

https://github.com/kneasle/sapling/blob/b5ec298c38552244d0ba61152febb3737885244e/src/ast/test_json.rs#L48 Was there a reason that you put an immutable array inside Json::Field?

Is this sort of related to #11

kneasle commented 3 years ago

I'm working on this one, and I'm not sure why do you think it is not feasible ?

Oh hang on - I'm also working on this :sweat_smile: - at least I'm doing some more huge refactoring, which will eventually fix this.

The thing that made me say this might be hard is that just fixing it for JSON objects is not really enough - I'd like to actually fix the problem that causes this. Unless I've missed something? - it's entirely possible that I'm making a mountain out of a molehill here.

Was there a reason that you put an immutable array inside Json::Field?

Yes - it's needed because Ast::children has to return a reference to a slice with the same lifetime as the node. And the only way to do this (without unsafe) is to explicitly store the key and value as a slice. The refactoring I'm doing is to change Ast into a Node type which has an AstClass and a Vec of children, and with that change there'll be no need to do janky things like that.

Is this sort of related to #11

Perhaps? I don't think it has that much connection.

stokhos commented 3 years ago

The thing that made me say this might be hard is that just fixing it for JSON objects is not really enough - I'd like to actually fix the problem that causes this. Unless I've missed something? - it's entirely possible that I'm making a mountain out of a molehill here.

Looking forward to your refactoring. Kind of want to get a master degree in CS. This is so fun.

kneasle commented 3 years ago

Kind of want to get a master degree in CS. This is so fun.

Go for it! I've no idea how the US university(/college?) system works, but it must be possible to do another degree. Fair warning, though - degree level CS is just as much about learning logic and maths as it is about programming - but knowing the theory is incredibly useful, even if learning it is less fun than just writing code all the time :laughing:.

stokhos commented 3 years ago

Actually I'm close to get a master degree in math. I learned some algorithm, and data structure from math department, but I have almost forgotten all of them. I definitely will get a degree in CS in near future.

kneasle commented 3 years ago

Actually I'm close to get a master degree in math. I learned some algorithm, and data structure from math department, but I have almost forgotten all of them. I definitely will get a degree in CS in near future.

Oh cool! I also enjoyed the course we had on algorithms and datastructures - until I got to an exam and discovered that the exams were just really really hard :laughing:. But I think that was just the person who wrote the exam being overoptimistic about how good the students were.

stokhos commented 3 years ago

But I think that was just the person who wrote the exam being overoptimistic about how good the students were. Profs always have unrealistic high expectation on students

kneasle commented 3 years ago

Absolutely :laughing:! This wasn't the worst module, actually - we had one exam where one of the examiner's reports said something along the lines of 'even compared to other years, this group did badly'...

stokhos commented 3 years ago

Absolutely laughing! This wasn't the worst module, actually - we had one exam where one of the examiner's reports said something along the lines of 'even compared to other years, this group did badly'...

Haha, actually, it was not you guys did badly in exam. It was the Prof didn't pay much attention in teaching.

kneasle commented 3 years ago

That's often true, I'll admit. But I think this was the opposite - the lecturer put so much effort into teaching that he expected the students to do really well in his crazily hard exam...