From d0542c01b04d73cee88be0cd7343c19d9d157525 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Tue, 10 Sep 2019 15:15:18 -0400 Subject: [PATCH] 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 --- internal/imports/mkstdlib.go | 5 ----- internal/imports/zstdlib.go | 10 ++++++++++ internal/lsp/testdata/unimported/mkunimported.go | 4 ---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/imports/mkstdlib.go b/internal/imports/mkstdlib.go index 43fdddb4ad..fa69eebb7e 100644 --- a/internal/imports/mkstdlib.go +++ b/internal/imports/mkstdlib.go @@ -19,7 +19,6 @@ import ( "regexp" "runtime" "sort" - "strings" ) func mustOpen(name string) io.Reader { @@ -75,10 +74,6 @@ func main() { for sc.Scan() { 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 { path, sym := m[1], m[2] diff --git a/internal/imports/zstdlib.go b/internal/imports/zstdlib.go index 78fac48cb5..544339e53b 100644 --- a/internal/imports/zstdlib.go +++ b/internal/imports/zstdlib.go @@ -2637,10 +2637,12 @@ var stdlib = map[string]map[string]bool{ "CommentMap": true, "CompositeLit": true, "Con": true, + "Decl": true, "DeclStmt": true, "DeferStmt": true, "Ellipsis": true, "EmptyStmt": true, + "Expr": true, "ExprStmt": true, "Field": true, "FieldFilter": true, @@ -2701,7 +2703,9 @@ var stdlib = map[string]map[string]bool{ "SendStmt": true, "SliceExpr": true, "SortImports": true, + "Spec": true, "StarExpr": true, + "Stmt": true, "StructType": true, "SwitchStmt": true, "Typ": true, @@ -2770,6 +2774,7 @@ var stdlib = map[string]map[string]bool{ "UnaryOp": true, "Unknown": true, "Val": true, + "Value": true, }, "go/doc": map[string]bool{ "AllDecls": true, @@ -3019,6 +3024,7 @@ var stdlib = map[string]map[string]bool{ "NewTypeName": true, "NewVar": true, "Nil": true, + "Object": true, "ObjectString": true, "Package": true, "PkgName": true, @@ -4326,6 +4332,7 @@ var stdlib = map[string]map[string]bool{ "StructOf": true, "StructTag": true, "Swapper": true, + "Type": true, "TypeOf": true, "Uint": true, "Uint16": true, @@ -8023,6 +8030,7 @@ var stdlib = map[string]map[string]bool{ "Rmdir": true, "RouteMessage": true, "RouteRIB": true, + "RoutingMessage": true, "RtAttr": true, "RtGenmsg": true, "RtMetrics": true, @@ -9391,6 +9399,7 @@ var stdlib = map[string]map[string]bool{ "SlicePtrFromStrings": true, "SockFilter": true, "SockFprog": true, + "Sockaddr": true, "SockaddrDatalink": true, "SockaddrGen": true, "SockaddrInet4": true, @@ -9863,6 +9872,7 @@ var stdlib = map[string]map[string]bool{ "RunTests": true, "Short": true, "T": true, + "TB": true, "Verbose": true, }, "testing/iotest": map[string]bool{ diff --git a/internal/lsp/testdata/unimported/mkunimported.go b/internal/lsp/testdata/unimported/mkunimported.go index 80915c90b6..d4210b0c38 100644 --- a/internal/lsp/testdata/unimported/mkunimported.go +++ b/internal/lsp/testdata/unimported/mkunimported.go @@ -72,10 +72,6 @@ func main() { paths := []string{"unsafe", "syscall/js"} for sc.Scan() { 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 { path, _ := m[1], m[2]