google / zoekt

Fast trigram based code search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

anchor to results is wrong

vpereira opened this issue · comments

Hi,

if i search for a term, and I'm running the webserver with "-print", then I get the results, and you have the line number as link to the place where the search term was found. However the anchor is wrong (i.e if you click in the line number, it doesn't bring you to the exact line number)

so I was able to fix it with:

diff --git a/web/templates.go b/web/templates.go
index 7e95a28..419f8f2 100644
--- a/web/templates.go
+++ b/web/templates.go
@@ -151,7 +151,7 @@ To list repositories, try:
       {{else}}
         <div style="background: #eef;">
         {{range .Matches}}
-          <pre>{{if .URL}}<a href="{{.URL}}">{{end}}{{.LineNum}}{{if .URL}}</a>{{end}}: {{range .Fragments}}{{.Pre}}<b>{{.Match}}</b>{{.Post}}{{end}}</pre>
+          <pre>{{if .URL}}<a href="{{.URL}}l{{.LineNum}}">{{end}}{{.LineNum}}{{if .URL}}</a>{{end}}: {{range .Fragments}}{{.Pre}}<b>{{.Match}}</b>{{.Post}}{{end}}</pre>
         {{end}}
         </div>
       {{end}}

However could you tell me how would be the best way to fix it? Maybe in the method where we generate the URL with fragments? Or maybe some defensive logic in the template to avoid issues when the LineNum doesn't exist?

I suspect this will break links for github/gitiles etc., so the change should be somewhere else. I can have a look this week.

oh great, indeed a better place to fix it.

I already submitted it. The real source of truth is actually https://gerrit.googlesource.com/zoekt (I mirror to github every once in a while.)

@hanwen can it be set to automatically mirror?

@hanwen can it be set to automatically mirror?

yup, maybe i'm missing something, but I wasn't able to go get on gerrit..

I actually work in the infrastructure that powers googlesource.com, and we should set up something automatic, but there's so many other important things to do, so it keeps slipping. The same for "go get" support.

ok, thank you for your hard work and support. If any help is needed, the community is here for that!

you're welcome. FWIW, I didnt know I had a community (much less that there are any other instances besides cs.bazel.build). If you have feedback of zoekt in practice, I'd love to hear it.

commit 128ced7
Author: Han-Wen Nienhuys hanwen@google.com
Date: Tue May 30 18:20:09 2017 +0200

web: don't auto focus the search box on the file print page

This fixes #fragment links in -print mode.

Change-Id: I0a8f255167f43ffa7597a3e3f8f3b910d4b363b3

commit 643f171
Author: Han-Wen Nienhuys hanwen@google.com
Date: Tue May 30 18:19:13 2017 +0200

web: populate the fragment in -print mode

Change-Id: I68d8f13e0cfbdc09f0ff8361b0111167ca601f87