rust-lang / rust-lang/rust-analyzer

Better ergonomics when pasting within code blocks in doc comments.

Open
#11,721 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I'm in the situation where I want to paste a multi-line bit of code here:
image

let (even, odd_map): (Vec<i32>, HashMap<i32, f32>) =
    a.iter()
        .partition_mapped(|&n| n % 2 == 0, |n| n, |&n| (n, (n * 10) as f32));

but when I do, only the first line stays as a doc comment, the rest end up pasted "outside":
image
What I'm proposing is that I should've ended up with this instead:

/// let (even, odd_map): (Vec<i32>, HashMap<i32, f32>) =
///     a.iter()
///         .partition_mapped(|&n| n % 2 == 0, |n| n, |&n| (n, (n * 10) as f32));

I don't know if this is within the purview of rust-analyzer or not, but I thought I'd bring it up, since it's a very frustrating behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the multiline paste behavior in a Rust doc comment using the example from the issue. First determine whether rust-analyzer owns this editor behavior or whether it belongs to the editor, then identify the relevant paste-handling entry point and add coverage for prefixing each pasted line with /// when done.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.