Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions queries/ruby/context.scm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
121 changes: 92 additions & 29 deletions test/lang/test.rb
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
Loading