Skip to content

Debug version panics on autocompletion when cursor is between two brackets #3087

@Glyphack

Description

@Glyphack

Summary

I found this panic using a fuzzer. It only happens on debug bulids. The following is a minimal reproduction:

#[test]
fn no_panic_argument_completion_before_paren() {
    let builder = completion_test_builder(
        r#"
list[int]<CURSOR>()
#",
    );

    assert_snapshot!(
        builder.skip_keywords().skip_builtins().skip_auto_import().build().snapshot(),
        @"<No completions found after filtering out completions>",
    );
}

The debug assert that is causing the panic is here:

https://github.com/astral-sh/ruff/blob/ffeee66dfaf1b4fb1200be2bf8443fcc03e9258e/crates/ty_ide/src/completion.rs#L1474

This checks that we are in an Arguments node. But the caller is only checking if the cursor is within the range for Arguments node.

But I'm not familiar with this part of code so I also removed the debug assert to see if anything strange would happen. The test passes with no completions.

So this is why I opened this issue I wanted to fix it but I also don't know what's the best way because I didn't understand the intent of the code.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    completionsBugs or features relating to autocomplete suggestionsfatala fatal error (panic or crash)serverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions