st0012 / ruby-lsp-rspec

A Ruby LSP addon for RSpec tests
MIT License
127 stars 7 forks source link

is the command that code lens executes configurable? #4

Open jedschneider opened 1 year ago

jedschneider commented 1 year ago

I'm trying to figure out if I can provide some arguments or change the load path of the rspec command that is run from the code lens annotations.

Details:

I have a project structured like this: a top level Gemfile and a binstub for rspec, I have multiple rails apps under an engines folder.

├── Gemfile
├── Gemfile.lock
├── bin
│   ├── rspec
├── engines
│   ├── broker_suite
│   │   ├── app
│   │   ├── lib
│   │   ├── spec

I have the code lens annotations showing up in my editor.

image

If i have the terminal open and have the broker_suite rails app set as the current working directory, the run in terminal code lens command works great.

If I try to use the run command, I get the following:

An error occurred while loading ./engines/broker_suite/spec/integration/mutation/attach_files_spec.rb.

Failure/Error: require "rails_helper"

LoadError:

  cannot load such file -- rails_helper

# ./engines/broker_suite/spec/integration/mutation/attach_files_spec.rb:1:in `<top (required)>'

Run options: include {:locations=>{"./engines/broker_suite/spec/integration/mutation/attach_files_spec.rb"=>[53]}}

All examples were filtered out

Finished in 0.00003 seconds (files took 0.10815 seconds to load)

0 examples, 0 failures, 1 error occurred outside of examples

I can run the following successfully from my terminal from the top level of the project:

% bin/rspec -Iengines/broker_suite/spec -rrails_helper engines/broker_suite/spec/integration/mutation/attach_files_spec.rb
...

Finished in 0.38453 seconds (files took 3.7 seconds to load)
3 examples, 0 failures

and I have a launch config that can do the same:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type":"ruby_lsp",
      "name":"lsp run",
      "program": "rspec -Iengines/broker_suite/spec -rrails_helper ${file}",
      "request": "launch",
    },
  ]
}

Is there a way for me to be able to specify the load path and require statements in order to mimic what I can do on the terminal? I see there is a reference to rubyLsp.runTest and I assume there might be some translation to a launch command, but I can't seem to configure it in such a way to get it to trigger. Thanks for the thoughts!