helix icon indicating copy to clipboard operation
helix copied to clipboard

Switch to regex-cursor

Open pascalkuthe opened this issue 7 months ago • 6 comments

Closes #185

Replaces our use of regex with regex-cursor, so we don't have to convert ropes to string. That implementation passes the regex testsuite so it should be stable but definitely needs testing.

See discussion at https://github.com/rust-lang/regex/issues/425.

I used the chance to replace split_at_newline with something that uses ropey so that unicode feature flags are correctly respected (should also be slightly faster).

pascalkuthe avatar Jan 25 '24 16:01 pascalkuthe

Crashed with (not sure what I did)

thread 'main' panicked at /home/sumire/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-cursor-0.1.2/src/input.rs:204:13:
internal error: entered unreachable code: cursor does not support backtracking 506
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: regex_cursor::engines::dfa::search::find_fwd
   3: regex_cursor::engines::dfa::try_search
   4: regex_cursor::engines::meta::strategy::StrategyI::search
   5: regex_cursor::engines::meta::regex::Regex::search
   6: helix_term::commands::search_impl
   7: helix_term::commands::search_next_or_prev_impl
   8: helix_term::ui::editor::EditorView::handle_keymap_event::{{closure}}
   9: helix_term::ui::editor::EditorView::handle_keymap_event
  10: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::handle_event
  11: helix_term::compositor::Compositor::handle_event
  12: hx::main_impl::{{closure}}
  13: tokio::runtime::park::CachedParkThread::block_on
  14: tokio::runtime::context::runtime::enter_runtime
  15: tokio::runtime::runtime::Runtime::block_on
  16: hx::main

kirawi avatar Jan 31 '24 16:01 kirawi

Crashed with (not sure what I did)

thread 'main' panicked at /home/sumire/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-cursor-0.1.2/src/input.rs:204:13:
internal error: entered unreachable code: cursor does not support backtracking 506
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: regex_cursor::engines::dfa::search::find_fwd
   3: regex_cursor::engines::dfa::try_search
   4: regex_cursor::engines::meta::strategy::StrategyI::search
   5: regex_cursor::engines::meta::regex::Regex::search
   6: helix_term::commands::search_impl
   7: helix_term::commands::search_next_or_prev_impl
   8: helix_term::ui::editor::EditorView::handle_keymap_event::{{closure}}
   9: helix_term::ui::editor::EditorView::handle_keymap_event
  10: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::handle_event
  11: helix_term::compositor::Compositor::handle_event
  12: hx::main_impl::{{closure}}
  13: tokio::runtime::park::CachedParkThread::block_on
  14: tokio::runtime::context::runtime::enter_runtime
  15: tokio::runtime::runtime::Runtime::block_on
  16: hx::main

Thats a stranfe one that shouldn't happen but it's very hard to track down without reproduction case (the backtrack is too stripped because it's a release build)

pascalkuthe avatar Jan 31 '24 17:01 pascalkuthe

Ah, it's hx then /git nix. This is on a personal fork with multiple PRs pulled in (I forgot to mention) but I don't think any of them touch regex.

Edit: I can reproduce with this branch alone

kirawi avatar Jan 31 '24 17:01 kirawi

oh yeah I can reproduce that is very odd. Is suspect it has do do with the special case of an empty file

pascalkuthe avatar Jan 31 '24 18:01 pascalkuthe

I don't think it's a special case with an empty file. If you delete the entire buffer and then do /git n it won't crash. If you add a new line and then 1G, it won't crash. If you add a new line without moving the cursor, it crashes. Maybe it has something to do with the cursor being on the line before the EOF newline?

kirawi avatar Jan 31 '24 18:01 kirawi

It was an edgecase when you search for stuff at a one-past-the-end position which is what I suspected. Adapting the ropey cursor semantics to the one regex-cusor uses isn't trivial. I published a new version where that is fixed

pascalkuthe avatar Jan 31 '24 19:01 pascalkuthe

I also haven't hit any bugs with this anymore

gabydd avatar Feb 25 '24 16:02 gabydd