mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
show-doc for core classes now shows file name, closes #536
This commit is contained in:
parent
765f0177c6
commit
d8d80419ee
2 changed files with 37 additions and 9 deletions
|
@ -54,17 +54,29 @@ class Pry
|
|||
klass = target.eval(name)
|
||||
|
||||
mod = Pry::WrappedModule(klass)
|
||||
file_name, line = mod.source_location
|
||||
|
||||
# source_file reveals the underlying .c file in case of core
|
||||
# classes on MRI.
|
||||
# This is different to source_location, which
|
||||
# will return nil.
|
||||
if mod.yard_docs?
|
||||
file_name, line = mod.source_file, nil
|
||||
else
|
||||
file_name, line = mod.source_location
|
||||
end
|
||||
|
||||
doc = mod.doc
|
||||
|
||||
if doc.empty?
|
||||
output.puts "No documentation found."
|
||||
else
|
||||
set_file_and_dir_locals(file_name)
|
||||
|
||||
# source_location is nil in case of core classes on MRI
|
||||
set_file_and_dir_locals(file_name) if !mod.yard_docs?
|
||||
output.puts "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n\n"
|
||||
|
||||
if opts.present?(:b) || opts.present?(:l)
|
||||
start_line = file_name.nil? ? 1 : line - doc.lines.count
|
||||
start_line = mod.source_location.nil? ? 1 : line - doc.lines.count
|
||||
doc = Code.new(doc, start_line, :text).
|
||||
with_line_numbers(true)
|
||||
end
|
||||
|
|
|
@ -101,17 +101,20 @@ class Pry
|
|||
super || wrapped.respond_to?(method_name)
|
||||
end
|
||||
|
||||
def yard_docs?
|
||||
!!(defined?(YARD) && YARD::Registry.at(name))
|
||||
end
|
||||
|
||||
def doc
|
||||
return @doc if @doc
|
||||
|
||||
file_name, line = source_location
|
||||
|
||||
if file_name.nil?
|
||||
if defined?(YARD) && from_yard = YARD::Registry.at(name)
|
||||
@doc = from_yard.docstring
|
||||
else
|
||||
raise CommandError, "Can't find module's source location"
|
||||
end
|
||||
if yard_docs?
|
||||
from_yard = YARD::Registry.at(name)
|
||||
@doc = from_yard.docstring
|
||||
elsif source_location.nil?
|
||||
raise CommandError, "Can't find module's source location"
|
||||
else
|
||||
@doc = extract_doc
|
||||
end
|
||||
|
@ -132,6 +135,19 @@ class Pry
|
|||
|
||||
end
|
||||
|
||||
def source_file
|
||||
if yard_docs?
|
||||
from_yard = YARD::Registry.at(name)
|
||||
from_yard.file
|
||||
else
|
||||
Array(source_location).first
|
||||
end
|
||||
end
|
||||
|
||||
def source_line
|
||||
source_location.nil? ? nil : source_location.last
|
||||
end
|
||||
|
||||
# Retrieve the source location of a module. Return value is in same
|
||||
# format as Method#source_location. If the source location
|
||||
# cannot be found this method returns `nil`.
|
||||
|
|
Loading…
Reference in a new issue