gopls: more 1.18 cleanup; use strings.Cut and os functions

Change-Id: Id2be028f3af23877d7707d3d883d5e05ee2b59a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/524839
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
diff --git a/gopls/internal/lsp/cache/cycle_test.go b/gopls/internal/lsp/cache/cycle_test.go
index d08e8e0..25edbbf 100644
--- a/gopls/internal/lsp/cache/cycle_test.go
+++ b/gopls/internal/lsp/cache/cycle_test.go
@@ -76,7 +76,7 @@
 		}
 		if s != "" {
 			for _, item := range strings.Split(s, ";") {
-				nodeID, succIDs, ok := cut(item, "->")
+				nodeID, succIDs, ok := strings.Cut(item, "->")
 				node := makeNode(nodeID)
 				if ok {
 					for _, succID := range strings.Split(succIDs, ",") {
diff --git a/gopls/internal/lsp/cache/snapshot.go b/gopls/internal/lsp/cache/snapshot.go
index cbc9c6e..a1fe475 100644
--- a/gopls/internal/lsp/cache/snapshot.go
+++ b/gopls/internal/lsp/cache/snapshot.go
@@ -1874,20 +1874,12 @@
 // Most likely, each call site of inVendor needs to be reconsidered to
 // understand and correctly implement the desired behavior.
 func inVendor(uri span.URI) bool {
-	_, after, found := cut(string(uri), "/vendor/")
+	_, after, found := strings.Cut(string(uri), "/vendor/")
 	// Only subdirectories of /vendor/ are considered vendored
 	// (/vendor/a/foo.go is vendored, /vendor/foo.go is not).
 	return found && strings.Contains(after, "/")
 }
 
-// TODO(adonovan): replace with strings.Cut when we can assume go1.18.
-func cut(s, sep string) (before, after string, found bool) {
-	if i := strings.Index(s, sep); i >= 0 {
-		return s[:i], s[i+len(sep):], true
-	}
-	return s, "", false
-}
-
 // unappliedChanges is a file source that handles an uncloned snapshot.
 type unappliedChanges struct {
 	originalSnapshot *snapshot
diff --git a/gopls/internal/lsp/lru/lru.go b/gopls/internal/lsp/lru/lru.go
index 5750f41..b75fc85 100644
--- a/gopls/internal/lsp/lru/lru.go
+++ b/gopls/internal/lsp/lru/lru.go
@@ -11,8 +11,6 @@
 	"sync"
 )
 
-type any = interface{} // TODO: remove once gopls only builds at go1.18+
-
 // A Cache is a fixed-size in-memory LRU cache.
 type Cache struct {
 	capacity int
diff --git a/gopls/internal/lsp/lru/lru_test.go b/gopls/internal/lsp/lru/lru_test.go
index 165a647..a9e6407 100644
--- a/gopls/internal/lsp/lru/lru_test.go
+++ b/gopls/internal/lsp/lru/lru_test.go
@@ -17,8 +17,6 @@
 	"golang.org/x/tools/gopls/internal/lsp/lru"
 )
 
-type any = interface{} // TODO: remove once gopls only builds at go1.18+
-
 func TestCache(t *testing.T) {
 	type get struct {
 		key  string
diff --git a/gopls/internal/lsp/regtest/marker.go b/gopls/internal/lsp/regtest/marker.go
index 1c364bd..36dcda3 100644
--- a/gopls/internal/lsp/regtest/marker.go
+++ b/gopls/internal/lsp/regtest/marker.go
@@ -746,8 +746,7 @@
 			test.env = make(map[string]string)
 			fields := strings.Fields(string(file.Data))
 			for _, field := range fields {
-				// TODO: use strings.Cut once we are on 1.18+.
-				key, value, ok := cut(field, "=")
+				key, value, ok := strings.Cut(field, "=")
 				if !ok {
 					return nil, fmt.Errorf("env vars must be formatted as var=value, got %q", field)
 				}
@@ -755,7 +754,7 @@
 			}
 
 		case strings.HasPrefix(file.Name, "@"): // golden content
-			id, name, _ := cut(file.Name[len("@"):], "/")
+			id, name, _ := strings.Cut(file.Name[len("@"):], "/")
 			// Note that a file.Name of just "@id" gives (id, name) = ("id", "").
 			if _, ok := test.golden[id]; !ok {
 				test.golden[id] = &Golden{
@@ -800,16 +799,6 @@
 	return test, nil
 }
 
-// cut is a copy of strings.Cut.
-//
-// TODO: once we only support Go 1.18+, just use strings.Cut.
-func cut(s, sep string) (before, after string, found bool) {
-	if i := strings.Index(s, sep); i >= 0 {
-		return s[:i], s[i+len(sep):], true
-	}
-	return s, "", false
-}
-
 // formatTest formats the test as a txtar archive.
 func formatTest(test *markerTest) ([]byte, error) {
 	arch := &txtar.Archive{
diff --git a/gopls/internal/lsp/regtest/regtest.go b/gopls/internal/lsp/regtest/regtest.go
index 02c0ad0..7def1d7 100644
--- a/gopls/internal/lsp/regtest/regtest.go
+++ b/gopls/internal/lsp/regtest/regtest.go
@@ -8,7 +8,6 @@
 	"context"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"runtime"
 	"testing"
@@ -133,7 +132,7 @@
 		}
 	}
 
-	dir, err := ioutil.TempDir("", "gopls-regtest-")
+	dir, err := os.MkdirTemp("", "gopls-regtest-")
 	if err != nil {
 		panic(fmt.Errorf("creating regtest temp directory: %v", err))
 	}
diff --git a/gopls/internal/lsp/regtest/runner.go b/gopls/internal/lsp/regtest/runner.go
index 4f085e7..e4aa2f3 100644
--- a/gopls/internal/lsp/regtest/runner.go
+++ b/gopls/internal/lsp/regtest/runner.go
@@ -9,7 +9,6 @@
 	"context"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net"
 	"os"
 	"path/filepath"
@@ -370,7 +369,7 @@
 	}
 
 	r.startRemoteOnce.Do(func() {
-		socketDir, err := ioutil.TempDir(r.tempDir, "gopls-regtest-socket")
+		socketDir, err := os.MkdirTemp(r.tempDir, "gopls-regtest-socket")
 		if err != nil {
 			r.remoteErr = err
 			return