Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show doc dialog for reline #269

Merged
merged 4 commits into from
Aug 29, 2021
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: |
gem update --system
gem install bundler --no-document
bundle install
- name: Run test
Expand Down
2 changes: 1 addition & 1 deletion irb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = Gem::Requirement.new(">= 2.5")

spec.add_dependency "reline", ">= 0.2.7"
spec.add_dependency "reline", ">= 0.2.8.pre.1"
end
46 changes: 46 additions & 0 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_relative 'completion'
require 'io/console'
require 'reline'
require 'rdoc'

module IRB
STDIN_FILE_NAME = "(line)" # :nodoc:
Expand Down Expand Up @@ -308,6 +309,50 @@ def auto_indent(&block)
@auto_indent_proc = block
end

SHOW_DOC_DIALOG = ->() {
begin
require 'rdoc'
rescue LoadError
return nil
end
if just_cursor_moving and completion_journey_data.nil?
return nil
end
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
begin
name = driver.expand_name(name)
rescue RDoc::RI::Driver::NotFoundError
return nil
end
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::ToAnsi.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, '49']
}

# Reads the next line from this input method.
#
# See IO#gets for more information.
Expand All @@ -316,6 +361,7 @@ def gets
Reline.output = @stdout
Reline.prompt_proc = @prompt_proc
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
if l = readmultiline(@prompt, false, &@check_termination_proc)
HISTORY.push(l) if !l.empty?
@line[@line_no += 1] = l + "\n"
Expand Down