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

Setting a custom path for "ruby.format": "rubocop" #413

Closed
ndbroadbent opened this issue Dec 15, 2018 · 7 comments
Closed

Setting a custom path for "ruby.format": "rubocop" #413

ndbroadbent opened this issue Dec 15, 2018 · 7 comments

Comments

@ndbroadbent
Copy link

ndbroadbent commented Dec 15, 2018

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"

@ndbroadbent
Copy link
Author

ndbroadbent commented Dec 17, 2018

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.

@nomoon
Copy link

nomoon commented Jan 3, 2019

@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.

@wingrunr21
Copy link
Collaborator

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).

@wingrunr21
Copy link
Collaborator

#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

@ndbroadbent
Copy link
Author

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?

@sisisin
Copy link

sisisin commented Jul 5, 2020

@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 ).

@NuckChorris
Copy link

It would appear this is an issue again due to the Ruby Language Server move @wingrunr21 :(

vscode-ruby-client uses the linter configs in the formatter, and allows ruby.lint.rubocop.exe to override the executable, but the Ruby Language Server no longer does this, and it's unclear if it even could (since the config is passed in, rather than retrieved)

It seems like there's a FormatterConfig interface in the language server, is that connected to the VS Code config? I could send a PR implementing the same command option as the linter has if it's configurable

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

5 participants