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

Add option to specify formatter command #548

Open
rightpad opened this issue Oct 16, 2019 · 5 comments
Open

Add option to specify formatter command #548

rightpad opened this issue Oct 16, 2019 · 5 comments
Assignees
Labels
feature-request Adds currently unsupported functionality

Comments

@rightpad
Copy link

Your environment

  • vscode-ruby version: 0.25.3
  • Ruby version: 2.6.5
  • Ruby version manager (if any): RVM
  • VS Code version: 1.39.2
  • Operating System: Ubuntu 18.04 via Remote:SSH extension on Win10
  • Using language server? (eg useLanguageServer is true?) Yes

Expected behavior

I have a rails project setup with rubocop as the linter & formatter, and the spring-commands-rubocop gem to try and speed things up. The linter portion of the extension for this setup works great, but there's no option to use the formatter with it. It'd be nice to have the same options for running formatters that there is for linters so this way I can specify my spring binstub for the rubocop formatter. Here's an example config of what I'd like:

{
  "ruby.lint": {
    "rubocop": {
      "command": "bin/rubocop"
    }
  },
  "ruby.format": {
    "rubocop": {
      "command": "bin/rubocp"
    }
  }
}

And what the output of "Ruby Language Server" would show:

Lint: executing bin/rubocop -s /path/to/project/app/controllers/sessions_controller.rb -f json...
Running via Spring preloader in process XXXXX
Format: executing bin/rubocop -s /path/to/project/app/controllers/sessions_controller.rb -a...
Running via Spring preloader in process XXXXX

Actual behavior

The current behavior doesn't allow selecting a command path for the formatter, instead only supporting a toggle of running through bundle exec. This doesn't allow for formatters to be ran through spring, which could potentially save time on formatter execution.

Current config:

{
  "ruby.lint": {
    "rubocop": {
      "command": "bin/rubocop"
    }
  },
  "ruby.format": "rubocop",
  "ruby.useBundler": true
}

Current output:

Lint: executing bin/rubocop -s /path/to/project/app/controllers/sessions_controller.rb -f json...
Running via Spring preloader in process 27599
Format: executing bundle exec rubocop -s /path/to/project/app/controllers/sessions_controller.rb -a...
@wingrunr21 wingrunr21 self-assigned this Oct 19, 2019
@wingrunr21 wingrunr21 added the feature-request Adds currently unsupported functionality label Oct 19, 2019
@mill1000
Copy link

Would like to see this as well. Perhaps just an option for rubocop path which the linter and formatter can use.

@Overload119
Copy link

I would also like this.
I think the change just has to happen here.

const command = 'rubocop';

@MikeMcQuaid
Copy link

Also interested. Assuming you're using the language server the relevant code difference is:

function getLinter(
name: string,
document: TextDocument,
env: RubyEnvironment,
config: RubyConfiguration
): ILinter {
if (!config.workspaceFolderUri) {
return new NullLinter(
`unable to lint ${document.uri} with ${name} as its workspace root folder could not be determined`
);
}
const linter = LINTER_MAP[name];
if (!linter) return new NullLinter(`attempted to lint with unsupported linter: ${name}`);
const lintConfig: RubyCommandConfiguration =
typeof config.lint[name] === 'object' ? config.lint[name] : {};
const linterConfig: LinterConfig = {
env,
executionRoot: URI.parse(config.workspaceFolderUri).fsPath,
config: lintConfig,
};
return new linter(document, linterConfig); // eslint-disable-line new-cap
}

vs.

function getFormatter(
document: TextDocument,
env: RubyEnvironment,
config: RubyConfiguration,
range?: Range
): IFormatter {
// Only format if we have a formatter to use and an execution root
if (typeof config.format === 'string' && config.workspaceFolderUri) {
const formatterConfig: FormatterConfig = {
env,
executionRoot: URI.parse(config.workspaceFolderUri).fsPath,
config: {
command: config.format,
useBundler: config.useBundler,
},
};
if (range) {
formatterConfig.range = range;
}
return new FORMATTER_MAP[config.format](document, formatterConfig);
} else {
return new NullFormatter();
}
}

@gstokkink
Copy link

@wingrunr21 hi, just wondering if this is something you'd like to implement in the future? :) Could really help with rubocop-daemon integration.

@fiveNinePlusR
Copy link

What are the issues that prevent rubocop from being fed a different or custom path for linting vs. formatting?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Adds currently unsupported functionality
Projects
None yet
Development

No branches or pull requests

7 participants