Skip to content

Allow customizable test runner commands for CodeLens #3586

Closed as not planned
Closed as not planned

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.

Activity

  1. Splines commented on Jun 15, 2025

    @Splines

    Related: #2965. Also note that the Ruby LSP addon ruby-lsp-rspec provides an rspecCommand option, e.g.:

    {
      "rubyLsp.addonSettings": {
        "Ruby LSP RSpec": {
          "rspecCommand": "rspec -f d"
        }
      }
    }

    For Docker users, see this PR: #2919 and this gist.

  2. github-actions commented on Aug 15, 2025

    @github-actions
    Contributor

    This issue is being marked as stale because there was no activity in the last 2 months

  3. vinistock commented on Sep 5, 2025

    @vinistock
    Member

    Container related discussions were happening in a few different places, so I created #3738 to try to centralize and move the discussion forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions