Skip to content

Rust resolver panics on empty source (index out of bounds) #992

@dqnykamp

Description

@dqnykamp

Description

PublicDoenetMLCore panics with an index-out-of-bounds error when set_source() / return_dast() is called on empty (or whitespace-only) DoenetML source.

Steps to Reproduce

  1. Initialize a PublicDoenetMLCore instance
  2. Call core.set_flags("{}")
  3. Call core.set_source(dast, "") where dast is the parsed result of an empty string
  4. Call core.return_dast()

This triggers a Rust panic:

panicked at typed-index-collections-3.3.0/src/slice/slice_index.rs:108:10:
index out of bounds: the len is 0 but the index is 0

Full stack trace includes:

core::panicking::panic_bounds_check
<K as typed_index_collections::slice::slice_index::TiSliceIndex<K,V>>::index

Context

This was discovered while wiring the Rust WASM resolver into the LSP for autocompletion. When a user selects all text in the editor and deletes it, the LSP calls set_source with the empty document, which triggers the panic.

Current Workaround

The RustResolverAdapter in @doenet/lsp-tools now guards against empty source before calling into the Rust core, skipping the sync and falling back to JS-only autocompletion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions