File tree Expand file tree Collapse file tree 5 files changed +33
-19
lines changed Expand file tree Collapse file tree 5 files changed +33
-19
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,23 @@ def leading_annotation?(index)
222
222
223
223
false
224
224
end
225
+
226
+ def as_comment
227
+ lines = [ ] #: Array[String]
228
+
229
+ each_paragraph ( [ ] ) do |paragraph |
230
+ case paragraph
231
+ when Location
232
+ lines << paragraph . local_source
233
+ end
234
+ end
235
+
236
+ string = lines . join ( "\n " )
237
+
238
+ unless string . strip . empty?
239
+ AST ::Comment . new ( string : string , location : location )
240
+ end
241
+ end
225
242
end
226
243
end
227
244
end
Original file line number Diff line number Diff line change @@ -177,6 +177,10 @@ def type
177
177
Types ::Bases ::Any . new ( location : nil )
178
178
end
179
179
end
180
+
181
+ def comment
182
+ leading_comment &.as_comment
183
+ end
180
184
end
181
185
end
182
186
end
Original file line number Diff line number Diff line change @@ -66,25 +66,7 @@ def comment
66
66
when AST ::Members ::Base
67
67
member . comment
68
68
when AST ::Ruby ::Members ::Base
69
- if member . leading_comment
70
- lines = [ ] #: Array[String]
71
-
72
- member . leading_comment . each_paragraph ( [ ] ) do |paragraph |
73
- case paragraph
74
- when Location
75
- lines << paragraph . local_source
76
- end
77
- end
78
-
79
- string = lines . join ( "\n " )
80
-
81
- unless string . strip . empty?
82
- AST ::Comment . new (
83
- string : string ,
84
- location : member . leading_comment . location
85
- )
86
- end
87
- end
69
+ member . leading_comment &.as_comment
88
70
end
89
71
end
90
72
Original file line number Diff line number Diff line change @@ -115,6 +115,12 @@ module RBS
115
115
def location : () -> Location
116
116
117
117
private def leading_annotation? : (Integer index) -> bool
118
+
119
+ # Returns an comment object that contains the docs of from the comment block
120
+ #
121
+ # It ignores type annotations and syntax errors.
122
+ #
123
+ def as_comment : () -> AST::Comment?
118
124
end
119
125
end
120
126
end
Original file line number Diff line number Diff line change @@ -101,7 +101,12 @@ module RBS
101
101
# - When type_anntoation is given, it returns the type from the annotation.
102
102
# - When type_annotation is not given, it returns infered type from the right-hand-side of the constant assignment
103
103
# - Or it returns `untyped` type
104
+ #
104
105
def type : () -> Types::t
106
+
107
+ # Returns the comment content extracted from the leading comment block
108
+ #
109
+ def comment : () -> AST::Comment?
105
110
end
106
111
end
107
112
end
You can’t perform that action at this time.
0 commit comments