Skip to content

Allow customizable test runner commands for CodeLensΒ #3586

@Masaokb

Description

@Masaokb

I have checked that this feature is not already implemented:

  • This feature does not exist

Use case:
Many development teams use containerized environments or custom test runners for their Ruby projects. Currently, Ruby LSP's CodeLens feature hardcodes the test command to bundle exec ruby or ruby.

For example, projects using:

  • dip rspec for Docker Integration Platform
  • docker-compose exec app rspec for Docker Compose setups
  • bin/rspec for custom binstubs
  • Other containerized test runners

These teams cannot benefit from the CodeLens test execution feature.

Description:
I propose adding a configuration option that allows users to customize the test command prefix used by CodeLens when executing tests. This would enable the Ruby LSP to generate appropriate test commands for any development environment.

The feature should allow users to specify their preferred test runner command through VS Code settings or Ruby LSP initialization options. When a user clicks on a CodeLens test button, the Ruby LSP would use the custom command instead of the default bundle exec ruby.

For example, if a user configures "rubyLsp.testCommand": "dip rspec", clicking on a test's CodeLens should execute dip rspec /path/to/spec_file.rb --name "TestName" instead of the current bundle exec ruby -Ispec /path/to/spec_file.rb --name "TestName".

Implementation:
The implementation could involve:

  1. Configuration Option: Add a new setting like testCommand to the Ruby LSP's configuration options, accessible through VS Code settings or initialization options.

  2. GlobalState Enhancement: Extend the GlobalState class to store and manage the custom test command configuration.

  3. CodeLens Modification: Update the BASE_COMMAND logic in lib/ruby_lsp/listeners/code_lens.rb to use the configured command instead of the hardcoded bundle exec ruby or ruby.

  4. Command Generation: Modify the generate_test_command method to properly construct commands using the custom prefix while maintaining compatibility with different test frameworks (minitest, test-unit, rspec).

  5. Framework Detection: Ensure the custom command works with the existing test library detection logic, possibly adjusting the command structure based on the detected framework.

The change should be backward compatible, defaulting to the current behavior when no custom command is specified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions