From 18727da048ff259b85114596c9a44317b58224a4 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 16 Jan 2024 15:06:22 +0000 Subject: [PATCH] Ignore context and describe calls without arguments (#18) --- lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb | 13 +++++++++---- spec/ruby_lsp_rspec_spec.rb | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb b/lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb index 36e09bb..6f87566 100644 --- a/lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb +++ b/lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb @@ -50,7 +50,7 @@ def on_call_node_enter(node) name = generate_name(node) add_test_code_lens(node, name: name, kind: :example) when "context", "describe" - return if node.receiver && node.receiver&.slice != "RSpec" + return unless valid_group?(node) name = generate_name(node) add_test_code_lens(node, name: name, kind: :group) @@ -64,12 +64,19 @@ def on_call_node_enter(node) def on_call_node_leave(node) case node.message when "context", "describe" - return if node.receiver && node.receiver&.slice != "RSpec" + return unless valid_group?(node) @group_id_stack.pop end end + private + + sig { params(node: Prism::CallNode).returns(T::Boolean) } + def valid_group?(node) + !(node.block.nil? || (node.receiver && node.receiver&.slice != "RSpec")) + end + sig { params(node: Prism::CallNode).returns(String) } def generate_name(node) arguments = node.arguments&.arguments @@ -92,8 +99,6 @@ def generate_name(node) end end - private - sig { params(node: Prism::Node, name: String, kind: Symbol).void } def add_test_code_lens(node, name:, kind:) line_number = node.location.start_line diff --git a/spec/ruby_lsp_rspec_spec.rb b/spec/ruby_lsp_rspec_spec.rb index 64d1ab5..035067b 100644 --- a/spec/ruby_lsp_rspec_spec.rb +++ b/spec/ruby_lsp_rspec_spec.rb @@ -129,6 +129,11 @@ describe var do end + + # these should bot be recognized + context + describe + context("foo") RUBY response = RubyLsp::Executor.new(store, message_queue).execute(