LSP-rust-analyzer icon indicating copy to clipboard operation
LSP-rust-analyzer copied to clipboard

Range formatting?

Open MrFoxPro opened this issue 10 months ago • 2 comments

Is it possible to enable lsp_format_document_range for rust-analyzer? I can't make it working with

{
    "settings": {
        "rust-analyzer.cargo.targetDir": true,
        "rust-analyzer.procMacro.enable": true,
        "rust-analyzer.cargo.buildScripts.rebuildOnSave": false,
        "rust-analyzer.rustfmt.rangeFormatting.enable": true,
        "rust-analyzer.rustfmt.overrideCommand": [
            "/usr/bin/rustfmt",
            "+nightly",
            "--edition=2024",
            "--unstable-features",
            "--emit=stdout",
            "--"
        ],
    },
    "command": [
        "/usr/lib/rustup/bin/rust-analyzer"
    ],
    "experimental_capabilities": {
        "documentRangeFormattingProvider": {
            "rangesSupport": true,
        },
    },
    "disabled_capabilities": {
        "diagnosticProvider": true,
    },
}

This feature works in VsCode using Format Selection command

MrFoxPro avatar Feb 20 '25 06:02 MrFoxPro

It looks like it also requires this:

    "initializationOptions": {
        "rustfmt.rangeFormatting.enable": true
    },

related issue: https://github.com/rust-lang/rust-analyzer/issues/17301

Once they support dynamic registration for range formatting then having it configured in settings would be enough.

BTW. That experimental_capabilities that you are setting doesn't seem to do anything.

rchl avatar Feb 26 '25 08:02 rchl

It looks like it also requires this:

    "initializationOptions": {
        "rustfmt.rangeFormatting.enable": true
    },

related issue: rust-lang/rust-analyzer#17301

Once they support dynamic registration for range formatting then having it configured in settings would be enough.

BTW. That experimental_capabilities that you are setting doesn't seem to do anything.

Nice! But now it formats whole document even with lsp_format_document_range command! 😅

MrFoxPro avatar Feb 26 '25 17:02 MrFoxPro