elijah-potter / harper

The Grammar Checker for Developers
https://writewithharper.com
Apache License 2.0
1.88k stars 34 forks source link

`harper-ls` panics on hover #250

Closed mcecode closed 2 weeks ago

mcecode commented 3 weeks ago

How to reproduce

  1. Add a comment with an error on the first line of an empty file. Don't add a new line character at the end. Something like:

    // Hello thur
  2. Hover on the part with an error (i.e., thur).

  3. harper-ls panics.

Video

harper-issue.webm

Backtrace

thread 'main' panicked at harper-core/src/span.rs:14:9:
assertion failed: start <= end
stack backtrace:
   0:     0x5cfe23d9009a - std::backtrace_rs::backtrace::libunwind::trace::h99efb0985cae5d78
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x5cfe23d9009a - std::backtrace_rs::backtrace::trace_unsynchronized::he2c1aa63b3f7fad8
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5cfe23d9009a - std::sys::backtrace::_print_fmt::h8a221d40f5e0f88b
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:66:9
   3:     0x5cfe23d9009a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h304520fd6a30aa07
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:39:26
   4:     0x5cfe23db9e9b - core::fmt::rt::Argument::fmt::h5da9c218ec984eaf
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/rt.rs:177:76
   5:     0x5cfe23db9e9b - core::fmt::write::hf5713710ce10ff22
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/fmt/mod.rs:1178:21
   6:     0x5cfe23d8cb93 - std::io::Write::write_fmt::hda708db57927dacf
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/io/mod.rs:1823:15
   7:     0x5cfe23d91402 - std::sys::backtrace::BacktraceLock::print::hbcdbec4d97c91528
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:42:9
   8:     0x5cfe23d91402 - std::panicking::default_hook::{{closure}}::he1ad87607d0c11c5
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:266:22
   9:     0x5cfe23d9106e - std::panicking::default_hook::h81c8cd2e7c59ee33
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:293:9
  10:     0x5cfe23d91c8f - std::panicking::rust_panic_with_hook::had2118629c312a4a
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:797:13
  11:     0x5cfe23d91943 - std::panicking::begin_panic_handler::{{closure}}::h7fa5985d111bafa2
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:664:13
  12:     0x5cfe23d90579 - std::sys::backtrace::__rust_end_short_backtrace::h704d151dbefa09c5
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:170:18
  13:     0x5cfe23d91604 - rust_begin_unwind
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:662:5
  14:     0x5cfe2314f2d3 - core::panicking::panic_fmt::h3eea515d05f7a35e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:74:14
  15:     0x5cfe2314f35c - core::panicking::panic::h102d65dbfa674afe
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:148:5
  16:     0x5cfe23bef559 - harper_core::span::Span::new::hee131bcd70c3a03c
                               at /home/runner/work/harper/harper/harper-core/src/span.rs:14:9
  17:     0x5cfe235287d7 - harper_ls::pos_conv::range_to_span::h59e2749bea1d9e54
                               at /home/runner/work/harper/harper/harper-ls/src/pos_conv.rs:66:5
  18:     0x5cfe2355aa9f - harper_ls::backend::Backend::generate_code_actions::{{closure}}::h89c6c811702bd98d
                               at /home/runner/work/harper/harper/harper-ls/src/backend.rs:253:20
  19:     0x5cfe2356553a - <harper_ls::backend::Backend as tower_lsp::LanguageServer>::code_action::{{closure}}::h8630d026d8ba5e73
                               at /home/runner/work/harper/harper/harper-ls/src/backend.rs:487:14
  20:     0x5cfe232e87ff - <core::pin::Pin<P> as core::future::future::Future>::poll::h00a782dd6559540d
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  21:     0x5cfe233fced5 - tower_lsp::generated::register_lsp_methods::code_action::{{closure}}::hcb92baffee9c642e
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-lsp-0.20.0/src/lib.rs:112:1
  22:     0x5cfe234b0911 - tower_lsp::jsonrpc::router::Router<S,E>::method::{{closure}}::{{closure}}::{{closure}}::h4190c8572848bcb7
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-lsp-0.20.0/src/jsonrpc/router.rs:58:64
  23:     0x5cfe232e87ff - <core::pin::Pin<P> as core::future::future::Future>::poll::h00a782dd6559540d
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  24:     0x5cfe233cf7d0 - <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll::hb1202c5072022b2f
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  25:     0x5cfe2342cea1 - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::hb4ab6d6f1c2ddb7c
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  26:     0x5cfe232e963f - <core::pin::Pin<P> as core::future::future::Future>::poll::he2d9ef272df5413e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  27:     0x5cfe2332a9da - <futures_util::abortable::Abortable<Fut> as core::future::future::Future>::poll::{{closure}}::h2453f1c1e48629a6
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/abortable.rs:170:37
  28:     0x5cfe232f2528 - futures_util::abortable::Abortable<T>::try_poll::h5857ed60b6262d38
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/abortable.rs:144:33
  29:     0x5cfe2332a98a - <futures_util::abortable::Abortable<Fut> as core::future::future::Future>::poll::h8435ad2b312efdf2
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/abortable.rs:170:9
  30:     0x5cfe232ef775 - tower_lsp::service::pending::Pending::execute::{{closure}}::h1bccf6e05b9e6af1
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-lsp-0.20.0/src/service/pending.rs:41:48
  31:     0x5cfe234a0c1a - <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll::he6386fe5c124bb08
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/either.rs:108:32
  32:     0x5cfe232e963f - <core::pin::Pin<P> as core::future::future::Future>::poll::he2d9ef272df5413e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  33:     0x5cfe232e963f - <core::pin::Pin<P> as core::future::future::Future>::poll::he2d9ef272df5413e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  34:     0x5cfe232f1c7e - <tower_lsp::service::LspService<S> as tower_service::Service<tower_lsp::jsonrpc::request::Request>>::call::{{closure}}::h37c25d69d2fea784
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-lsp-0.20.0/src/service.rs:124:32
  35:     0x5cfe232e963f - <core::pin::Pin<P> as core::future::future::Future>::poll::he2d9ef272df5413e
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/future/future.rs:123:9
  36:     0x5cfe232dc22a - <F as futures_core::future::TryFuture>::try_poll::hdd4bcb4fe55d80f1
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-core-0.3.31/src/future.rs:92:9
  37:     0x5cfe232f0ee1 - <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll::hc0b9036b02d88bc0
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/try_future/into_future.rs:34:9
  38:     0x5cfe233d1435 - <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll::hd30b272463447f98
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  39:     0x5cfe2342bfd1 - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::h22d87426bbdceaa3
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  40:     0x5cfe2342dd01 - <futures_util::future::try_future::UnwrapOrElse<Fut,F> as core::future::future::Future>::poll::h164fc61f9c94a6f7
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  41:     0x5cfe235931c7 - <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next::h6146e6fa59e1e6d5
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/futures_unordered/mod.rs:528:17
  42:     0x5cfe23597ed0 - futures_util::stream::stream::StreamExt::poll_next_unpin::h178cc39b8276b91b
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/mod.rs:1638:9
  43:     0x5cfe2352a0c6 - <futures_util::stream::stream::buffer_unordered::BufferUnordered<St> as futures_core::stream::Stream>::poll_next::h09cd90fdf9d55907
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/buffer_unordered.rs:75:15
  44:     0x5cfe23410cc0 - <futures_util::stream::stream::filter_map::FilterMap<St,Fut,F> as futures_core::stream::Stream>::poll_next::h28fb48b3f3d16223
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/filter_map.rs:79:47
  45:     0x5cfe232f021c - <futures_util::stream::stream::map::Map<St,F> as futures_core::stream::Stream>::poll_next::h777cc48b30541611
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/map.rs:58:26
  46:     0x5cfe233f8163 - <futures_util::stream::stream::fuse::Fuse<S> as futures_core::stream::Stream>::poll_next::h21210b96624928d2
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/fuse.rs:53:27
  47:     0x5cfe23361e2b - <futures_util::stream::stream::forward::Forward<St,Si,Item> as core::future::future::Future>::poll::h353a5d5982e3bbb9
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/stream/stream/forward.rs:59:19
  48:     0x5cfe232bce53 - <futures_util::stream::stream::Forward<St,Si> as core::future::future::Future>::poll::h583c4cbac1af5817
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  49:     0x5cfe233d0b93 - <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll::hcbf5505c16bda4f8
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  50:     0x5cfe2342c6f3 - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::h648a12536ff94ec6
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  51:     0x5cfe2338c28f - <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll::h5944b2dc446392e5
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/maybe_done.rs:95:38
  52:     0x5cfe233c272a - tower_lsp::transport::Server<I,O,L>::serve::{{closure}}::{{closure}}::h53f45d08526ea1da
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/async_await/join_mod.rs:95:13
  53:     0x5cfe232eacf8 - <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::h07fe698aecf66112
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/poll_fn.rs:56:9
  54:     0x5cfe233bfe7c - tower_lsp::transport::Server<I,O,L>::serve::{{closure}}::hafc6fa337d8c4175
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-lsp-0.20.0/src/transport.rs:163:9
  55:     0x5cfe23566e86 - harper_ls::main::{{closure}}::hfe6a81a350282d54
                               at /home/runner/work/harper/harper/harper-ls/src/main.rs:53:59
  56:     0x5cfe2341f5ef - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::hd595a20ccd211ea3
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/park.rs:281:63
  57:     0x5cfe2341ea27 - tokio::runtime::coop::with_budget::h4247396180a4ba64
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:107:5
  58:     0x5cfe2341ea27 - tokio::runtime::coop::budget::hecb1cbeb70c9e955
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:73:5
  59:     0x5cfe2341ea27 - tokio::runtime::park::CachedParkThread::block_on::h55428d134cdfaefa
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/park.rs:281:31
  60:     0x5cfe233a37d3 - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::h62a03a5deb5d4129
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/blocking.rs:66:9
  61:     0x5cfe2346b438 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h960ec7fa59d1d43b
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  62:     0x5cfe233a2ebd - tokio::runtime::context::runtime::enter_runtime::h51ae7385b6aeb7be
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/runtime.rs:65:16
  63:     0x5cfe2346b3a3 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h93d9106e2949518c
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  64:     0x5cfe233a3bae - tokio::runtime::runtime::Runtime::block_on_inner::h56a3285095f40636
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/runtime.rs:363:45
  65:     0x5cfe233a3cf6 - tokio::runtime::runtime::Runtime::block_on::h6fb94d1290c2a69e
                               at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/runtime.rs:335:13
  66:     0x5cfe2356677e - harper_ls::main::h8596c5a8bab5b1aa
                               at /home/runner/work/harper/harper/harper-ls/src/main.rs:50:5
  67:     0x5cfe2343818b - core::ops::function::FnOnce::call_once::hab8d1010886c86fe
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  68:     0x5cfe2328942e - std::sys::backtrace::__rust_begin_short_backtrace::h427731ad8977e2b3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:154:18
  69:     0x5cfe23498491 - std::rt::lang_start::{{closure}}::hb3264b11e4773a84
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:164:18
  70:     0x5cfe23d843f0 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h08ecba131ab90ec4
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:284:13
  71:     0x5cfe23d843f0 - std::panicking::try::do_call::hf33a59fd8ce953f4
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  72:     0x5cfe23d843f0 - std::panicking::try::h5005ce80ce949fd8
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  73:     0x5cfe23d843f0 - std::panic::catch_unwind::hfbae19e2e2c5b7ed
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  74:     0x5cfe23d843f0 - std::rt::lang_start_internal::{{closure}}::ha0331c3690741813
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:48
  75:     0x5cfe23d843f0 - std::panicking::try::do_call::hcdcbdb616b4d0295
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  76:     0x5cfe23d843f0 - std::panicking::try::h3f2f1725a07d2256
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  77:     0x5cfe23d843f0 - std::panic::catch_unwind::h51869e04b56b2dc3
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  78:     0x5cfe23d843f0 - std::rt::lang_start_internal::h4d90db0530245041
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:143:20
  79:     0x5cfe2349846a - std::rt::lang_start::h88d7703b8f63eab4
                               at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/rt.rs:163:17
  80:     0x5cfe2356790e - main
  81:     0x770265429d90 - <unknown>
  82:     0x770265429e40 - __libc_start_main
  83:     0x5cfe2314fe4e - _start
  84:                0x0 - <unknown>
elijah-potter commented 3 weeks ago

I've found the issue! It's related to how we convert from the Language Server Protocol Range to Harper's Span. I'll get a fix drafted right away and you can test it. I've been testing Harper this whole time in Neovim, which adds line breaks for us. Since Visual Studio Code doesn't, we're hitting a bunch of new cases. Thanks for finding all these issues.

elijah-potter commented 3 weeks ago

Alright. The issue should be resolved. Give it go and let me know if you run into anything else.

mcecode commented 2 weeks ago

I can confirm that this issue has been resolved. I'll be closing it now. Thank you for the speedy bug fixes!