diff options
author | aycabta <aycabta@gmail.com> | 2021-08-28 01:53:43 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2021-08-29 20:30:33 +0900 |
commit | 78f46e65767563f0ec0dc6564901dcd7e99dc044 (patch) | |
tree | 0c723e90b059669c8412e7c180523ca6bec45671 /lib/reline.rb | |
parent | 7e8a6270525f4ea944e8b3b3c3014a48bdb5a734 (diff) |
[ruby/reline] Show method or class doc correctly
https://github.com/ruby/reline/commit/a505294f12
Diffstat (limited to 'lib/reline.rb')
-rw-r--r-- | lib/reline.rb | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/reline.rb b/lib/reline.rb index ddc4a06af9..fea0498dfb 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -222,16 +222,31 @@ module Reline cursor_pos_to_render, result, pointer = context.pop(3) return nil if result.nil? or pointer.nil? name = result[pointer] + driver = RDoc::RI::Driver.new - doc = RDoc::Markup::Document.new - begin - driver.add_method(doc, name) - rescue RDoc::RI::Driver::NotFoundError => e - return nil + name = driver.expand_name name + doc = nil + used_for_class = false + if not name =~ /#|\./ + found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name) + if not found.empty? + doc = driver.class_document name, found, klasses, includes, extends + used_for_class = true + end end + unless used_for_class + doc = RDoc::Markup::Document.new + begin + driver.add_method(doc, name) + rescue RDoc::RI::Driver::NotFoundError + doc = nil + end + end + return nil if doc.nil? formatter = RDoc::Markup::ToBs.new formatter.width = 40 str = doc.accept(formatter) + [Reline::CursorPos.new(cursor_pos_to_render.x + 40, cursor_pos_to_render.y + pointer), str.split("\n"), nil] } |