Skip to content

Commit 76e1b46

Browse files
committed
Update parser to support skip annotation
1 parent 0795a23 commit 76e1b46

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

lib/rbs/inline_parser.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,20 @@ def push_module_nesting(mod)
7474
module_nesting.pop()
7575
end
7676

77+
def skip_node?(node)
78+
if ref = comments.leading_block(node)
79+
if ref.block.each_paragraph([]).any? { _1.is_a?(AST::Ruby::Annotations::SkipAnnotation) }
80+
ref.associate!
81+
return true
82+
end
83+
end
84+
85+
false
86+
end
87+
7788
def visit_class_node(node)
89+
return if skip_node?(node)
90+
7891
unless class_name = constant_as_type_name(node.constant_path)
7992
diagnostics << Diagnostic::NonConstantClassName.new(
8093
rbs_location(node.constant_path.location),
@@ -95,6 +108,8 @@ def visit_class_node(node)
95108
end
96109

97110
def visit_module_node(node)
111+
return if skip_node?(node)
112+
98113
unless module_name = constant_as_type_name(node.constant_path)
99114
diagnostics << Diagnostic::NonConstantModuleName.new(
100115
rbs_location(node.constant_path.location),
@@ -115,6 +130,8 @@ def visit_module_node(node)
115130
end
116131

117132
def visit_def_node(node)
133+
return if skip_node?(node)
134+
118135
if node.receiver
119136
diagnostics << Diagnostic::NotImplementedYet.new(
120137
rbs_location(node.receiver.location),

sig/inline_parser.rbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ module RBS
7171

7272
def push_module_nesting: [T] (module_context) { () -> T } -> T
7373

74+
# Returns `true` if the node is a comment block including `@rbs skip` annotation
75+
#
76+
# Doesn't update the `association` flag if returning `false`.
77+
#
78+
def skip_node?: (Prism::Node) -> bool
79+
7480
def insert_declaration: (module_context) -> void
7581

7682
def report_unused_annotation: (*AST::Ruby::Annotations::t | nil | AST::Ruby::CommentBlock::AnnotationSyntaxError) -> void

test/rbs/inline_parser_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,36 @@ def foo(x = nil)
235235
end
236236
end
237237
end
238+
239+
def test_parse__skip_class_module
240+
result = parse(<<~RUBY)
241+
# @rbs skip -- not a constant
242+
class (c::)Foo
243+
end
244+
245+
# @rbs skip
246+
module Bar
247+
end
248+
RUBY
249+
250+
assert_empty result.diagnostics
251+
252+
assert_empty result.declarations
253+
end
254+
255+
def test_parse__skip_def
256+
result = parse(<<~RUBY)
257+
class Foo
258+
# @rbs skip
259+
def foo
260+
end
261+
end
262+
RUBY
263+
264+
assert_empty result.diagnostics
265+
266+
result.declarations[0].tap do |decl|
267+
assert_empty decl.members
268+
end
269+
end
238270
end

0 commit comments

Comments
 (0)