1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:54:57 -07:00

internal/imports: add all interfaces in mkstdlib

In api/*.txt, interface declarations are represented with lines like:
  pkg container/heap, type Interface interface { Len, Less, Pop, Push, Swap }
or, when they have no exported methods:
  pkg go/ast, type Expr interface, unexported methods

The latter form confuses mkstdlib into thinking that it's a method
because of the extra comma, and then it skips the interface entirely.
Running this program is a matter of seconds once per release, so rather
than trying to fix the optimization, just remove it. The parsing logic
doesn't care about the extra lines.

And the corresponding change to the copy in lsp/testdata/unimported.

Updates golang/go#34199

Change-Id: Ic34b8a47537608401e4ef6683617d797f9f50f8a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194568
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Heschi Kreinick 2019-09-10 15:15:18 -04:00
parent 5e3480f0e0
commit d0542c01b0
3 changed files with 10 additions and 9 deletions

View File

@ -19,7 +19,6 @@ import (
"regexp" "regexp"
"runtime" "runtime"
"sort" "sort"
"strings"
) )
func mustOpen(name string) io.Reader { func mustOpen(name string) io.Reader {
@ -75,10 +74,6 @@ func main() {
for sc.Scan() { for sc.Scan() {
l := sc.Text() l := sc.Text()
has := func(v string) bool { return strings.Contains(l, v) }
if has("struct, ") || has("interface, ") || has(", method (") {
continue
}
if m := sym.FindStringSubmatch(l); m != nil { if m := sym.FindStringSubmatch(l); m != nil {
path, sym := m[1], m[2] path, sym := m[1], m[2]

View File

@ -2637,10 +2637,12 @@ var stdlib = map[string]map[string]bool{
"CommentMap": true, "CommentMap": true,
"CompositeLit": true, "CompositeLit": true,
"Con": true, "Con": true,
"Decl": true,
"DeclStmt": true, "DeclStmt": true,
"DeferStmt": true, "DeferStmt": true,
"Ellipsis": true, "Ellipsis": true,
"EmptyStmt": true, "EmptyStmt": true,
"Expr": true,
"ExprStmt": true, "ExprStmt": true,
"Field": true, "Field": true,
"FieldFilter": true, "FieldFilter": true,
@ -2701,7 +2703,9 @@ var stdlib = map[string]map[string]bool{
"SendStmt": true, "SendStmt": true,
"SliceExpr": true, "SliceExpr": true,
"SortImports": true, "SortImports": true,
"Spec": true,
"StarExpr": true, "StarExpr": true,
"Stmt": true,
"StructType": true, "StructType": true,
"SwitchStmt": true, "SwitchStmt": true,
"Typ": true, "Typ": true,
@ -2770,6 +2774,7 @@ var stdlib = map[string]map[string]bool{
"UnaryOp": true, "UnaryOp": true,
"Unknown": true, "Unknown": true,
"Val": true, "Val": true,
"Value": true,
}, },
"go/doc": map[string]bool{ "go/doc": map[string]bool{
"AllDecls": true, "AllDecls": true,
@ -3019,6 +3024,7 @@ var stdlib = map[string]map[string]bool{
"NewTypeName": true, "NewTypeName": true,
"NewVar": true, "NewVar": true,
"Nil": true, "Nil": true,
"Object": true,
"ObjectString": true, "ObjectString": true,
"Package": true, "Package": true,
"PkgName": true, "PkgName": true,
@ -4326,6 +4332,7 @@ var stdlib = map[string]map[string]bool{
"StructOf": true, "StructOf": true,
"StructTag": true, "StructTag": true,
"Swapper": true, "Swapper": true,
"Type": true,
"TypeOf": true, "TypeOf": true,
"Uint": true, "Uint": true,
"Uint16": true, "Uint16": true,
@ -8023,6 +8030,7 @@ var stdlib = map[string]map[string]bool{
"Rmdir": true, "Rmdir": true,
"RouteMessage": true, "RouteMessage": true,
"RouteRIB": true, "RouteRIB": true,
"RoutingMessage": true,
"RtAttr": true, "RtAttr": true,
"RtGenmsg": true, "RtGenmsg": true,
"RtMetrics": true, "RtMetrics": true,
@ -9391,6 +9399,7 @@ var stdlib = map[string]map[string]bool{
"SlicePtrFromStrings": true, "SlicePtrFromStrings": true,
"SockFilter": true, "SockFilter": true,
"SockFprog": true, "SockFprog": true,
"Sockaddr": true,
"SockaddrDatalink": true, "SockaddrDatalink": true,
"SockaddrGen": true, "SockaddrGen": true,
"SockaddrInet4": true, "SockaddrInet4": true,
@ -9863,6 +9872,7 @@ var stdlib = map[string]map[string]bool{
"RunTests": true, "RunTests": true,
"Short": true, "Short": true,
"T": true, "T": true,
"TB": true,
"Verbose": true, "Verbose": true,
}, },
"testing/iotest": map[string]bool{ "testing/iotest": map[string]bool{

View File

@ -72,10 +72,6 @@ func main() {
paths := []string{"unsafe", "syscall/js"} paths := []string{"unsafe", "syscall/js"}
for sc.Scan() { for sc.Scan() {
l := sc.Text() l := sc.Text()
has := func(v string) bool { return strings.Contains(l, v) }
if has("struct, ") || has("interface, ") || has(", method (") {
continue
}
if m := sym.FindStringSubmatch(l); m != nil { if m := sym.FindStringSubmatch(l); m != nil {
path, _ := m[1], m[2] path, _ := m[1], m[2]