solargraph
solargraph copied to clipboard
Support for RSpec `let` definitions
Hey folks,
Is there any way to get the go-to-definition feature working with variables bound RSpec's let
construct?
Suppose I have:
let(:endpoint) { MyAPI::Path::To::Endpoint }
let(:response) {endpoint.get(params)
If I click get
and go-to-definition, it says no definition found. But, if instead I have:
endpoint = MyAPI::Path::To::Endpoint
response = endpoint.get(params)
Then go-to-definition will work just fine. Thoughts?
Variables defined in RSpec's let
construct aren't accessible to the code maps. Those kinds of DSL-specific conventions usually require special handling.
There's a Convention
feature in Solargraph that's intended to help fill some of those gaps. The current RSpec convention, for example, is able to map RSpec methods like expect
and eq
if you're editing a *_spec.rb
file. It might be possible to extend the convention to support let
as well, but it's a little more complicated than simply exposing methods.
Is using a 'convention' a matter of configuration, then? If so, where can I learn more?
The current RSpec convention: https://github.com/castwide/solargraph/blob/master/lib/solargraph/convention/rspec.rb
Conventions are undergoing an upgrade for version 0.40.0, which I expect to release in June. The API will change slightly and it will be possible to add custom conventions through plugins. When it's ready, I'll also release a solargraph-rails
plugin that will utilize the new convention features. I'm working on more documentation.
@castwide is this covered in the latest versions of SG now? I'm trying to set up my existing project with the solargraph-rails plugin and finding that I need more work to support the rspec/rake DSLs. As you have advised in other threads, I'm not setting a global domain for all my files, but I would like to know what kind of domains I might need to use to get my expects, lets and describes working properly
# @!domain RSpec::Matchers
# @!parse extend RSpec::Core
# @!parse extend RSpec::Core::MemoizedHelpers
Using:
---
include:
- "**/*.rb"
exclude:
- "spec/**/*.rb"
- spec/**/*
- test/**/*
- vendor/**/*
- ".bundle/**/*"
require:
- actioncable
- actionmailbox
- actionmailer
- actionpack
- actiontext
- actionview
- activejob
- activemodel
- activerecord
- activestorage
- activesupport
- administrate
- aws-sdk-core
- bullet
- devise
- factory_bot
- factory_bot_rails
- graphiti
- graphiti-rails
- rails
- rspec
- rspec-core
- rspec-expectations
- rspec-mocks
- rspec-rails
- rspec-snapshot
- rspec-support
domains: []
reporters:
- rubocop
- require_not_found
- typecheck:strict
formatter:
rubocop:
cops: safe
except: []
only: []
extra_args: []
require_paths: []
plugins:
- solargraph-rails
max_files: 5000
Any progress on this?