Skip to content

Panic on trying to highlight new file (even when empty) #15907

@yaksher

Description

@yaksher

rust-analyzer version: rust-analyzer version: 0.3.1730-standalone (416e9c8 2023-11-12)

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

relevant settings: No settings that I can think of being relevant

Adding a new file to a project causes rust-analyzer to fail to analyze that file and print a panic to output. This happens both when the file is empty and when rerunning with code in the file.

Panic context:
> 
version: 0.3.1730-standalone (416e9c856 2023-11-12)
request: textDocument/documentHighlight DocumentHighlightParams {
    text_document_position_params: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/Users/yaksher/rustbucket/rustbucket/src/hashbucket/hashbucket.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 0,
            character: 7,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread 'Worker' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rowan-0.15.11/src/cursor.rs:751:9:
Bad offset: range 0..1 offset 7
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rowan::cursor::SyntaxNode::token_at_offset
   3: ide::highlight_related::highlight_related
   4: std::panicking::try
   5: rust_analyzer::handlers::request::handle_document_highlight
   6: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 3:04:10 PM] Request textDocument/documentHighlight failed.
  Message: request handler panicked: Bad offset: range 0..1 offset 7
  Code: -32603 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions