-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor change code, add TextRange and TextSize types #638
Conversation
I'm confused, was there prior discussion about this on Matrix? I don't quite understand the reason for this change 😅 |
I really appreciate your enthusiasm to contribute to Helix. However, it's not at all clear to me what the benefit of this refactor is, nor the new types you're adding. It feels like abstraction for abstraction's sake, and to my eye at least actually makes things less straight-forward/obvious. Maybe I missed where this was discussed, but I'd really recommend opening an issue to discuss sweeping changes like this and get some consensus before actually coding them up. That way you don't spend a lot of effort that just gets rejected. (Again, maybe I just missed where that discussion happened, in which case nevermind.) |
I did talk on matrix about something similar but that was just for me to understand things. There was no prior discussion matrix about this refactor, The reason for this change is that this greatly simplifies the code. A single |
Thanks for appreciating my enthusiasm! I should definitely post an issue next time, sorry. I think I definitely am not overabstracting though. I removed the |
@cessen Thanks for your suggestions. I have simplified the code a lot, it is now really nice. I think I did overabstract the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still not overtly clear to me what benefits this has over the existing code, but I'm not really familiar with this area of the codebase either. (I would also suggest marking this PR as a draft since I noticed a lot of commented code; there should be an option on the right-hand sidebar of this page)
pub use smallvec::SmallVec; | ||
pub use syntax::Syntax; | ||
|
||
pub use diagnostic::Diagnostic; | ||
pub use state::State; | ||
|
||
pub use line_ending::{LineEnding, DEFAULT_LINE_ENDING}; | ||
pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction}; | ||
pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline here.
/// | ||
/// It is a logic error for `start` to be greater than `end`. | ||
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] | ||
pub struct TextRange { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this basically just SelectionRange
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelectionRange
can be flipped
helix-core/src/text_size/traits.rs
Outdated
@@ -0,0 +1,25 @@ | |||
use super::size::TextSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also confused here, I feel like this is also already a covered case w/ RopeGraphemes
(I might be wrong though).
helix-core/src/text_size/traits.rs
Outdated
fn text_len(&self) -> TextSize { | ||
*self | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline.
helix-core/src/text_size/size.rs
Outdated
fn sum<I: Iterator<Item = A>>(iter: I) -> TextSize { | ||
iter.fold(0.into(), Add::add) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline.
Could you explain what you still don't think has benefits over the existing code? I think I can keep |
From the cursory look I gave, it seems to me that you can achieve the same benefit for less abstraction/work by improving upon the already-existing code in |
Like I explained above, the existing |
I agree with @cessen's sentiment: I appreciate the effort put into this, but a sweeping change that affects all open PRs needs a prior discussion (see #362 for an example). In particular, it's good to talk through why the code is currently the way it is, because there's often a reason behind it.
The diff is currently +1200 -500. It's also very noisy, most of the diff is renaming various existing structs, I'd prefer to keep those names as is.
There are of course reasons why we have two types right now. The editing primitive is an But
Since the changeset builder is more low-level and we control all the methods I was thinking there's no need to do a check for ordering and this should actually be a debug_assert. Kakoune has built-in assertions in debug builds that verify a bunch of invariants before and after every command. |
I have put the new
Change
in a separate file and haven't updated everything yet.