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

show-doc doens't work for some items but ri does #17

Open
Silex opened this issue Feb 13, 2014 · 10 comments
Open

show-doc doens't work for some items but ri does #17

Silex opened this issue Feb 13, 2014 · 10 comments

Comments

@Silex
Copy link

Silex commented Feb 13, 2014

Hello,

Before you complain about 0.4.6, the same things happen with 0.5.1. Basically show-doc doens't work for some items but ri works (either at the command line or inside pry):

philippe@philippe-desktop:~$ pry
[1] pry(main)> Pry::VERSION
=> "0.9.12.6"
[2] pry(main)> PryDoc::VERSION
=> "0.4.6"
[3] pry(main) »  ri File.exists?

File.exists?
(from ruby site)
------------------------------------------------------------------------------
  exists?(p1)

------------------------------------------------------------------------------

[4] pry(main) »  ? File.exists?
Error: Cannot locate this method: exists?. (source_location returns nil)
[5] pry(main) »  ? File

From: /home/philippe/.rvm/gems/ruby-2.1.0@gemset/gems/yard-0.8.7.3/lib/yard/core_ext/file.rb @ line 3:
Class name: File
Number of lines: 1

[6] pry(main) »  ? String

From: object.c (C Method):
Owner: Kernel
Visibility: private
Signature: String(arg1)
Number of lines: 6

Converts arg to a String by calling its
to_s method.

   String(self)        #=> "main"
   String(self.class   #=> "Object"
   String(123456)      #=> "123456"

[7] pry(main)> ? GC
Error: Couldn't locate a definition for GC!

[8] pry(main)> ri GC
GC

(from ruby site)
------------------------------------------------------------------------------
The GC module provides an interface to Ruby's mark and sweep garbage
collection mechanism.

Some of the underlying methods are also available via the ObjectSpace module.

You may obtain information about the operation of the GC through GC::Profiler.
------------------------------------------------------------------------------
Constants:

INTERNAL_CONSTANTS:
  [not documented]

OPTS:
  [not documented]


Class methods:

  count
  disable
  enable
  (... snip)

Basically, seems it cannot find File or GC for some weird reason. From the command line ri GC or ri File.exists? works (as showed in the pry session).

How can I debug this? Maybe a path issue?

@kyrylo
Copy link
Member

kyrylo commented Feb 13, 2014

Hello, @Silex! Thanks for reporting this. The problem is that the ri command and the show-doc command use completely different ways to find the docs. The key difference between them is that ri is "static" and show-doc is dynamic. It means that show-doc can display docs on the fly.

[11] pry(main)> # Hello, Silex!
[12] pry(main)> def hi
              |   :hi!
              | end  
=> :hi
[13] pry(main)> ? hi

From: (pry) @ line 4:
Owner: Object
Visibility: public
Signature: hi()
Number of lines: 1

Hello, Silex!

show-doc for core/stdlib depends on YARD. In the case of File, it seems Pry cannot resolve ? File properly (and other mentioned stuff). I think it is a bug in Pry, because our underlying API does provide docs YARD::Registry.at("File").docstring. So patches are welcome :)

@Silex
Copy link
Author

Silex commented Feb 13, 2014

Interesting:

[1] pry »  YARD::Registry.at("File").docstring
=> ""
[2] pry »  YARD::Registry.at("GC").docstring
=> "The <code>GC</code> module provides an interface to Ruby's mark and\nsweep garbage collection mechanism. Some of the underlying methods\nare also available via the <code>ObjectSpace</code> module."

Basically it looks like it somewhat finds it (for GC at least) but not when called through show-doc. So, any pointers at where stuffs go wrong? You say it's in Pry, any idea where I should start looking in pry?

@kyrylo
Copy link
Member

kyrylo commented Feb 14, 2014

[2] pry(main)> pry-version
Pry version: 0.9.12.6 on Ruby 2.1.0.
[3] pry(main)> PryDoc::VERSION
=> "0.5.1"
[4] pry(main)> YARD::Registry.at("File").docstring
=> "A <code>File</code> is an abstraction of any file object accessible\nby the program and is closely associated with class <code>IO</code>\n<code>File</code> includes the methods of module\n<code>FileTest</code> as class methods, allowing you to write (for\nexample) <code>File.exist?(\"foo\")</code>.\n\nIn the description of File methods,\n<em>permission bits</em> are a platform-specific\nset of bits that indicate permissions of a file. On Unix-based\nsystems, permissions are viewed as a set of three octets, for the\nowner, the group, and the rest of the world. For each of these\nentities, permissions may be set to read, write, or execute the\nfile:\n\nThe permission bits <code>0644</code> (in octal) would thus be\ninterpreted as read/write for owner, and read-only for group and\nother. Higher-order bits may also be used to indicate the type of\nfile (plain, directory, pipe, socket, and so on) and various other\nspecial features. If the permissions are for a directory, the\nmeaning of the execute bit changes; when set the directory can be\nsearched.\n\nOn non-Posix operating systems, there may be only the ability to\nmake a file read-only or read-write. In this case, the remaining\npermission bits will be synthesized to resemble typical values. For\ninstance, on Windows NT the default permission bits are\n<code>0644</code>, which means read/write for owner, read-only for\nall others. The only change that can be made is to make the file\nread-only, which is reported as <code>0444</code>.\n\nVarious constants for the methods in File can be found in File::Constants."

Not sure where to start looking. I haven't investigated this issue much. Sorry.

@dgutov
Copy link
Contributor

dgutov commented Feb 14, 2014

And on an older Ruby, too:

