helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.65k stars 2.5k forks source link

Crash while browsing workspace symbol picker #8259

Closed eilvelia closed 1 year ago

eilvelia commented 1 year ago

Edit https://github.com/prepor/ocaml-edn/blob/12e54ae9deefbbd69299b74f966724a231a50df4/src/edn.ml (happens on other projects too), press space S to open the picker, hold down, helix crashes closer to the end of the list.

$ nix shell github:helix-editor/helix
[…]
$ RUST_BACKTRACE=full hx src/edn.ml
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Line index out of bounds: line index 1904, Rope/RopeSlice line count 89', /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vendor-cargo-deps/c19b7c6f923b580ac259164a89f2577984ad5ab09ee9d583b888f934adbbe8d0/ropey-1.6.0/src/rope.rs:764:41
stack backtrace:
   0:        0x106e65c6b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9da7574d41a27793
   1:        0x1063a300b - core::fmt::write::h30e9018632f2aef2
   2:        0x106e6180e - std::io::Write::write_fmt::h56af08ec60343535
   3:        0x106e65a1a - std::sys_common::backtrace::print::h4d81fafe758cf4b8
   4:        0x106e6a855 - std::panicking::default_hook::{{closure}}::h120f229f25c70a74
   5:        0x106e6a625 - std::panicking::default_hook::hceec3dccba707793
   6:        0x106e6af52 - std::panicking::rust_panic_with_hook::h6683bf919d2bf510
   7:        0x106e6ac84 - std::panicking::begin_panic_handler::{{closure}}::h9ad2a0e8640ca3c3
   8:        0x106e68cb9 - std::sys_common::backtrace::__rust_end_short_backtrace::h1aa11996f1542333
   9:        0x106e6a9e2 - _rust_begin_unwind
  10:        0x106f40ca3 - core::panicking::panic_fmt::hb305629a540f8ae6
  11:        0x106f41135 - core::result::unwrap_failed::h1066469645d18ac3
  12:        0x1069d0870 - <helix_term::ui::picker::Picker<T> as helix_term::compositor::Component>::render::h74dc3964a5ed4ff5
  13:        0x106c14793 - helix_term::application::Application::render::{{closure}}::h691ee7993501402e
  14:        0x106c122f2 - helix_term::application::Application::run::{{closure}}::h3bf88bc37f9daf4b
  15:        0x106c29bca - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::ha74a9e6857453a73
  16:        0x106c70b0f - tokio::runtime::context::runtime::enter_runtime::h66d441fd93e21d7f
  17:        0x106ca356d - tokio::runtime::runtime::Runtime::block_on::h5a44c645f53787f8
  18:        0x106bfd621 - hx::main::h3b3529f11a9265e6
  19:        0x106c1d256 - std::sys_common::backtrace::__rust_begin_short_backtrace::h57e60ee102d15a04
  20:        0x106c1d541 - std::rt::lang_start::{{closure}}::hb63f915239eaf79d
  21:        0x106e5b654 - std::rt::lang_start_internal::h2bb66f5226335a85
  22:        0x106bfd70c - _main
~/.cache/helix/helix.log The log is too long for GitHub: https://pastebin.com/mPGhahyW

Platform

macOS, nix

Terminal Emulator

kitty 0.29.2

Helix Version

both helix master ccabfee3811bdcc8372beaae777a98fd36e2657e and helix 23.05 (7f5940be)

pascalkuthe commented 1 year ago

this is caused by the OCMAL LSP sending invalid symbols with ranges far past the end of the file.

For example:

{"deprecated":false,"kind":12,"location":{"range":{"end":{"character":59,"line":1900},"start":{"character":0,"line":1887}},"uri":"file:///home/pascalkuthe/git/ocaml-edn/src/edn_read.mll"},"name":"__ocaml_lex_read_comment_rec"}

was send by the server but edn_read.mll only has about 90 lines.

I will add some extra redundancy here so we at least won't crash but the best you will get here is <file not found>. This is ultimately a bug in the LS and should be reported to them.

eilvelia commented 1 year ago

Thanks, it looks like the lsp server reports symbols that are present in generated files and not in the actual source files. There are already some existing issues and PRs like https://github.com/ocaml/ocaml-lsp/pull/1097, I'll look into that. Nevertheless, fixing the panic would indeed be helpful so that even in the presence of invalid symbols I can fuzzy-search over the valid ones without randomly crashing if invalid one gets in the way. file not found is ok, since the symbols aren't really there anyway.

pascalkuthe commented 1 year ago

the panic is fixed in https://github.com/helix-editor/helix/pull/8265