Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring custom rspec command in VS Code #57

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

westonkd
Copy link

@westonkd westonkd commented Jan 6, 2025

ruby-lsp already does a good job of inferring the base rspec command to run based on the presence of a Gemfile or binstup.

This pull request allows further customization of the rspec command using the addonSettings VS Code configuration exposed by ruby-lsp

Check out the modifications to README.md for descriptions of the two newly-added configuration options (rspecCommand and useRelativePaths).

These two new options can be used in conjunction to solve issues like those described in #27 (using ruby-lsp-rspec with docker):

.vscode/settings.json

{
  "rubyLsp.addonSettings": {
    "Ruby LSP RSpec": {
      "rspecCommand": "docker compose exec app rspec",
      "useRelativePaths": true
    }
  }
}

@westonkd westonkd mentioned this pull request Jan 6, 2025
@carlqt
Copy link

carlqt commented Jan 7, 2025

I was just thinking of contributing this same feature. Thanks!

Hope this get merges soon 🙏

@westonkd
Copy link
Author

@st0012 Any thoughts on this feature or implementation? Thanks!

@westonkd
Copy link
Author

I just hit another use case where the combination of the two settings I added here are not quite sufficient to get things working (Docker + a monorepo-style setup).

When I get time I'll push a change making the settings interface slightly more flexible than what I've added here.

@st0012
Copy link
Owner

st0012 commented Jan 25, 2025

Hi sorry for the delay. I understand the need of custom RSpec commands, but what's the problem useRelativePaths is going to solve?

From my experience, if the test files need to be run with a relative path, it usually indicates that the project should properly utilize VS Code's multi-root workspaces feature.

westonkd and others added 2 commits January 25, 2025 16:15
This commit adds an option (consumed from VS Code settings) that
allows a debug mode to troubleshoot configuration issues.

Further, this commit clarifies the preferred approach for using
this addon with Dev Containers.

Projects that use Docker or other container technologies for development
should use a the VS Code Dev Containers extension to run Ruby LSP _within_
the dev Container.

This prevents situations where the spec paths provided to rspec are
host machine paths rather than container paths.
@westonkd
Copy link
Author

👋 Hey! No problem for the delay, thanks for taking a look.

but what's the problem useRelativePaths is going to solve?
I was working in a development environment that:

  • Used Docker containers to run the application in development
  • Ran rspec within those same containers
  • Ran VS Code extensions (like Ruby LSP) on the host machine, not within the container

With that setup, the spec file path was an absolute path pointing to the file on the host machine, not the path within the container.

One way to fix that was to add support for a relative path so the spec path was correct, even if it was generated on the host machine but used in a container.

I've thought more about that and don't think it's the right solution. Instead, using a Dev Container and running Ruby LSP extension in that container yields the correct spec paths without the need for an additional setting.

I've updated this pull request to add a bit of documentation to those who might be wondering how do do this in #27 .

I've additionally added a debug option to print the rspec commands generated for each code lense since it was helpful for me to troubleshoot my configuration and contribute. I'm fine leaving this bit out though if it does not feel generally helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants