1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:04:44 -07:00

godoc: line numbers for all remote search results

Instead of returning the index lookup result via
RPC which has to be corrected for the client,
simply render it on the server and return the
final output.

R=rsc, r
CC=golang-dev
https://golang.org/cl/669041
This commit is contained in:
Robert Griesemer 2010-03-19 22:48:08 -07:00
parent e8fb0b014c
commit 6c8fdbe8c7
3 changed files with 15 additions and 10 deletions

View File

@ -1,4 +1,5 @@
QUERY = {Query}
QUERY
{Query}
{.section Accurate}
{.or}

View File

@ -746,8 +746,9 @@ func infoLineFmt(w io.Writer, x interface{}, format string) {
line = index.(*Index).Snippet(line).Line
} else {
// no line information available because
// we don't have an index
// TODO(gri) Fix this for remote search
// we don't have an index - this should
// never happen; be conservative and don't
// crash
line = 0
}
}
@ -1392,10 +1393,15 @@ type Query struct {
}
type Result struct {
Result []byte
}
type IndexServer struct{}
func (s *IndexServer) Lookup(query *Query, result *SearchResult) os.Error {
*result = lookup(query.Query)
func (s *IndexServer) Lookup(query *Query, result *Result) os.Error {
result.Result = applyTemplate(searchText, "searchText", lookup(query.Query))
return nil
}

View File

@ -158,7 +158,7 @@ func loggingHandler(h http.Handler) http.Handler {
}
func remoteLookup(query string) (result *SearchResult, err os.Error) {
func remoteLookup(query string) (result *Result, err os.Error) {
var client *rpc.Client
if *serverAddr != "" {
// try server only
@ -178,7 +178,7 @@ func remoteLookup(query string) (result *SearchResult, err os.Error) {
}
}
result = new(SearchResult)
result = new(Result)
err = client.Call("IndexServer.Lookup", &Query{query}, result)
if err != nil {
return nil, err
@ -281,9 +281,7 @@ func main() {
if err != nil {
log.Exitf("remoteLookup: %s", err)
}
if err := searchText.Execute(result, os.Stdout); err != nil {
log.Exitf("searchText.Execute: %s", err)
}
os.Stdout.Write(result.Result)
}
return
}