]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: proper file path conversion for remote search
authorRobert Griesemer <gri@golang.org>
Sat, 20 Mar 2010 00:07:16 +0000 (17:07 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 20 Mar 2010 00:07:16 +0000 (17:07 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/664041

lib/godoc/search.txt
src/cmd/godoc/godoc.go

index 46f7ae478e0c866231d1e4edebe4a388efd618c2..5724da404dc03c2fb88ac857b851e307b454403b 100644 (file)
@@ -1,4 +1,5 @@
-QUERY = {Query}
+QUERY
+{Query}
 
 {.section Accurate}
 {.or}
@@ -21,7 +22,7 @@ package {Pak.Name}
 {.repeated section Files}
 {.repeated section Groups}
 {.repeated section Infos}
-       {File.Path|url-src}:{@|infoLine}
+       {File.Path}:{@|infoLine}
 {.end}
 {.end}
 {.end}
@@ -36,7 +37,7 @@ package {Pak.Name}
 {.repeated section Files}
 {.repeated section Groups}
 {.repeated section Infos}
-       {File.Path|url-src}:{@|infoLine}
+       {File.Path}:{@|infoLine}
 {.end}
 {.end}
 {.end}
index ab45880464618455366ce9d56c8632052cb91f15..1baa6f2c65a95128c3cbdba4e75cf31ec3e85409 100644 (file)
@@ -1394,5 +1394,29 @@ type IndexServer struct{}
 
 func (s *IndexServer) Lookup(query *Query, result *SearchResult) os.Error {
        *result = lookup(query.Query)
+       if hit := result.Hit; hit != nil {
+               // the hitlists contain absolute server file paths;
+               // convert them into relative paths on the server
+               // because the client usually has a different file
+               // mapping
+               mapHitList(hit.Decls)
+               mapHitList(hit.Others)
+       }
        return nil
 }
+
+
+func mapHitList(list HitList) {
+       for _, prun := range list {
+               for _, frun := range prun.Files {
+                       // convert absolute file paths to relative paths
+                       f := frun.File
+                       if f != nil && len(f.Path) > 0 && f.Path[0] == '/' {
+                               f.Path = relativePath(f.Path)
+                       }
+                       // TODO(gri) convert SpotInfos containing snippets
+                       //           so that the line number is available
+                       //           on the client side
+               }
+       }
+}