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)
|
klass = target.eval(name)
|
||||||
|
|
||||||
mod = Pry::WrappedModule(klass)
|
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
|
doc = mod.doc
|
||||||
|
|
||||||
if doc.empty?
|
if doc.empty?
|
||||||
output.puts "No documentation found."
|
output.puts "No documentation found."
|
||||||
else
|
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"
|
output.puts "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n\n"
|
||||||
|
|
||||||
if opts.present?(:b) || opts.present?(:l)
|
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).
|
doc = Code.new(doc, start_line, :text).
|
||||||
with_line_numbers(true)
|
with_line_numbers(true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,17 +101,20 @@ class Pry
|
||||||
super || wrapped.respond_to?(method_name)
|
super || wrapped.respond_to?(method_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def yard_docs?
|
||||||
|
!!(defined?(YARD) && YARD::Registry.at(name))
|
||||||
|
end
|
||||||
|
|
||||||
def doc
|
def doc
|
||||||
return @doc if @doc
|
return @doc if @doc
|
||||||
|
|
||||||
file_name, line = source_location
|
file_name, line = source_location
|
||||||
|
|
||||||
if file_name.nil?
|
if yard_docs?
|
||||||
if defined?(YARD) && from_yard = YARD::Registry.at(name)
|
from_yard = YARD::Registry.at(name)
|
||||||
@doc = from_yard.docstring
|
@doc = from_yard.docstring
|
||||||
else
|
elsif source_location.nil?
|
||||||
raise CommandError, "Can't find module's source location"
|
raise CommandError, "Can't find module's source location"
|
||||||
end
|
|
||||||
else
|
else
|
||||||
@doc = extract_doc
|
@doc = extract_doc
|
||||||
end
|
end
|
||||||
|
@ -132,6 +135,19 @@ class Pry
|
||||||
|
|
||||||
end
|
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
|
# Retrieve the source location of a module. Return value is in same
|
||||||
# format as Method#source_location. If the source location
|
# format as Method#source_location. If the source location
|
||||||
# cannot be found this method returns `nil`.
|
# cannot be found this method returns `nil`.
|
||||||
|
|
Loading…
Reference in a new issue