internal/lsp: clean up unused parameters

Noticed these when I enabled the "unusedparams" analyzer. Not really
necessary to fix most of them, but seemed harmless.

Change-Id: I77c6e5f7c79f1abb701cd3332642486c34049736
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263203
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/lsp/source/completion/completion_format.go b/internal/lsp/source/completion/completion_format.go
index 878beba..a6b7e11 100644
--- a/internal/lsp/source/completion/completion_format.go
+++ b/internal/lsp/source/completion/completion_format.go
@@ -56,7 +56,7 @@
 	// expandFuncCall mutates the completion label, detail, and snippet
 	// to that of an invocation of sig.
 	expandFuncCall := func(sig *types.Signature) {
-		s := source.NewSignature(ctx, c.snapshot, c.pkg, c.file, "", sig, nil, c.qf)
+		s := source.NewSignature(ctx, c.snapshot, c.pkg, sig, nil, c.qf)
 		snip = c.functionCallSnippet(label, s.Params())
 		detail = "func" + s.Format()
 	}
@@ -70,7 +70,7 @@
 		if _, ok := obj.Type().(*types.Struct); ok {
 			detail = "struct{...}" // for anonymous structs
 		} else if obj.IsField() {
-			detail = source.FormatVarType(ctx, c.snapshot, c.pkg, c.file, obj, c.qf)
+			detail = source.FormatVarType(ctx, c.snapshot, c.pkg, obj, c.qf)
 		}
 		if obj.IsField() {
 			kind = protocol.FieldCompletion
@@ -207,7 +207,7 @@
 		return item, nil
 	}
 
-	hover, err := source.HoverInfo(pkg, obj, decl)
+	hover, err := source.HoverInfo(ctx, pkg, obj, decl)
 	if err != nil {
 		event.Error(ctx, "failed to find Hover", err, tag.URI.Of(uri))
 		return item, nil
diff --git a/internal/lsp/source/completion/completion_literal.go b/internal/lsp/source/completion/completion_literal.go
index e7ebc6e..2c75310 100644
--- a/internal/lsp/source/completion/completion_literal.go
+++ b/internal/lsp/source/completion/completion_literal.go
@@ -211,7 +211,7 @@
 			// If the param has no name in the signature, guess a name based
 			// on the type. Use an empty qualifier to ignore the package.
 			// For example, we want to name "http.Request" "r", not "hr".
-			name = source.FormatVarType(ctx, c.snapshot, c.pkg, c.file, p, func(p *types.Package) string {
+			name = source.FormatVarType(ctx, c.snapshot, c.pkg, p, func(p *types.Package) string {
 				return ""
 			})
 			name = abbreviateTypeName(name)
@@ -265,7 +265,7 @@
 		// of "i int, j int".
 		if i == sig.Params().Len()-1 || !types.Identical(p.Type(), sig.Params().At(i+1).Type()) {
 			snip.WriteText(" ")
-			typeStr := source.FormatVarType(ctx, c.snapshot, c.pkg, c.file, p, c.qf)
+			typeStr := source.FormatVarType(ctx, c.snapshot, c.pkg, p, c.qf)
 			if sig.Variadic() && i == sig.Params().Len()-1 {
 				typeStr = strings.Replace(typeStr, "[]", "...", 1)
 			}
@@ -293,7 +293,7 @@
 		if name := r.Name(); name != "" {
 			snip.WriteText(name + " ")
 		}
-		snip.WriteText(source.FormatVarType(ctx, c.snapshot, c.pkg, c.file, r, c.qf))
+		snip.WriteText(source.FormatVarType(ctx, c.snapshot, c.pkg, r, c.qf))
 	}
 	if resultsNeedParens {
 		snip.WriteText(")")
diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go
index 5388862..c1f5826 100644
--- a/internal/lsp/source/diagnostics.go
+++ b/internal/lsp/source/diagnostics.go
@@ -62,7 +62,7 @@
 	// Prepare the reports we will send for the files in this package.
 	reports := make(map[VersionedFileIdentity][]*Diagnostic)
 	for _, pgf := range pkg.CompiledGoFiles() {
-		clearReports(ctx, snapshot, reports, pgf.URI)
+		clearReports(snapshot, reports, pgf.URI)
 	}
 	// Prepare any additional reports for the errors in this package.
 	for _, e := range pkg.GetErrors() {
@@ -78,7 +78,7 @@
 				}
 			}
 		}
-		clearReports(ctx, snapshot, reports, e.URI)
+		clearReports(snapshot, reports, e.URI)
 	}
 	// Run diagnostics for the package that this URI belongs to.
 	hadDiagnostics, hadTypeErrors, err := diagnostics(ctx, snapshot, reports, pkg, len(pkg.MissingDependencies()) > 0)
@@ -195,7 +195,7 @@
 		} else if len(set.typeErrors) > 0 {
 			hasTypeErrors = true
 		}
