Vscode-ruby: Setting a custom path for "ruby.format": "rubocop"

Created on 15 Dec 2018  路  6Comments  路  Source: rubyide/vscode-ruby

It looks like the rubocop for formatOnSave doesn't use the path from:

  "ruby.lint": {
    "rubocop": {
      "path": "/usr/local/bin"
    }
  },

(But the lint step does use /usr/local/bin/rubocop.)

How can I configure the path for "ruby.format": "rubocop"?

I've been working on this PR for rubocop-daemon, and have been trying to get my wrapper script to work with VS Code. The script starts a RuboCop server process as a daemon, and then sends commands via netcat. It's about 20x faster than running the plain rubocop command (150ms vs 4s), so I would really love to get this working!

My workaround for now is to just override the rubocop binary with a symlink to my wrapper script:

ln -fs /usr/local/bin/rubocop-daemon-wrapper /Users/ndbroadbent/.rvm/gems/ruby-2.5.3/bin/rubocop

But this is very brittle, and will probably break a lot in the future.

Also it would be great if I could rename the binary. Something like: "ruby.rubocop.binary": " /usr/local/bin/rubocop-daemon-wrapper"

Most helpful comment

Whoa, I just realized that vscode-ruby could directly integrate with rubocop-daemon via TCP connections, instead of needing to start a client process. This would make it even faster. I'm going to start working on this instead, and then I won't need the path option (but that would be nice too.)

I'll add a new rubocop-daemon option for ruby.format and ruby.lint, which will connect to the daemon via TCP, and it will start a new daemon server if it's not already running.

All 6 comments

Whoa, I just realized that vscode-ruby could directly integrate with rubocop-daemon via TCP connections, instead of needing to start a client process. This would make it even faster. I'm going to start working on this instead, and then I won't need the path option (but that would be nice too.)

I'll add a new rubocop-daemon option for ruby.format and ruby.lint, which will connect to the daemon via TCP, and it will start a new daemon server if it's not already running.

@ndbroadbent Moving over to VS Code from Atom where I was able to configure rubocop-daemon just fine, I'm very excited to try out your changes.

This will work when #405 lands. I've been explicitly testing absolute paths in the configuration (although I'd also love to add first-party support for a TCP connection).

405 has been merged which should help a lot with RuboCop configuration.

@ndbroadbent would you open a new issue related to getting rubocop-daemon integrated via a TCP connection? I think that's going to be some work

Hi @wingrunr21, sorry I didn't reply until now! I am just setting up rubocop-daemon-wrapper again, and I'm still struggling to set the path for rubocop. This is my settings.json:

  "ruby.lint": {
    "rubocop": {
      "path": "/usr/local/bin/rubocop-daemon-wrapper"
    }
  },
  "ruby.format": "rubocop"

(I'm trying to run the rubocop wrapper at /usr/local/bin/rubocop-daemon-wrapper/rubocop.)

Should this work, or do I need to change my settings?

@ndbroadbent How about following settins?

{
  "ruby.lint": {
    "rubocop": {
      "useBundler": true,
      "command": "/usr/local/bin/rubocop-daemon-wrapper/rubocop"
    }
  },
  "ruby.format": "rubocop"
}

I think this works well in linting.
But format with rubocop-daemon-wrapper does'nt(this is reported at #548 ).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

rachsmithcodes picture rachsmithcodes  路  5Comments

archfish picture archfish  路  5Comments

rebornix picture rebornix  路  3Comments

ecbrodie picture ecbrodie  路  5Comments