From a1a928ddbedd8082c24d6223aa9ce1f00f922286 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 1 Sep 2023 10:42:17 -0400 Subject: [PATCH] gopls: remove dead code This change removes functions reported as unreachable by internal/cmd/deadcode. Also, move the "generated" file marker to the correct positions. Change-Id: I56f3c056cd010914ac5d4e410f1ee4a44289cc77 Reviewed-on: https://go-review.googlesource.com/c/tools/+/524760 Run-TryBot: Alan Donovan Reviewed-by: Robert Findley Auto-Submit: Alan Donovan TryBot-Result: Gopher Robot --- gopls/internal/lsp/cmd/cmd.go | 9 ------- gopls/internal/lsp/command/command_gen.go | 4 +-- gopls/internal/lsp/command/gen/gen.go | 4 +-- gopls/internal/lsp/source/options.go | 8 ------ gopls/internal/lsp/tests/tests.go | 32 ----------------------- 5 files changed, 4 insertions(+), 53 deletions(-) diff --git a/gopls/internal/lsp/cmd/cmd.go b/gopls/internal/lsp/cmd/cmd.go index 2d637f29a70..267456bc4be 100644 --- a/gopls/internal/lsp/cmd/cmd.go +++ b/gopls/internal/lsp/cmd/cmd.go @@ -348,15 +348,6 @@ func (app *Application) connect(ctx context.Context, onProgress func(*protocol.P } } -// CloseTestConnections terminates shared connections used in command tests. It -// should only be called from tests. -func CloseTestConnections(ctx context.Context) { - for _, c := range internalConnections { - c.Shutdown(ctx) - c.Exit(ctx) - } -} - func (app *Application) connectRemote(ctx context.Context, remote string) (*connection, error) { conn, err := lsprpc.ConnectToRemote(ctx, remote) if err != nil { diff --git a/gopls/internal/lsp/command/command_gen.go b/gopls/internal/lsp/command/command_gen.go index 25a101cb36e..00b76579601 100644 --- a/gopls/internal/lsp/command/command_gen.go +++ b/gopls/internal/lsp/command/command_gen.go @@ -7,10 +7,10 @@ //go:build !generate // +build !generate -package command - // Code generated by generate.go. DO NOT EDIT. +package command + import ( "context" "fmt" diff --git a/gopls/internal/lsp/command/gen/gen.go b/gopls/internal/lsp/command/gen/gen.go index b3f89c8d773..9f0453c62cc 100644 --- a/gopls/internal/lsp/command/gen/gen.go +++ b/gopls/internal/lsp/command/gen/gen.go @@ -25,10 +25,10 @@ const src = `// Copyright 2021 The Go Authors. All rights reserved. //go:build !generate // +build !generate -package command - // Code generated by generate.go. DO NOT EDIT. +package command + import ( {{range $k, $v := .Imports -}} "{{$k}}" diff --git a/gopls/internal/lsp/source/options.go b/gopls/internal/lsp/source/options.go index 334cc9dc798..67818fad34a 100644 --- a/gopls/internal/lsp/source/options.go +++ b/gopls/internal/lsp/source/options.go @@ -1311,14 +1311,6 @@ func (e *SoftError) Error() string { return e.msg } -// softErrorf reports an error that does not affect the functionality of gopls -// (a warning in the UI). -// The formatted message will be shown to the user unmodified. -func (r *OptionResult) softErrorf(format string, values ...interface{}) { - msg := fmt.Sprintf(format, values...) - r.Error = &SoftError{msg} -} - // deprecated reports the current setting as deprecated. If 'replacement' is // non-nil, it is suggested to the user. func (r *OptionResult) deprecated(replacement string) { diff --git a/gopls/internal/lsp/tests/tests.go b/gopls/internal/lsp/tests/tests.go index 150bec9bc7b..4f5fc3c5080 100644 --- a/gopls/internal/lsp/tests/tests.go +++ b/gopls/internal/lsp/tests/tests.go @@ -1159,38 +1159,6 @@ func SpanName(spn span.Span) string { return fmt.Sprintf("%v_%v_%v", uriName(spn.URI()), spn.Start().Line(), spn.Start().Column()) } -func CopyFolderToTempDir(folder string) (string, error) { - if _, err := os.Stat(folder); err != nil { - return "", err - } - dst, err := ioutil.TempDir("", "modfile_test") - if err != nil { - return "", err - } - fds, err := ioutil.ReadDir(folder) - if err != nil { - return "", err - } - for _, fd := range fds { - srcfp := filepath.Join(folder, fd.Name()) - stat, err := os.Stat(srcfp) - if err != nil { - return "", err - } - if !stat.Mode().IsRegular() { - return "", fmt.Errorf("cannot copy non regular file %s", srcfp) - } - contents, err := ioutil.ReadFile(srcfp) - if err != nil { - return "", err - } - if err := ioutil.WriteFile(filepath.Join(dst, fd.Name()), contents, stat.Mode()); err != nil { - return "", err - } - } - return dst, nil -} - func shouldSkip(data *Data, uri span.URI) bool { if data.ModfileFlagAvailable { return false