gopls/internal/lsp: remove redundant conversions

(I was motivated by the DocumentURI cleanup, but found
a number of others too.)

Change-Id: Ic02c7ce71ab64ad21737b078121e9c4d7acee73b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/543440
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/doc/generate.go b/gopls/doc/generate.go
index 34034fb..0c6ef3b 100644
--- a/gopls/doc/generate.go
+++ b/gopls/doc/generate.go
@@ -730,7 +730,7 @@
 func strMultiply(str string, count int) string {
 	var result string
 	for i := 0; i < count; i++ {
-		result += string(str)
+		result += str
 	}
 	return result
 }
diff --git a/gopls/internal/cmd/cmd.go b/gopls/internal/cmd/cmd.go
index bff10ee..69b703b 100644
--- a/gopls/internal/cmd/cmd.go
+++ b/gopls/internal/cmd/cmd.go
@@ -672,7 +672,7 @@
 	var success bool
 	if params.External {
 		// Open URI in external browser.
-		success = browser.Open(string(params.URI))
+		success = browser.Open(params.URI)
 	} else {
 		// Open file in editor, optionally taking focus and selecting a range.
 		// (cmdClient has no editor. Should it fork+exec $EDITOR?)
diff --git a/gopls/internal/lsp/cache/errors.go b/gopls/internal/lsp/cache/errors.go
index 36e3e9e..e5f6ec6 100644
--- a/gopls/internal/lsp/cache/errors.go
+++ b/gopls/internal/lsp/cache/errors.go
@@ -61,7 +61,7 @@
 			return protocol.Location{}, err
 		}
 		return protocol.Location{
-			URI: protocol.DocumentURI(uri),
+			URI: uri,
 			Range: protocol.Range{
 				Start: posn,
 				End:   posn,
@@ -95,7 +95,7 @@
 		return diags, nil
 	}
 	return []*source.Diagnostic{{
-		URI:      protocol.DocumentURI(loc.URI),
+		URI:      loc.URI,
 		Range:    loc.Range,
 		Severity: protocol.SeverityError,
 		Source:   source.ListError,
@@ -406,7 +406,7 @@
 	for _, fix := range diag.SuggestedFixes {
 		edits := make(map[protocol.DocumentURI][]protocol.TextEdit)
 		for _, e := range fix.TextEdits {
-			uri := protocol.DocumentURI(e.Location.URI)
+			uri := e.Location.URI
 			edits[uri] = append(edits[uri], protocol.TextEdit{
 				Range:   e.Location.Range,
 				NewText: string(e.NewText),
diff --git a/gopls/internal/lsp/cache/load.go b/gopls/internal/lsp/cache/load.go
index a4d6b94..00538bb 100644
--- a/gopls/internal/lsp/cache/load.go
+++ b/gopls/internal/lsp/cache/load.go
@@ -85,7 +85,7 @@
 		case moduleLoadScope:
 			modQuery := fmt.Sprintf("%s%c...", scope.dir, filepath.Separator)
 			query = append(query, modQuery)
-			moduleQueries[modQuery] = string(scope.modulePath)
+			moduleQueries[modQuery] = scope.modulePath
 
 		case viewLoadScope:
 			// If we are outside of GOPATH, a module, or some other known
diff --git a/gopls/internal/lsp/fake/workdir.go b/gopls/internal/lsp/fake/workdir.go
index f45aec6..3e18e97 100644
--- a/gopls/internal/lsp/fake/workdir.go
+++ b/gopls/internal/lsp/fake/workdir.go
@@ -55,7 +55,7 @@
 	}
 	backoff := 1 * time.Millisecond
 	for {
-		err := os.WriteFile(fp, []byte(content), 0644)
+		err := os.WriteFile(fp, content, 0644)
 		if err != nil {
 			// This lock file violation is not handled by the robustio package, as it
 			// indicates a real race condition that could be avoided.
@@ -275,7 +275,7 @@
 			// the error from Rename may be accurate.
 			return renameErr
 		}
-		if writeErr := writeFileData(newPath, []byte(content), w.RelativeTo); writeErr != nil {
+		if writeErr := writeFileData(newPath, content, w.RelativeTo); writeErr != nil {
 			// At this point we have tried to actually write the file.
 			// If it still doesn't exist, assume that the error from Rename was accurate:
 			// for example, maybe we don't have permission to create the new path.
diff --git a/gopls/internal/lsp/mod/diagnostics.go b/gopls/internal/lsp/mod/diagnostics.go
index 88ce7f8..1f2d7fc 100644
--- a/gopls/internal/lsp/mod/diagnostics.go
+++ b/gopls/internal/lsp/mod/diagnostics.go
@@ -440,7 +440,7 @@
 func suggestGovulncheckAction(fromGovulncheck bool, uri protocol.DocumentURI) (source.SuggestedFix, error) {
 	if fromGovulncheck {
 		resetVulncheck, err := command.NewResetGoModDiagnosticsCommand("Reset govulncheck result", command.ResetGoModDiagnosticsArgs{
-			URIArg:           command.URIArg{URI: protocol.DocumentURI(uri)},
+			URIArg:           command.URIArg{URI: uri},
 			DiagnosticSource: string(source.Govulncheck),
 		})
 		if err != nil {
@@ -449,7 +449,7 @@
 		return source.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
 	}
 	vulncheck, err := command.NewRunGovulncheckCommand("Run govulncheck to verify", command.VulncheckArgs{
-		URI:     protocol.DocumentURI(uri),
+		URI:     uri,
 		Pattern: "./...",
 	})
 	if err != nil {
diff --git a/gopls/internal/lsp/regtest/marker.go b/gopls/internal/lsp/regtest/marker.go
index 1154e85..a96b409 100644
--- a/gopls/internal/lsp/regtest/marker.go
+++ b/gopls/internal/lsp/regtest/marker.go
@@ -1966,7 +1966,7 @@
 	editMap, err := env.Editor.Server.Rename(env.Ctx, &protocol.RenameParams{
 		TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
 		Position:     loc.Range.Start,
-		NewName:      string(newName),
+		NewName:      newName,
 	})
 	if err != nil {
 		return nil, err
diff --git a/gopls/internal/lsp/source/rename.go b/gopls/internal/lsp/source/rename.go
index 5338d60..4075436 100644
--- a/gopls/internal/lsp/source/rename.go
+++ b/gopls/internal/lsp/source/rename.go
@@ -701,7 +701,7 @@
 				replacedPath = filepath.Join(modFileDir, r.New.Path)
 			}
 
-			suffix := strings.TrimPrefix(replacedPath, string(oldBase))
+			suffix := strings.TrimPrefix(replacedPath, oldBase)
 
 			newReplacedPath, err := filepath.Rel(modFileDir, newPkgDir+suffix)
 			if err != nil {
@@ -807,7 +807,7 @@
 
 		pkgName := m.Name
 		if m.PkgPath == oldPkgPath {
-			pkgName = PackageName(newName)
+			pkgName = newName
 
 			if err := renamePackageClause(ctx, m, s, newName, edits); err != nil {
 				return nil, err
diff --git a/gopls/internal/lsp/template/completion.go b/gopls/internal/lsp/template/completion.go
index 46cc489..fbb2744 100644
--- a/gopls/internal/lsp/template/completion.go
+++ b/gopls/internal/lsp/template/completion.go
@@ -94,7 +94,7 @@
 		}
 		// If the interval [x,offset] does not contain Left or Right
 		// then provide completions. (do we need the test for Right?)
-		if !bytes.Contains(fc.buf[x:offset], []byte(Left)) && !bytes.Contains(fc.buf[x:offset], []byte(Right)) {
+		if !bytes.Contains(fc.buf[x:offset], Left) && !bytes.Contains(fc.buf[x:offset], Right) {
 			return x
 		}
 	}
@@ -127,7 +127,7 @@
 	if len(words) == 0 {
 		return nil, nil // if this happens, why were we called?
 	}
-	pattern := string(words[len(words)-1])
+	pattern := words[len(words)-1]
 	if pattern[0] == '$' {
 		// should we also return a raw "$"?
 		for _, s := range c.syms {
@@ -156,7 +156,7 @@
 	// could we get completion attempts in strings or numbers, and if so, do we care?
 	// globals
 	for _, kw := range globals {
-		if weakMatch(kw, string(pattern)) != 0 {
+		if weakMatch(kw, pattern) != 0 {
 			ans.Items = append(ans.Items, protocol.CompletionItem{
 				Label:  kw,
 				Kind:   protocol.KeywordCompletion,
@@ -177,7 +177,7 @@
 	// keywords if we're at the beginning
 	if len(words) <= 1 || len(words[len(words)-2]) == 1 && words[len(words)-2][0] == '|' {
 		for _, kw := range keywords {
-			if weakMatch(kw, string(pattern)) != 0 {
+			if weakMatch(kw, pattern) != 0 {
 				ans.Items = append(ans.Items, protocol.CompletionItem{
 					Label:  kw,
 					Kind:   protocol.KeywordCompletion,
diff --git a/gopls/internal/lsp/template/implementations.go b/gopls/internal/lsp/template/implementations.go
index ff2f26d..7f081de 100644
--- a/gopls/internal/lsp/template/implementations.go
+++ b/gopls/internal/lsp/template/implementations.go
@@ -86,7 +86,7 @@
 			if !s.vardef || s.name != sym {
 				continue
 			}
-			ans = append(ans, protocol.Location{URI: protocol.DocumentURI(k), Range: p.Range(s.start, s.length)})
+			ans = append(ans, protocol.Location{URI: k, Range: p.Range(s.start, s.length)})
 		}
 	}
 	return ans, nil
@@ -139,7 +139,7 @@
 			if s.vardef && !params.Context.IncludeDeclaration {
 				continue
 			}
-			ans = append(ans, protocol.Location{URI: protocol.DocumentURI(k), Range: p.Range(s.start, s.length)})
+			ans = append(ans, protocol.Location{URI: k, Range: p.Range(s.start, s.length)})
 		}
 	}
 	// do these need to be sorted? (a.files is a map)
diff --git a/gopls/internal/lsp/template/symbols.go b/gopls/internal/lsp/template/symbols.go
index 1d1d988..356705f 100644
--- a/gopls/internal/lsp/template/symbols.go
+++ b/gopls/internal/lsp/template/symbols.go
@@ -180,7 +180,7 @@
 			break
 		}
 		// nothing to report, but build one for hover
-		sz := utf8.RuneCount([]byte(x.Text))
+		sz := utf8.RuneCount(x.Text)
 		p.symbols = append(p.symbols, symbol{start: int(x.Pos), length: sz, kind: protocol.Constant})
 	case *parse.VariableNode:
 		p.symbols = append(p.symbols, p.fields(x.Ident, x)...)