-
Notifications
You must be signed in to change notification settings - Fork 10
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
Disable ruby-lsp-rspec's definition listener outside test files #46
Conversation
@@ -42,6 +42,7 @@ def on_call_node_enter(node) | |||
entries.each do |entry| | |||
# Technically, let can be defined in a different file, but we're not going to handle that case yet | |||
next unless entry.file_path == @uri.to_standardized_path | |||
next unless entry.file_path.end_with?('spec.rb') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks tests that use tempfiles, do you know how can I make tempfiles use spec.rb
files? Or do you know any other way to check it's an rspec. I have seen used node.receiver && node.receiver&.slice != "RSpec"
but it doesn't work always.
I roughly understand the issue but it can not be caused by the listener you're trying to patch because it only returns definitions that are also from the same file (condition). |
Thank you for replying so quickly!
Yes, so both core and LSP rspec return definitions
That doesn't exist at all, this happens with every definition of every file (not if the definition is in another file). Also, how can you explain that if I remove my new check, the test returns 2 definitions instead of 1? I'm curious about your setup, since I cannot get working this addon without including in the gemfile. |
It took me a while to find a reproduceable case in my projects but I can confirm that it is the listener's fault 👍 diff --git a/lib/ruby_lsp/ruby_lsp_rspec/addon.rb b/lib/ruby_lsp/ruby_lsp_rspec/addon.rb
index 98d13ff..3cde027 100644
--- a/lib/ruby_lsp/ruby_lsp_rspec/addon.rb
+++ b/lib/ruby_lsp/ruby_lsp_rspec/addon.rb
@@ -64,6 +64,8 @@ module RubyLsp
).void
end
def create_definition_listener(response_builder, uri, node_context, dispatcher)
+ return unless uri.to_standardized_path&.end_with?("_test.rb") || uri.to_standardized_path&.end_with?("_spec.rb")
+
Definition.new(response_builder, uri, node_context, T.must(@index), dispatcher)
end |
Nice! Thank you, it's because I don't know much how the LSP addon system works. This solution has the same issue with specs than mine, any ideas? |
On my side the test failed without the change and passed when the above diff is applied. Can you first push the lib code and we can see what's failing on CI? |
3f8d870
to
ed0b97c
Compare
Ah ok I get what you mean now. It's other tests that are failing. You can do this to create tempfiles that end with specific postfix: |
ed0b97c
to
e13e5c8
Compare
Nice! Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for reporting the issue and the PR 😄
I've cut a release for this: https://github.com/st0012/ruby-lsp-rspec/releases/tag/v0.1.17 |
That was really fast, thank to you for the help! |
Here is what happens when I add the addon