With the SolarGraph extension enabled and the following two VsCode settings enabled:
{
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
}
Close and re-open VsCode and open a new editor window to an existing Ruby file.
The files.insertFinalNewline does not work anymore.
I tried flipping all the Solargraph settings to see if I can get this to go away but I can't.
This doesn't appear to be specific to Solargraph. If there's any other formatting provider available, the files.insertFinalNewline configuration gets ignored.
In my tests, it happens when RuboCop formatting is enabled with either the vscode-ruby extension ("ruby.format": "rubocop") or vscode-solargraph ("solargraph.formatting": true). If both are disabled, insertFinalNewline works as expected.
Thanks for clarifying @castwide. One workaround would be to have Solargraph insert a final newline and trim excess newlines upon save. Any idea how to do that?
Prettier appears not to interfere with "files.insertFinalNewline": true or "files.trimFinalNewlines": true because it ships with both of those as sensible defaults.
I may have found the problem. The default setting for editor.formatOnSaveTimeout is 750, and RuboCop formatting takes too long to complete. An error gets emitted to the developer console when the format gets aborted.
Solargraph formatting with insertFinalNewline worked for me with the following workspace settings:
"solargraph.formatting": true,
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 3000,
"files.insertFinalNewline": true
The settings I suggested should resolve this problem. If not, please open a new issue.
I just had the same issue, this setting works for me. Thanks.
Most helpful comment
I may have found the problem. The default setting for
editor.formatOnSaveTimeoutis 750, and RuboCop formatting takes too long to complete. An error gets emitted to the developer console when the format gets aborted.Solargraph formatting with insertFinalNewline worked for me with the following workspace settings: