Skip to content

Range formatting doesn't appear to work #1125

@bombela

Description

@bombela

What's the output of :CocInfo

    3 vim version: NVIM v0.8.1
    4 node version: v18.12.1
    5 coc.nvim version: 0.0.82-b7375d5f 2023-01-30 05:09:03 +0800
    6 coc.nvim directory: /home/bombela/.config/nvim/plugged/coc.nvim
    7 term: xterm-256color
    8 platform: linux

What's the output of :CocCommand rust-analyzer.serverVersion

[coc.nvim] rust-analyzer 0.4.1442-standalone

What's your coc-rust-analyzer version? You can get it from :CocList extensions

coc-rust-analyzer 0.72.1

In my coc-config I also have:

    3   "rust-analyzer.updates.checkOnStartup": "false",
    4   "rust-analyzer.rustfmt.enableRangeFormatting": true,
    5   "rust-analyzer.updates.channel": "nightly",

And :echo CocHasProvider('formatRange') returns v:true.

(by the way, "rust-analyzer.rustfmt.enableRangeFormatting": true enables the feature but "rust-analyzer": { "rustfmt.enableRangeFormatting": true } does not. Took me 45minutes to realize that).

Then I do :set formatexpr=CocAction('formatSelected'). Now I expect gq on a visual selection to format similar to RustFmt. Instead it formats the same as the default vim behavior. :CoInfo reports nothing of interest besides Request action: formatSelected [].

As a baseline, I can compare with rustfmt nightly and :'<,'>RustFmtRange.

Just to make sure things are happening at all, I can :set formatexpr=CocAction('wontwork'), and in this case it silently doesn't format anything. And :CoInfo reports Request error: wontwork [] Error: Action "wontwork" not exist.

I can also :set formatexpr=CocAction('format'), which does indeed format the whole file like RustFmt, confirming again that something is really executed.

So it appears that CocAction('formatSelected') with coc-rust-analyzer somehow falls-back to the default neovim formatting. I am not sure how to debug the issue further.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions