CocAction('format') using 2 spaces instead of 4
bugeats opened this issue · comments
When I run :call CocAction('format')
(and when it's called automatically on save via coc.preferences.formatOnSaveFiletypes
), the buffer is formatted with 2 spaces instead of the default 4.
When I run rustfmt
on the file directly, the correct 4 spaces are used.
No rustfmt.toml
is in my project.
My indent related settings are set like so:
autocmd FileType rust setlocal ts=4 sw=4 expandtab equalprg=rustfmt
coc-rls 1.1.6
NVIM v0.5.0-532-g2ca8f02a6
rustfmt 1.4.14-nightly
Should be problem of your language server, checkout https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel
I see this in the verbose output:
[Trace - 10:00:09 AM] Sending request 'textDocument/formatting - (6)'.
Params: {
"textDocument": {
"uri": "file:///<redacted>/src/lib.rs"
},
"options": {
"tabSize": 2,
"insertSpaces": true
}
}
Where are those options being set?
Oh, after checking :set ts?
I see it's set to tabstop=2
. A clue emerges... Somebody somewhere is overriding my tabstop settings.
It was my editorconfig/editorconfig-vim causing the tabstop override. Unexpected.
Thanks for your help.
I have similar issue here, but I get weird result.
I have no idea about what I did wrong. All of the tab settings are 4.
tabstop=4
softtabstop=4
shiftwidth=4
noexpandtab
my request format block is like this. (line 17 to line 29)
class hole {
public:
int x;
int y;
hole *link;
hole() : x(0), y(0), link(nullptr) {}
friend ostream &operator<<(ostream &out, const hole &h) {
out << "(" << h.x << "," << h.y << ")";
return out;
}
};
And I've checked the LSP server log as below.
[Trace - 7:31:06 PM] Sending request 'textDocument/rangeFormatting - (11)'.
Params: {
"textDocument": {
"uri": "</path/to/located/dir>/wormhole.cpp"
},
"range": {
"start": {
"line": 16,
"character": 0
},
"end": {
"line": 28,
"character": 2
}
},
"options": {
"tabSize": 4, <======
"insertSpaces": false <======
}
}
And the log of result is like this
[Trace - 7:31:06 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"version": 24,
"uri": "</path/to/located/dir>/wormhole.cpp"
},
"contentChanges": [
{
"range": {
"start": {
"line": 17,
"character": 0
},
"end": {
"line": 27,
"character": 1
}
},
"rangeLength": 191,
"text": "public:\n int x;\n int y;\n hole *link;\n\n hole() : x(0), y(0), link(nullptr) {}\n\n friend ostream &operator<<(ostream &out, const hole &h) {\n out << \"(\" << h.x << \",\" << h.y << \")\";\n return out;\n "
^--------- insert two spaces at beginning??
}
]
}
The output change is like this.
class hole {
public:
int x;
int y;
hole *link;
hole() : x(0), y(0), link(nullptr) {}
friend ostream &operator<<(ostream &out, const hole &h) {
out << "(" << h.x << "," << h.y << ")";
return out;
}
};
If I did build-in format command, like '=', the result would be normal.
class hole {
public:
int x;
int y;
hole *link;
hole() : x(0), y(0), link(nullptr) {}
friend ostream &operator<<(ostream &out, const hole &h) {
out << "(" << h.x << "," << h.y << ")";
return out;
}
};
Should be problem of your language server, checkout https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel
Bug of your rls
Bug of your rls
Thanks a lot! I've spent lots of time in this problem.