Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Using standardrb as formatter does not work #518

Closed
pcriv opened this issue Aug 16, 2019 · 27 comments
Closed

Using standardrb as formatter does not work #518

pcriv opened this issue Aug 16, 2019 · 27 comments

Comments

@pcriv
Copy link

pcriv commented Aug 16, 2019

Your environment

  • vscode-ruby version:
  • Ruby version: 2.3.8
  • Ruby version manager (if any): adsf
  • VS Code version: 1.37.1
  • Operating System: macOS Mojave 10.14.6
  • Using language server? true

Expected behavior

The file gets formatted using standardrb --fix

Actual behavior

The whole content of the file it's replaced by:

andardrb. Perhaps you have to reshim?
@wingrunr21
Copy link
Collaborator

Please post any logs and verify that you can run standardrb via the same command that gets printed out via the language server logs

@pcriv
Copy link
Author

pcriv commented Aug 17, 2019

@wingrunr21 I don't see anything on the logs when I run the command

@wingrunr21
Copy link
Collaborator

If you are using the language server it is logging something. The logs are available by clicking the x ! icons in the lower left of the editor, choosing the Output tab, and then choosing Ruby Language Server from the dropdown near the right side of the panel.

Without additional information there isn't a whole lot I can do to help here.

@pcriv
Copy link
Author

pcriv commented Aug 18, 2019

Oh yeah thanks for the guidance, I missed that I had to select the Ruby Language Server from the dropdown

Format: executing standardrb -s /Users/username/example.rb --fix...

When I try to run that on my terminal It just gets stuck

@wingrunr21
Copy link
Collaborator

No problem. I'm including some additional documentation and helpers in the next release to make this easier on folks.

Ok and is standard installed globally or via bundler? I added some documentation this morning on how to verify commands and their functionality.

I'm trying to ascertain if this is a configuration issue or if the language server isn't correctly pulling out the asdf environment.

@pcriv
Copy link
Author

pcriv commented Aug 19, 2019

I tried both with and without bundler and got the same issue.

@pcriv
Copy link
Author

pcriv commented Aug 19, 2019

[Info  - 11:34:43 PM] Initializing Ruby language server...
[Info  - 11:34:43 PM] Rebuilding tree-sitter for local Electron version
[Info  - 11:34:43 PM] Rebuild succeeded!
Format: executing standardrb -s /Users/username/Workspace/example.rb --fix...
Format: executing bundle exec standardrb -s /Users/username/Workspace/example.rb --fix...

@pcriv
Copy link
Author

pcriv commented Sep 2, 2019

I just updated to the last the version of vscode-ruby and tried to use stardard formatter again.
This are the logs I get now:

With bundler setting enabled:

[Info  - 8:36:53 AM] Initializing Ruby language server...
Loading Ruby tree-sitter syntax from /Users/username/.vscode/extensions/rebornix.ruby-0.25.0/dist/server/tree-sitter-ruby.wasm
Format: executing bundle exec standardrb -s /Users/username/Workspace/app/lib/adyen/extension.rb --fix...
[Error - 8:36:57 AM] Request textDocument/formatting failed.
  Message: Request textDocument/formatting failed with message: 
    unable to execute bundle exec standardrb -s /Users/username/Workspace/app/lib/adyen/extension.rb --fix:
    Error: spawn bundle ENOENT - command not found
  Code: -32603 

Disabled:

Format: executing standardrb -s /Users/username/Workspace/app/lib/adyen/extension.rb --fix...
[Error - 8:40:16 AM] Request textDocument/formatting failed.
  Message: Request textDocument/formatting failed with message: 
    unable to execute standardrb -s /Users/username/Workspace/app/lib/adyen/extension.rb --fix:
    Error: spawn standardrb ENOENT - command not found
  Code: -32603 

@wingrunr21
Copy link
Collaborator

How do you have standard installed? If you execute it on the command line what command works for you?

@pcriv
Copy link
Author

pcriv commented Sep 2, 2019

I tried installing it via Gemfile and globally using gem install standard

@wingrunr21
Copy link
Collaborator

If you cd to your project directory (in your terminal) and run standard, what command works?

@pcriv
Copy link
Author

pcriv commented Sep 3, 2019

Either of these work:

bundle exec standardrb --fix file.rb
standardrb --fix file.rb

@pcriv
Copy link
Author

pcriv commented Sep 3, 2019

Okay I think I understand the issue now:

standardrb does not seem to support the -s flag like rubocop does

    -s, --stdin FILE                 Pipe source from STDIN, using FILE in offense

These are the supported options:

$ standardrb --help                                                                                                                                                            
Usage: standardrb [--fix] [-vh] [--format <name>] [--] [FILE]...

Options:

  --fix             Automatically fix failures where possible
  --no-fix          Do not automatically fix failures
  --format <name>   Format output with any RuboCop formatter (e.g. "json")
  -v, --version     Print the version of Standard
  -h, --help        Print this message
  FILE              Files to lint [default: ./]

@wingrunr21
Copy link
Collaborator

@pcriv
Copy link
Author

pcriv commented Sep 3, 2019

When I try to run it like that it just gets stuck

Edit: I was using the command the wrong way, but still, the standardrb binary works when I cd to my project.

Sorry for the confusion 😬

@wingrunr21
Copy link
Collaborator

Ok, so something with asdf is not being pulled in properly and the server cannot find standardrb in the PATH.

@pcriv
Copy link
Author

pcriv commented Sep 4, 2019

Is there anything else I could do to help you with this issue?

@wingrunr21
Copy link
Collaborator

Well, it's pretty obvious something is missing from the environment. If it can't find bundle or standard that most likely means your GEM_PATH is not set. I don't use asdf so I'm not sure how that is set. Can you give more details on your setup? What shell do you use? Is it the same as your system shell?

@pcriv
Copy link
Author

pcriv commented Sep 5, 2019

I'm using fish shell

@wingrunr21
Copy link
Collaborator

ahhhhhh:

#523

@pcriv
Copy link
Author

pcriv commented Sep 5, 2019

oooooooh 😅 feel free to close this in favor of that issue then :)

@wingrunr21
Copy link
Collaborator

ok great thanks. That's next on my list to work on so I should hopefully fix this for you soon! Sorry about that!

@pcriv
Copy link
Author

pcriv commented Sep 5, 2019

Awesome! Thank you! :)

@wingrunr21
Copy link
Collaborator

Fish shell support for the environment detection landed in v0.26.0. Please give it a try!

@obahareth
Copy link

This is still not working for me.

I even tried setting it manually:

❯ which standardrb
/Users/obahareth/.asdf/shims/standardrb
"ruby.lint": {
  "standard": {
    "command": "/Users/obahareth/.asdf/shims/standardrb",
    "useBundler": false
  }
}

I still get this message:

unable to execute standardrb -s '/Users/obahareth/path/to/file.rb' --fix:
    Error: spawn standardrb ENOENT - command not found
  Code: -32603 
SIGPIPE received

@obahareth
Copy link

@wingrunr21 I am not sure if I should make a new issue or if we should reopen this one?

Am I doing something wrong with my configuration?

@obahareth
Copy link

obahareth commented Aug 4, 2022

The only thing that worked for me is to run it from the terminal, providing the full path to the shim only works when I run it from the terminal.

It seems like this is the same issue as #816

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants