Commit f6f5ce87 authored by Robert Griesemer's avatar Robert Griesemer

godoc: fix identifier search

Thanks to Andrey Mirtchovski for tracking this down.

This was broken by CL 5528077 which removed the InsertSemis
flag from go/scanner - as a result, semicolons are now always
inserted and the respective indexer code checked for the
wrong token.

Replaced the code by a direct identifier test.

R=rsc
CC=golang-dev
https://golang.org/cl/5606065
parent bd41831f
...@@ -44,7 +44,6 @@ import ( ...@@ -44,7 +44,6 @@ import (
"errors" "errors"
"go/ast" "go/ast"
"go/parser" "go/parser"
"go/scanner"
"go/token" "go/token"
"index/suffixarray" "index/suffixarray"
"io" "io"
...@@ -54,6 +53,7 @@ import ( ...@@ -54,6 +53,7 @@ import (
"sort" "sort"
"strings" "strings"
"time" "time"
"unicode"
) )
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -921,15 +921,15 @@ func (x *Index) lookupWord(w string) (match *LookupResult, alt *AltWords) { ...@@ -921,15 +921,15 @@ func (x *Index) lookupWord(w string) (match *LookupResult, alt *AltWords) {
return return
} }
// isIdentifier reports whether s is a Go identifier.
func isIdentifier(s string) bool { func isIdentifier(s string) bool {
var S scanner.Scanner for i, ch := range s {
fset := token.NewFileSet() if unicode.IsLetter(ch) || ch == ' ' || i > 0 && unicode.IsDigit(ch) {
S.Init(fset.AddFile("", fset.Base(), len(s)), []byte(s), nil, 0) continue
if _, tok, _ := S.Scan(); tok == token.IDENT { }
_, tok, _ := S.Scan() return false
return tok == token.EOF
} }
return false return len(s) > 0
} }
// For a given query, which is either a single identifier or a qualified // For a given query, which is either a single identifier or a qualified
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment