Skip to content

Documentation is missing lines from code snippets #17966

Closed
@wildework

Description

@wildework

I'm getting completion results with missing lines from documentation code blocks.

rust-analyzer version: rust-analyzer version: 0.3.2086-standalone (7106cd3be 2024-08-25)

rustc version: rustc 1.80.1 (3f5fd8dd4 2024-08-06)

editor or extension: Manually LSP server requests but same behavior with VS Code Version: 1.92.2.

code snippet to reproduce:

fn main() {
    // Place cursor at the end of ...by and the completion suggestion will include incorrect documentation.
    u16::from_le_by
}
Screenshot 2024-08-26 at 11 03 23

The generated documentation has the full snippets. Also, the same as the official docs

let value = u16::from_le_bytes([0x34, 0x12]);
assert_eq!(value, 0x1234);

and

fn read_le_u16(input: &mut &[u8]) -> u16 {
    let (int_bytes, rest) = input.split_at(std::mem::size_of::<u16>());
    *input = rest;
    u16::from_le_bytes(int_bytes.try_into().unwrap())
}

Whereas rust-analyzer generates the first block as empty code and the second one with two lines with the rest missing.

Here's the LSP server completion response JSON.

{
        "label": "from_le_bytes",
        "kind": 3,
        "detail": "const fn([u8; {in type const InTypeConstId(36)}]) -> u16",
        "documentation": {
          "kind": "markdown",
          "value": "Create a native endian integer value from its representation\nas a byte array in little endian.\n\n\n\n# Examples\n\n```rust\n```\n\nWhen starting from a slice rather than an array, fallible conversion APIs can be used:\n\n```rust\n    *input = rest;\n}\n```"
        },
        "deprecated": false,
        "sortText": "ffffffe0",
        "filterText": "from_le_bytes",
        "textEdit": {
          "range": {
            "start": {
              "line": 22,
              "character": 9
            },
            "end": {
              "line": 22,
              "character": 18
            }
          },
          "newText": "from_le_bytes"
        },
        "additionalTextEdits": []
},

Activity

deleted a comment from on Aug 26, 2024
Veykril

Veykril commented on Aug 26, 2024

@Veykril
Member

This is known, the cause is that r-a can't yet expand macros in inert attributes (closing it as t here are bunch of issues regarding this already)

wildework

wildework commented on Aug 26, 2024

@wildework
Author

Thanks! Perhaps you could link to the other issues that refer to this issue? I looked but couldn't find them. @Veykril

deleted a comment from on Aug 26, 2024
lnicola

lnicola commented on Aug 26, 2024

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lnicola@Veykril@wildework

        Issue actions

          Documentation is missing lines from code snippets · Issue #17966 · rust-lang/rust-analyzer