Skip to content

Position.character is not clamped to line length

Open

Description

LSP says about Position::character

If the character value is greater than the line length it defaults back
to the line length.

but from_proto::offset() doesnt' implement this

    let text_size = line_index.index.offset(line_col).ok_or_else(|| {
        format_err!("Invalid offset {line_col:?} (line index length: {:?})", line_index.index.len())
    })?;

I hit this because rust-analyzer crashes with the kakoune-lsp client because -- if there is no code action in the selection -- this client falls back to requesting code actions for the whole line by simply specifying Position::character=1e6.
I worked around the crash by sending the actual line length instead.

I'm not yet sure what we should do, following the protocol can help but the downside is that we're masking potential bugs

I haven't yet found a case where a client inherently needs this behavior, so it doesn't seem important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-lspLSP conformance issues and missing featuresLSP conformance issues and missing features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions