Skip to content

Plaintext textDocument/hover malformed #10028

@sclu1034

Description

@sclu1034

When an LSP client only reports MarkupKind::Plaintext for capabilities.textDocument.hover.content_format, the text returned for a textDocument/hover request is still advertised as "kind": "markdown" and while the Markdown syntax is removed, whitespace is partially broken.

The following example includes

  • whitespace after dot missing
  • forced newline mid-sentence
  • code blocks not separated from text
{
    "jsonrpc": "2.0",
    "id": 13,
    "result": {
        "contents": {
            "kind": "markdown",
            "value": "fn\n\n\nA function or function pointer.Functions are the primary way code is executed within Rust. Function blocks, usually just\ncalled functions, can be defined in a variety of different places and be assigned many\ndifferent attributes and modifiers.Standalone functions that just sit within a module not attached to anything else are common,\nbut most functions will end up being inside impl blocks, either on another type itself, or\nas a trait impl for that type.fn standalone_function() {\n    // code\n}\n\npub fn public_thing(argument: bool) -> String {\n    // code\n    # \"\".to_string()\n}\n\nstruct Thing {\n    foo: i32,\n}\n\nimpl Thing {\n    pub fn new() -> Self {\n        Self {\n       foo: 42,\n        }\n    }\n}\n\nIn addition to presenting fixed types in the form of fn name(arg: type, ..) -> return_type,\nfunctions can also declare a list of type parameters along with trait bounds that they fall\ninto.fn generic_function<T: Clone>(x: T) -> (T, T, T) {\n    (x.clone(), x.clone(), x.clone())\n}\n\nfn generic_where<T>(x: T) -> T\n    where T: std::ops::Add<Output = T> + Copy\n{\n    x + x + x\n}\n\nDeclaring trait bounds in the angle brackets is functionally identical to using a where\nclause. It's up to the programmer to decide which works better in each situation, but where\ntends to be better when things get longer than one line.Along with being made public via pub, fn can also have an extern added for use in\nFFI.For more information on the various types of functions and how they're used, consult the Rust\nbook or the Reference."
        },
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 2
            }
        }
    }
}

The code tested with is src/main.rs from a fresh cargo new.

kak-lsp version: kakoune-lsp/kakoune-lsp@d5e39a9
rust-analyzer version: rust-analyzer cbbb7f351 2021-08-25 dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-hoverhover featureC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions