14
14
require_relative 'completion'
15
15
require 'io/console'
16
16
require 'reline'
17
+ require 'rdoc'
17
18
18
19
module IRB
19
20
STDIN_FILE_NAME = "(line)" # :nodoc:
@@ -308,6 +309,46 @@ def auto_indent(&block)
308
309
@auto_indent_proc = block
309
310
end
310
311
312
+ SHOW_DOC_DIALOG = -> ( ) {
313
+ begin
314
+ require 'rdoc'
315
+ rescue LoadError
316
+ return nil
317
+ end
318
+ if just_cursor_moving and completion_journey_data . nil?
319
+ return nil
320
+ end
321
+ cursor_pos_to_render , result , pointer = context . pop ( 3 )
322
+ return nil if result . nil? or pointer . nil?
323
+ name = result [ pointer ]
324
+
325
+ driver = RDoc ::RI ::Driver . new
326
+ name = driver . expand_name ( name )
327
+ doc = nil
328
+ used_for_class = false
329
+ if not name =~ /#|\. /
330
+ found , klasses , includes , extends = driver . classes_and_includes_and_extends_for ( name )
331
+ if not found . empty?
332
+ doc = driver . class_document ( name , found , klasses , includes , extends )
333
+ used_for_class = true
334
+ end
335
+ end
336
+ unless used_for_class
337
+ doc = RDoc ::Markup ::Document . new
338
+ begin
339
+ driver . add_method ( doc , name )
340
+ rescue RDoc ::RI ::Driver ::NotFoundError
341
+ doc = nil
342
+ end
343
+ end
344
+ return nil if doc . nil?
345
+ formatter = RDoc ::Markup ::ToAnsi . new
346
+ formatter . width = 40
347
+ str = doc . accept ( formatter )
348
+
349
+ [ Reline ::CursorPos . new ( cursor_pos_to_render . x + 40 , cursor_pos_to_render . y + pointer ) , str . split ( "\n " ) , nil , '49' ]
350
+ }
351
+
311
352
# Reads the next line from this input method.
312
353
#
313
354
# See IO#gets for more information.
@@ -316,6 +357,7 @@ def gets
316
357
Reline . output = @stdout
317
358
Reline . prompt_proc = @prompt_proc
318
359
Reline . auto_indent_proc = @auto_indent_proc if @auto_indent_proc
360
+ Reline . add_dialog_proc ( :show_doc , SHOW_DOC_DIALOG , Reline ::DEFAULT_DIALOG_CONTEXT )
319
361
if l = readmultiline ( @prompt , false , &@check_termination_proc )
320
362
HISTORY . push ( l ) if !l . empty?
321
363
@line [ @line_no += 1 ] = l + "\n "
0 commit comments