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 for RSpec let definitions #325

Closed
clmay opened this issue May 15, 2020 · 7 comments
Closed

Support for RSpec let definitions #325

clmay opened this issue May 15, 2020 · 7 comments

Comments

@clmay
Copy link

clmay commented May 15, 2020

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?

@castwide
Copy link
Owner

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.

@clmay
Copy link
Author

clmay commented May 26, 2020

Is using a 'convention' a matter of configuration, then? If so, where can I learn more?

@castwide
Copy link
Owner

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.

@chozandrias76
Copy link

chozandrias76 commented Feb 1, 2022

@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

@liarokapisv
Copy link

Any progress on this?

@lekemula
Copy link

lekemula commented May 12, 2024

@clmay @liarokapisv Please see: #683 (comment).

Right now does not support the return type inference of let methods but hope we'll get there soon!

Looking forward to your feedback!

@clmay
Copy link
Author

clmay commented May 12, 2024

That's great news, thank you for following up @lekemula !

@clmay clmay closed this as completed May 12, 2024
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

No branches or pull requests

5 participants