diff --git a/queries/ruby/context.scm b/queries/ruby/context.scm index 9128f098..666bb2fe 100644 --- a/queries/ruby/context.scm +++ b/queries/ruby/context.scm @@ -1,35 +1,46 @@ (class - (body_statement) @context.end) @context + name: (constant) + (_) @context.end) @context (singleton_class - (body_statement) @context.end) @context + value: (self) @context.end) @context (module - (body_statement) @context.end) @context + name: (constant) @context.end) @context + +(method + name: (identifier) + parameters: (method_parameters) @context.end) @context (method - (body_statement) @context.end) @context + name: (identifier) @context.end) @context + +(singleton_method + object: (self) + name: (identifier) + parameters: (method_parameters) @context.end) @context (singleton_method - (body_statement) @context.end) @context + object: (self) + name: (identifier) @context.end) @context (if (then) @context.end) @context (if - (else - (_) @context.end)) @context + condition: (_) @context.end) @context + +(else + (_) @context.end) @context (unless (then) @context.end) @context (unless - (else - (_) @context.end)) @context + condition: (_) @context.end) @context -(_ - (do_block - (body_statement) @context.end)) @context +(do_block + parameters: (block_parameters) @context.end) @context (call method: (identifier) @_identifier diff --git a/test/lang/test.rb b/test/lang/test.rb index 122fab70..1e6d1b58 100644 --- a/test/lang/test.rb +++ b/test/lang/test.rb @@ -1,45 +1,108 @@ +# {{TEST}} # frozen_string_literal: true -module Bar # BUG: The contexts here include too many newlines - class Foo - class << self - def run +# BUG: The contexts need newlines or they don't appear +# Comment before module starts +module Bar # {{CONTEXT}} + # Comment after module starts + # {{CURSOR}} + # Comment before class starts + class Foo # {{CONTEXT}} + # Comment after class starts - if false - (20..30).each do |element| - block.call(element) - end - else - 1 + 1 - end - end - end - def self.other_method - unless false - (10..20).each do |element| - block.call(element) - end - else - 1 + 1 - end - end + # {{CURSOR}} + # Comment before singleton class starts + class << self # {{CONTEXT}} + # Comment after singleton class starts - def run(&block) - unless false - (1..10).each do |element| - block.call(element) - end - else - 1 + 1 + + # {{CURSOR}} + # Comment before method starts + def run # {{CONTEXT}} + # Comment after method starts + + + # {{CURSOR}} + if false # {{CONTEXT}} + # Comment after if starts + + + # {{CURSOR}} + (20..30).each do |element| # {{CONTEXT}} + # Comment after block starts + + + block.call(element) # {{CURSOR}} + end # {{POPCONTEXT}} + else # {{CONTEXT}} + # Comment after else starts + + + 1 + 1 #{{CURSOR}} + end # {{POPCONTEXT}} + end # {{POPCONTEXT}} + end # {{POPCONTEXT}} + # {{POPCONTEXT}} # XXX: Extra pop to pop the else context + + # Comment before singleton method + def self.other_method # {{CONTEXT}} + # Comment after singleton method starts + + + # {{CURSOR}} + unless false # {{CONTEXT}} + # Comment after unless starts + + + # {{CURSOR}} + (10..20).each do |element| # {{CONTEXT}} + # Comment after block starts + + + block.call(element) # {{CURSOR}} + end # {{POPCONTEXT}} + else # {{CONTEXT}} + # Comment after else starts + + + 1 + 1 # {{CURSOR}} + end # {{POPCONTEXT}} + end # {{POPCONTEXT}} + # {{POPCONTEXT}} # XXX: Extra pop to pop the else context + + # Comment before method starts + def run(&block) # {{CONTEXT}} + # Comment after method starts + + + # {{CURSOR}} + unless false # {{CONTEXT}} + # Comment after unless starts + + + # {{CURSOR}} + (1..10).each do |element| # {{CONTEXT}} + # Comment after block starts + + + block.call(element) # {{CURSOR}} + end # {{POPCONTEXT}} + else # {{CONTEXT}} + # Comment after else starts + + + 1 + 1 # {{CURSOR}} end end end end +# {{TEST}} + RSpec.describe 'foo' do # {{CONTEXT}} context 'bar' do # {{CONTEXT}} shared_context 'shared context' do # {{CONTEXT}}