tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.23k stars 85 forks source link

LSP crash on _some_ modifications of a file imported in another #1943

Closed thufschmitt closed 3 weeks ago

thufschmitt commented 4 weeks ago

(yeah, convoluted title, but the repro is somewhat convoluted too, although I'm sure there could be a simpler one if I really understood the problem)

Describe the bug

If bar.ncl imports baz.ncl, and I modify baz.ncl in certain ways, then the LSP panics with a typechecking-related error.

See the gif below:

recording

The LSP crashes the instant I type the backtick character. Not every character triggers the crash. From some quick testing, it seems that at least the alphanumeric characters, &, / and @ don't cause it (but everything else I've tried, including things that are part of the grammar like ' cause it).

LSP log and backtrace ``` 2024-06-05T17:35:26.450 helix_lsp::transport [INFO] nls -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"text":"{\n '\n x,\n}\n"}],"textDocument":{"uri":"file:///tmp/tmp.MTYXidOIhu/baz.ncl","version":18}}} 2024-06-05T17:35:26.450 helix_lsp::transport [ERROR] nls err <- "thread 'main' panicked at core/src/typecheck/mod.rs:2793:26:\n" 2024-06-05T17:35:26.450 helix_lsp::transport [ERROR] nls err <- "Internal error: resolved import not found during typechecking.\n" 2024-06-05T17:35:26.450 helix_lsp::transport [ERROR] nls err <- "stack backtrace:\n" 2024-06-05T17:35:26.450 helix_lsp::transport [INFO] nls <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"message":"unexpected token","range":{"end":{"character":3,"line":1},"start":{"character":2,"line":1}},"relatedInformation":[],"severity":1},{"message":"","range":{"end":{"character":3,"line":1},"start":{"character":2,"line":1}},"severity":4}],"uri":"file:///tmp/tmp.MTYXidOIhu/baz.ncl"}} 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 0: 0x5583fe667f77 - ::fmt::h4886110ae7835fd2\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 1: 0x5583fe69f9e0 - core::fmt::write::h6fab83f0f5bc0c8f\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 2: 0x5583fe682075 - std::io::Write::write_fmt::h64824cb874054607\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 3: 0x5583fe667d44 - std::sys_common::backtrace::print::hb8fea9d041077138\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 4: 0x5583fe6688b7 - std::panicking::default_hook::{{closure}}::hc60f0f690c67943c\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 5: 0x5583fe668617 - std::panicking::default_hook::h56281bcc5d6e2f17\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 6: 0x5583fe668e28 - std::panicking::rust_panic_with_hook::hd61e30fe5971d187\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 7: 0x5583fe668d0a - std::panicking::begin_panic_handler::{{closure}}::h95d2684e28f89fd2\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 8: 0x5583fe6681a6 - std::sys_common::backtrace::__rust_end_short_backtrace::h48780d898316fff8\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 9: 0x5583fe668a54 - rust_begin_unwind\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 10: 0x5583fdfe69c5 - core::panicking::panic_fmt::hdb89b5c14a056cec\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 11: 0x5583fdfe7083 - core::option::expect_failed::h27bb97517ce6ecdf\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 12: 0x5583fe312b48 - nickel_lang_core::typecheck::apparent_type::apparent_type_check_cycle::h99ed9efde0589b4c\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 13: 0x5583fe311ba4 - nickel_lang_core::typecheck::binding_type::h99fb2226ace2bef7\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 14: 0x5583fe11a0a3 - nickel_lang_core::typecheck::walk::h018d5afc526ad349\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 15: 0x5583fe1162cb - nickel_lang_core::typecheck::type_check_with_visitor::h80d2621bc539c33a\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 16: 0x5583fe0bdf2a - ::typecheck_with_analysis::h0990007f53c1dc77\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 17: 0x5583fe04685f - nls::world::World::typecheck::h0cd585e708bef479\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 18: 0x5583fe0f93d1 - nls::files::handle_save::hf94b8957bcbf2471\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 19: 0x5583fe05925f - nls::server::Server::handle_message::h70ce56c31ba13d67\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 20: 0x5583fe057f2d - nls::server::Server::run::h9b4e1a179adb8dc2\n" 2024-06-05T17:35:26.454 helix_lsp::transport [ERROR] nls err <- " 21: 0x5583fe10da37 - nls::main::h2b0835bd328a43af\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 22: 0x5583fe103583 - std::sys_common::backtrace::__rust_begin_short_backtrace::h66567cb7208ae91d\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 23: 0x5583fe10359d - std::rt::lang_start::{{closure}}::hbe3c71ccfbaad6dc\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 24: 0x5583fe668954 - std::panicking::try::ha86251cf5daa9bea\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 25: 0x5583fe6580db - std::rt::lang_start_internal::ha6a51778162f8d22\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 26: 0x5583fe10f0e5 - main\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 27: 0x7fc9ac4e710e - __libc_start_call_main\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 28: 0x7fc9ac4e71c9 - __libc_start_main@@GLIBC_2.34\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 29: 0x5583fdfe7345 - _start\n" 2024-06-05T17:35:26.455 helix_lsp::transport [ERROR] nls err <- " 30: 0x0 - \n" 2024-06-05T17:35:26.461 helix_lsp::transport [ERROR] nls err: <- StreamClosed ```

To Reproduce

  1. Create the files:
    cat <<EOF > bar.ncl
    let baz = import "baz.ncl" in
    {}
    EOF
    cat <<EOF > baz.ncl
    {
      x,
    }
    EOF
  2. Open them in an editor with LSP properly setup
    hx -v bar.ncl baz.ncl --hsplit
  3. Add a backtick before the x in baz.ncl

Expected behavior A clear and concise description of what you expected to happen.

Environment

Additional context

That looks like it could be related to https://github.com/tweag/nickel/issues/1935 . Not 100% sure though

jneem commented 4 weeks ago

The specialness of ` comes from the fact that some parse errors are recoverable and others aren't, and we cache imports differently depending on whether the import completely failed to parse vs parsed with some errors. I'm not sure why ` triggers a complete failure but other characters don't...