File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,11 @@ def source_location
2121 end
2222
2323 def comment
24- @method . comment
25- rescue MethodSource ::SourceNotFoundError , Errno ::EINVAL
24+ return nil if source_location . nil? || source_location . first . start_with? ( '<' )
25+
26+ # Do not use method_source's comment method because it's slow
27+ @comment ||= RubyMethod . last_comment *source_location
28+ rescue Errno ::EINVAL , Errno ::ENOENT
2629 nil
2730 end
2831
@@ -37,6 +40,21 @@ def name
3740 def labels
3841 @package . labels
3942 end
43+
44+ private
45+
46+ # Read file and get last comment before line.
47+ def self . last_comment ( file , line )
48+ File . open ( file ) do |f |
49+ buffer = [ ]
50+ f . lines . lazy . take ( line - 1 ) . reverse_each do |line |
51+ break unless ( line =~ /^\s *#/ ) || ( line =~ /^\s *$/ )
52+
53+ buffer << line . lstrip
54+ end
55+ buffer . reverse . join
56+ end
57+ end
4058 end
4159
4260 class Tracing
You can’t perform that action at this time.
0 commit comments