rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.09k stars 1.57k forks source link

Extend selection behaves differently between single- and multi-line statements #7452

Open YaLTeR opened 3 years ago

YaLTeR commented 3 years ago

Say I have code like this:

mod gl {}

fn main() {
    let gl = ();

    gl.GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut previous_framebuffer);
    gl.BindFramebuffer(gl::DRAW_FRAMEBUFFER, self.framebuffer);
    gl.FramebufferTexture2D(
        gl::DRAW_FRAMEBUFFER,
        gl::COLOR_ATTACHMENT0,
        gl::TEXTURE_2D,
        self.texture,
        0,
    );
}

I'd like to wrap all calls in some other call. I set up multiple cursors like so:

image

Then I hit extend selection:

image

Note how single-line statements got fully selected up to ;, but the multi-line one didn't. In fact, it requires one more extend selection:

image

But now the single-line statements have ; selected, too. All this means I have to first deal with single-line statements, and then, separately, with multi-line statements. It would be nice if the behavior was unified.

lnicola commented 3 years ago

Hmm, why don't I have this Extend selection command?

image

image

bjorn3 commented 3 years ago

Try alt+shift+left/right arrow.

lnicola commented 3 years ago

Oh, that's my cursorColumnSelectRight. Do you know why it doesn't show up in the command list?

Veykril commented 3 years ago

I think its not a rust-analyzer only command, but a generic one? image

matklad commented 3 years ago

but the multi-line one didn't.

I believe this is sadly vs-codes build-in extend selection logic kicking in :( They produce a union of semantic selections from server and naive selections from the editor. would be good to prepare a minimal repro here, and open an issuer at the vscode repo.

Veykril commented 3 years ago

Interestingly enough, I wrote a small test for this and this is the output that passes.


    #[test]
    fn extend_selection_call_multiline() {
        do_check(
            r#"
fn main() {
    f$0.call(

    );
}"#,
            &["f", "f.call(\n        \n    )", "f.call(\n        \n    );"],
        );
    }

But if I expand cursor through vscode multiple times myself for the given snippet I get this additional f.call( selection after the f selection 🤔

Veykril commented 3 years ago

Ah that would explain it if vscode does some stuff as well 😕

lnicola commented 3 years ago

Filed #7454 for the feature name.

tadeokondrak commented 1 year ago

I think setting the VSCode option editor.smartSelect.selectLeadingAndTrailingWhitespace to false fixes this.

Veykril commented 1 year ago

That indeed fixes it. At this point we should keep a list of VSCode settings that cause issues with user experience 😅

flodiebold commented 1 year ago

We could at least note it in the manual section for the feature.