dgl/cpangrep

Line numbers are always 1

Closed this issue · 7 comments

The line numbers always come out as 1:

http://grep.cpan.me/?q=nice%2C+rice%2C+lice
https://metacpan.org/source/BKB/Text-Fuzzy-0.22/examples/list-context.pl#L1

http://grep.cpan.me/?q=Gotta+get+down+on+Friday
https://metacpan.org/source/BKB/JSON-Parse-0.38/lib/JSON/Parse.pod#L1

Every other example I have tried gives a line number of 1.

The line number seems to be printed here:

$_->select('.excerpt-link')->set_attribute(href => "$source#L$excerpt->{line}[0]");

using a value which is set here:

line => [$start, $end],

from calculations here:

my $start = 1 + substr($pm, $indexed_file_offset, $match->[0] - $indexed_file_offset) =~ tr/\n//;

Without running the code I cannot see what's wrong in the above, but it is always coming out as 1.

By the way, thanks for the useful grep.cpan.me service.

I can't reproduce this clicking the links above, nor with the App::cpangrep command line client, which uses the web API.

If you look at the HTML of a results page that's got the wrong line numbers, what do you see?

Oooh, I think I know what's happening. :-) Click the code hunk, not the linked filename.

That is, you're clicking the link produced by:

$_ = $_->select('.file-link')->replace_content($filename)
->then
->set_attribute(href => "$source#L1");

Not the link produced by:

$_->select('.excerpt-link')->set_attribute(href => "$source#L$excerpt->{line}[0]");

Click the code hunk, not the linked filename.

I didn't even know there was a link on the code hunk. Maybe this is something of a web design/usability issue? Feel free to close this if you want to.

I agree it's not obvious the code hunks are links. The only hint is that your pointer will change when you mouse over it. I'm not a repo owner, I can't close it even if I wanted to. Just an interested bystander. :-)

I agree it's not obvious the code hunks are links.

I wasn't expecting to find links there. My mental model of how search pages work is Google, and I don't get those links on Google, so it would help to have some visual guidance. It's also not obvious that they are going to the specific line numbers of the file.

The other usability problem is that the link to the file takes me to "#L1" of the file, which really doesn't make sense. If it's a link to the file in general, then there's no reason to link to line one of the file. That is just confusing.

Anyway now that I know how to use it better, I'll be able to work the system. It's up to the owner of the repository whether they want to worry about usability or not. If this doesn't help, feel free to delete.

dgl commented

I just dropped the linking to line 1, maybe makes things clearer.