Vscode-ruby: Selection formatting broken with rubocop and standardrb

Created on 21 Feb 2019  路  11Comments  路  Source: rubyide/vscode-ruby

Your environment

  • vscode-ruby version: 0.22.0
  • Ruby version: 2.4.1
  • Ruby version manager (if any): chruby
  • VS Code version: 1.31.1
  • Operating System: macOS Mojave
  • Using language server? yes

Expected behavior

When I select one or more lines in a file and execute "Format Selection" command, it should use the configured tool (rubocop or standardrb) to format selected part of the file.

FWIW - rufo does work and "Format Document" command works fine too, regardless of the formatting tool.

Actual behavior

Getting exceptions in the console like this:

rubocop:

[Error - 11:50:39 AM] Request textDocument/rangeFormatting failed.
  Message: Request textDocument/rangeFormatting failed with message: 
    unable to execute rubocop -s /absolute/path/to/the/file.rb -a:
    Error: Failed with exit code: 1 - unknown error
  Code: -32603 

standardb:

Format: executing standardrb -s  /absolute/path/to/the/file.rb --fix...
[Error - 11:52:44 AM] Request textDocument/rangeFormatting failed.
  Message: Request textDocument/rangeFormatting failed with message: 
    unable to execute standardrb -s /absolute/path/to/the/file.rb --fix:
    Error: Failed with exit code: 1 - unknown error
bug

Most helpful comment

ok great. This is definitely a bug. I'll get it fixed!

All 11 comments

How are those installed? Globally? Does that exact command work in a console?

Globally, not part of the Gemfile. Notice that rufo works fine, it's installed globally as well. When I run the command in the console nothing happens. I'm not sure if using -s option is correct, it's for reading from STDIN but we're passing a path to a file.

-s is correct

Looks like the 1 exit code is what's causing that. I must have broken that when doing the error handling. If you fix all the errors in a file does the formatting work?

If you fix all the errors in a file does the formatting work?

Yes!

ok great. This is definitely a bug. I'll get it fixed!

v0.22.2 should fix this

I'm on 0.22.2 and I still get an error about no selection formatter being defined. Am I missing a configuration option?

@bjeanes it only works with the language server enabled

Turning that on gets rid of the error message, but instead it just doesn't indent, silently. :|

I can confirm that it doesn't format, both rubocop and standard. Nothing happens, no errors in the output.

Can you post screenshots of your highlighting, logs, and config?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atracy picture atracy  路  3Comments

rebornix picture rebornix  路  3Comments

webmastak picture webmastak  路  4Comments

abraham picture abraham  路  4Comments

ghost picture ghost  路  4Comments