Class: RubyLsp::RSpec::CodeLens
- Inherits:
-
Object
- Object
- RubyLsp::RSpec::CodeLens
- Extended by:
- T::Sig
- Includes:
- RubyLsp::Requests::Support::Common
- Defined in:
- lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb
Instance Method Summary collapse
-
#initialize(response_builder, uri, dispatcher) ⇒ CodeLens
constructor
A new instance of CodeLens.
- #on_call_node_enter(node) ⇒ Object
- #on_call_node_leave(node) ⇒ Object
Constructor Details
#initialize(response_builder, uri, dispatcher) ⇒ CodeLens
Returns a new instance of CodeLens.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb', line 18 def initialize(response_builder, uri, dispatcher) @response_builder = response_builder # Listener is only initialized if uri.to_standardized_path is valid @path = T.let(T.must(uri.to_standardized_path), String) @group_id = T.let(1, Integer) @group_id_stack = T.let([], T::Array[Integer]) @anonymous_example_count = T.let(0, Integer) dispatcher.register(self, :on_call_node_enter, :on_call_node_leave) @base_command = T.let( begin cmd = if File.exist?(File.join(Dir.pwd, "bin", "rspec")) "bin/rspec" else "rspec" end if File.exist?("Gemfile.lock") "bundle exec #{cmd}" else cmd end end, String, ) end |
Instance Method Details
#on_call_node_enter(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb', line 46 def on_call_node_enter(node) case node. when "example", "it", "specify" name = generate_name(node) add_test_code_lens(node, name: name, kind: :example) when "context", "describe" return unless valid_group?(node) name = generate_name(node) add_test_code_lens(node, name: name, kind: :group) @group_id_stack.push(@group_id) @group_id += 1 end end |
#on_call_node_leave(node) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb', line 63 def on_call_node_leave(node) case node. when "context", "describe" return unless valid_group?(node) @group_id_stack.pop end end |