-		if err := addReports(ctx, snapshot, reports, uri, diags...); err != nil {
+		if err := addReports(snapshot, reports, uri, diags...); err != nil {
 			return false, false, err
 		}
 	}
@@ -221,7 +221,7 @@
 		// meant to provide diagnostics, but rather only suggested fixes.
 		// Skip these types of errors in diagnostics; we will use their
 		// suggested fixes when providing code actions.
-		if isConvenienceAnalyzer(snapshot.View().Options(), e.Category) {
+		if isConvenienceAnalyzer(e.Category) {
 			continue
 		}
 		// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
@@ -231,7 +231,7 @@
 		if onlyDeletions(e.SuggestedFixes) {
 			tags = append(tags, protocol.Unnecessary)
 		}
-		if err := addReports(ctx, snapshot, reports, e.URI, &Diagnostic{
+		if err := addReports(snapshot, reports, e.URI, &Diagnostic{
 			Range:    e.Range,
 			Message:  e.Message,
 			Source:   e.Category,
@@ -245,7 +245,7 @@
 	return nil
 }
 
-func clearReports(ctx context.Context, snapshot Snapshot, reports map[VersionedFileIdentity][]*Diagnostic, uri span.URI) {
+func clearReports(snapshot Snapshot, reports map[VersionedFileIdentity][]*Diagnostic, uri span.URI) {
 	fh := snapshot.FindFile(uri)
 	if fh == nil {
 		return
@@ -253,7 +253,7 @@
 	reports[fh.VersionedFileIdentity()] = []*Diagnostic{}
 }
 
-func addReports(ctx context.Context, snapshot Snapshot, reports map[VersionedFileIdentity][]*Diagnostic, uri span.URI, diagnostics ...*Diagnostic) error {
+func addReports(snapshot Snapshot, reports map[VersionedFileIdentity][]*Diagnostic, uri span.URI, diagnostics ...*Diagnostic) error {
 	fh := snapshot.FindFile(uri)
 	if fh == nil {
 		return nil
@@ -312,7 +312,7 @@
 	return false
 }
 
-func isConvenienceAnalyzer(o *Options, category string) bool {
+func isConvenienceAnalyzer(category string) bool {
 	for _, a := range DefaultOptions().ConvenienceAnalyzers {
 		if category == a.Analyzer.Name {
 			return true
diff --git a/internal/lsp/source/extract.go b/internal/lsp/source/extract.go
index 411b465..4aee845 100644
--- a/internal/lsp/source/extract.go
+++ b/internal/lsp/source/extract.go
@@ -21,7 +21,7 @@
 	"golang.org/x/tools/internal/span"
 )
 
-func extractVariable(fset *token.FileSet, rng span.Range, src []byte, file *ast.File, pkg *types.Package, info *types.Info) (*analysis.SuggestedFix, error) {
+func extractVariable(fset *token.FileSet, rng span.Range, src []byte, file *ast.File, _ *types.Package, info *types.Info) (*analysis.SuggestedFix, error) {
 	expr, path, ok, err := canExtractVariable(rng, file)
 	if !ok {
 		return nil, fmt.Errorf("extractVariable: cannot extract %s: %v", fset.Position(rng.Start), err)
@@ -794,7 +794,7 @@
 
 // canExtractFunction reports whether the code in the given range can be
 // extracted to a function.
-func canExtractFunction(fset *token.FileSet, rng span.Range, src []byte, file *ast.File, info *types.Info) (*fnExtractParams, bool, error) {
+func canExtractFunction(fset *token.FileSet, rng span.Range, src []byte, file *ast.File, _ *types.Info) (*fnExtractParams, bool, error) {
 	if rng.Start == rng.End {
 		return nil, false, fmt.Errorf("start and end are equal")
 	}
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index 5d25d18..f4c6957 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -94,7 +94,7 @@
 		return nil, nil, err
 	}
 	if err := snapshot.RunProcessEnvFunc(ctx, func(opts *imports.Options) error {
-		allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot, pgf, opts)
+		allFixEdits, editsPerFix, err = computeImportEdits(snapshot, pgf, opts)
 		return err
 	}); err != nil {
 		return nil, nil, fmt.Errorf("AllImportsFixes: %v", err)
@@ -104,7 +104,7 @@
 
 // computeImportEdits computes a set of edits that perform one or all of the
 // necessary import fixes.
-func computeImportEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFile, options *imports.Options) (allFixEdits []protocol.TextEdit, editsPerFix []*ImportFix, err error) {
+func computeImportEdits(snapshot Snapshot, pgf *ParsedGoFile, options *imports.Options) (allFixEdits []protocol.TextEdit, editsPerFix []*ImportFix, err error) {
 	filename := pgf.URI.Filename()
 
 	// Build up basic information about the original file.
diff --git a/internal/lsp/source/gc_annotations.go b/internal/lsp/source/gc_annotations.go
index 1eee1ca..6494b6a 100644
--- a/internal/lsp/source/gc_annotations.go
+++ b/internal/lsp/source/gc_annotations.go
@@ -165,7 +165,7 @@
 
 func findJSONFiles(dir string) ([]string, error) {
 	ans := []string{}
-	f := func(path string, fi os.FileInfo, err error) error {
+	f := func(path string, fi os.FileInfo, _ error) error {
 		if fi.IsDir() {
 			return nil
 		}
diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go
index 5f91152..be6edb1 100644
--- a/internal/lsp/source/hover.go
+++ b/internal/lsp/source/hover.go
@@ -11,7 +11,6 @@
 	"go/ast"
 	"go/doc"
 	"go/format"
-	"go/token"
 	"go/types"
 	"strings"
 
@@ -87,7 +86,7 @@
 	defer done()
 
 	fset := i.Snapshot.FileSet()
-	h, err := hover(ctx, fset, i.pkg, i.Declaration)
+	h, err := HoverInfo(ctx, i.pkg, i.Declaration.obj, i.Declaration.node)
 	if err != nil {
 		return nil, err
 	}
@@ -229,16 +228,9 @@
 	return str
 }
 
-func hover(ctx context.Context, fset *token.FileSet, pkg Package, d Declaration) (*HoverInformation, error) {
-	_, done := event.Start(ctx, "source.hover")
-	defer done()
-
-	return HoverInfo(pkg, d.obj, d.node)
-}
-
 // HoverInfo returns a HoverInformation struct for an ast node and its type
 // object.
-func HoverInfo(pkg Package, obj types.Object, node ast.Node) (*HoverInformation, error) {
+func HoverInfo(ctx context.Context, pkg Package, obj types.Object, node ast.Node) (*HoverInformation, error) {
 	var info *HoverInformation
 
 	switch node := node.(type) {
diff --git a/internal/lsp/source/signature_help.go b/internal/lsp/source/signature_help.go
index ed0252c..b49880d 100644
--- a/internal/lsp/source/signature_help.go
+++ b/internal/lsp/source/signature_help.go
@@ -107,7 +107,7 @@
 			node: node,
 		}
 		decl.MappedRange = append(decl.MappedRange, rng)
-		d, err := hover(ctx, snapshot.FileSet(), pkg, decl)
+		d, err := HoverInfo(ctx, pkg, decl.obj, decl.node)
 		if err != nil {
 			return nil, 0, err
 		}
@@ -116,7 +116,7 @@
 	} else {
 		name = "func"
 	}
-	s := NewSignature(ctx, snapshot, pkg, pgf.File, name, sig, comment, qf)
+	s := NewSignature(ctx, snapshot, pkg, sig, comment, qf)
 	paramInfo := make([]protocol.ParameterInformation, 0, len(s.params))
 	for _, p := range s.params {
 		paramInfo = append(paramInfo, protocol.ParameterInformation{Label: p})
diff --git a/internal/lsp/source/types_format.go b/internal/lsp/source/types_format.go
index 9da19c8..2455bdf 100644
--- a/internal/lsp/source/types_format.go
+++ b/internal/lsp/source/types_format.go
@@ -160,11 +160,11 @@
 }
 
 // NewSignature returns formatted signature for a types.Signature struct.
-func NewSignature(ctx context.Context, s Snapshot, pkg Package, file *ast.File, name string, sig *types.Signature, comment *ast.CommentGroup, qf types.Qualifier) *signature {
+func NewSignature(ctx context.Context, s Snapshot, pkg Package, sig *types.Signature, comment *ast.CommentGroup, qf types.Qualifier) *signature {
 	params := make([]string, 0, sig.Params().Len())
 	for i := 0; i < sig.Params().Len(); i++ {
 		el := sig.Params().At(i)
-		typ := FormatVarType(ctx, s, pkg, file, el, qf)
+		typ := FormatVarType(ctx, s, pkg, el, qf)
 		p := typ
 		if el.Name() != "" {
 			p = el.Name() + " " + typ
@@ -178,7 +178,7 @@
 			needResultParens = true
 		}
 		el := sig.Results().At(i)
-		typ := FormatVarType(ctx, s, pkg, file, el, qf)
+		typ := FormatVarType(ctx, s, pkg, el, qf)
 		if el.Name() == "" {
 			results = append(results, typ)
 		} else {
@@ -204,7 +204,7 @@
 // FormatVarType formats a *types.Var, accounting for type aliases.
 // To do this, it looks in the AST of the file in which the object is declared.
 // On any errors, it always fallbacks back to types.TypeString.
-func FormatVarType(ctx context.Context, snapshot Snapshot, srcpkg Package, srcfile *ast.File, obj *types.Var, qf types.Qualifier) string {
+func FormatVarType(ctx context.Context, snapshot Snapshot, srcpkg Package, obj *types.Var, qf types.Qualifier) string {
 	pgf, pkg, err := FindPosInPackage(snapshot, srcpkg, obj.Pos())
 	if err != nil {
 		return types.TypeString(obj.Type(), qf)
@@ -224,7 +224,7 @@
 
 	// If the request came from a different package than the one in which the
 	// types are defined, we may need to modify the qualifiers.
-	qualified = qualifyExpr(snapshot.FileSet(), qualified, srcpkg, pkg, srcfile, clonedInfo, qf)
+	qualified = qualifyExpr(qualified, srcpkg, pkg, clonedInfo, qf)
 	fmted := FormatNode(snapshot.FileSet(), qualified)
 	return fmted
 }
@@ -247,7 +247,7 @@
 }
 
 // qualifyExpr applies the "pkgName." prefix to any *ast.Ident in the expr.
-func qualifyExpr(fset *token.FileSet, expr ast.Expr, srcpkg, pkg Package, file *ast.File, clonedInfo map[token.Pos]*types.PkgName, qf types.Qualifier) ast.Expr {
+func qualifyExpr(expr ast.Expr, srcpkg, pkg Package, clonedInfo map[token.Pos]*types.PkgName, qf types.Qualifier) ast.Expr {
 	ast.Inspect(expr, func(n ast.Node) bool {
 		switch n := n.(type) {
 		case *ast.ArrayType, *ast.ChanType, *ast.Ellipsis,