[2] pry(main)> pry-version
Pry version: 0.9.12.6 on Ruby 1.9.3.
[3] pry(main)> PryDoc::VERSION
=> "0.4.6"
[4] pry(main)> YARD::Registry.at("File").docstring
=> "A <code>File</code> is an abstraction of any file object accessible\nby the program and is closely associated with class <code>IO</code>\n<code>File</code> includes the methods of module\n<code>FileTest</code> as class methods, allowing you to write (for\nexample) <code>File.exist?(\"foo\")</code>.\n\nIn the description of File methods,\n<em>permission bits</em> are a platform-specific\nset of bits that indicate permissions of a file. On Unix-based\nsystems, permissions are viewed as a set of three octets, for the\nowner, the group, and the rest of the world. For each of these\nentities, permissions may be set to read, write, or execute the\nfile:\n\nThe permission bits <code>0644</code> (in octal) would thus be\ninterpreted as read/write for owner, and read-only for group and\nother. Higher-order bits may also be used to indicate the type of\nfile (plain, directory, pipe, socket, and so on) and various other\nspecial features. If the permissions are for a directory, the\nmeaning of the execute bit changes; when set the directory can be\nsearched.\n\nOn non-Posix operating systems, there may be only the ability to\nmake a file read-only or read-write. In this case, the remaining\npermission bits will be synthesized to resemble typical values. For\ninstance, on Windows NT the default permission bits are\n<code>0644</code>, which means read/write for owner, read-only for\nall others. The only change that can be made is to make the file\nread-only, which is reported as <code>0444</code>."

(pry-doc 0.5.1 behaves the same here).

@Silex
Copy link
Author

Silex commented Feb 14, 2014

Ok I finally got it working like you guys:

[2] pry(main)> pry-version
Pry version: 0.9.12.6 on Ruby 2.1.0.
[3] pry(main)> PryDoc::VERSION
=> "0.5.1"
[4] pry(main)> YARD::Registry.at("File").docstring
=> "A <code>File</code> is an abstraction of any file object accessible\nby the program and is closely associated with class <code>IO</code>\n<code>File</code> includes the methods of module\n<code>FileTest</code> as class methods, allowing you to write (for\nexample) <code>File.exist?(\"foo\")</code>.\n\nIn the description of File methods,\n<em>permission bits</em> are a platform-specific\nset of bits that indicate permissions of a file. On Unix-based\nsystems, permissions are viewed as a set of three octets, for the\nowner, the group, and the rest of the world. For each of these\nentities, permissions may be set to read, write, or execute the\nfile:\n\nThe permission bits <code>0644</code> (in octal) would thus be\ninterpreted as read/write for owner, and read-only for group and\nother. Higher-order bits may also be used to indicate the type of\nfile (plain, directory, pipe, socket, and so on) and various other\nspecial features. If the permissions are for a directory, the\nmeaning of the execute bit changes; when set the directory can be\nsearched.\n\nOn non-Posix operating systems, there may be only the ability to\nmake a file read-only or read-write. In this case, the remaining\npermission bits will be synthesized to resemble typical values. For\ninstance, on Windows NT the default permission bits are\n<code>0644</code>, which means read/write for owner, read-only for\nall others. The only change that can be made is to make the file\nread-only, which is reported as <code>0444</code>.\n\nVarious constants for the methods in File can be found in File::Constants."
[5] pry(main)> ? File

From: /home/philippe/.rvm/gems/ruby-2.1.0@test/gems/yard-0.8.7.3/lib/yard/core_ext/file.rb @ line 3:
Class name: File
Number of lines: 1

[6] pry(main)> ? GC
Error: Couldn't locate a definition for GC!

[7] pry(main)> YARD::Registry.at("GC").docstring
=> "The GC module provides an interface to Ruby's mark and\nsweep garbage collection mechanism.\n\nSome of the underlying methods are also available via the ObjectSpace\nmodule.\n\nYou may obtain information about the operation of the GC through\nGC::Profiler."

There are two things interesting:

  1. GC is still not findable.
  2. This time I tested by creating a new gemset, so it means that previously some other gem conflicts with pry-doc. I'll try to find which one.

@dgutov
Copy link
Contributor

dgutov commented Feb 14, 2014

some other gem conflicts with pry-doc

Could it be an old version of Yard?

@Silex
Copy link
Author

Silex commented Feb 14, 2014

Ok, turns out point 2 is a non issue (me miss-testing stuffs). I use YARD 0.8.7.3 so I don't think it's an issue.

There is only point 1 to worry about, and I just had a good debugging session and I'm pretty close to finding the culprit. The problem is that at https://github.com/pry/pry/blob/master/lib/pry/commands/show_info.rb#L42, code_object.candidates.find(&:source) returns nil for GC but true for File or FileUtils.

Not sure what this really means, but if make it return code_object then stuff just work.

[EDIT] I was going to create an issue in pry but without pry-doc YARD::Registry.at("GC").docstring doesn't return anything, so it looks like pry-doc finds the doc string but pry fails somewhere? How should I present this to the pry people?

@dgutov
Copy link
Contributor

dgutov commented Feb 15, 2014

code_object_with_accessible_source looks weird. The docstring says "with accessible source (or docs)", but the code only looks for the source. I haven't checked though, maybe source also returns non-nil when the candidate only has a doc, without the source.

@Silex
Copy link
Author

Silex commented Feb 16, 2014

Just curious, does show-doc GC work for you guys?

@kyrylo
Copy link
Member

kyrylo commented Feb 16, 2014

It doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants