Skip to content

Commit 00a4006

Browse files
committed
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 <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 1b54dd7 commit 00a4006

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

gopls/doc/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ func capitalize(s string) string {
730730
func strMultiply(str string, count int) string {
731731
var result string
732732
for i := 0; i < count; i++ {
733-
result += string(str)
733+
result += str
734734
}
735735
return result
736736
}

gopls/internal/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func (c *cmdClient) ShowDocument(ctx context.Context, params *protocol.ShowDocum
672672
var success bool
673673
if params.External {
674674
// Open URI in external browser.
675-
success = browser.Open(string(params.URI))
675+
success = browser.Open(params.URI)
676676
} else {
677677
// Open file in editor, optionally taking focus and selecting a range.
678678
// (cmdClient has no editor. Should it fork+exec $EDITOR?)

gopls/internal/lsp/cache/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func goPackagesErrorDiagnostics(ctx context.Context, e packages.Error, m *source
6161
return protocol.Location{}, err
6262
}
6363
return protocol.Location{
64-
URI: protocol.DocumentURI(uri),
64+
URI: uri,
6565
Range: protocol.Range{
6666
Start: posn,
6767
End: posn,
@@ -95,7 +95,7 @@ func goPackagesErrorDiagnostics(ctx context.Context, e packages.Error, m *source
9595
return diags, nil
9696
}
9797
return []*source.Diagnostic{{
98-
URI: protocol.DocumentURI(loc.URI),
98+
URI: loc.URI,
9999
Range: loc.Range,
100100
Severity: protocol.SeverityError,
101101
Source: source.ListError,
@@ -406,7 +406,7 @@ func suggestedAnalysisFixes(diag *gobDiagnostic, kinds []protocol.CodeActionKind
406406
for _, fix := range diag.SuggestedFixes {
407407
edits := make(map[protocol.DocumentURI][]protocol.TextEdit)
408408
for _, e := range fix.TextEdits {
409-
uri := protocol.DocumentURI(e.Location.URI)
409+
uri := e.Location.URI
410410
edits[uri] = append(edits[uri], protocol.TextEdit{
411411
Range: e.Location.Range,
412412
NewText: string(e.NewText),

gopls/internal/lsp/cache/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
8585
case moduleLoadScope:
8686
modQuery := fmt.Sprintf("%s%c...", scope.dir, filepath.Separator)
8787
query = append(query, modQuery)
88-
moduleQueries[modQuery] = string(scope.modulePath)
88+
moduleQueries[modQuery] = scope.modulePath
8989

9090
case viewLoadScope:
9191
// If we are outside of GOPATH, a module, or some other known

gopls/internal/lsp/fake/workdir.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func writeFileData(path string, content []byte, rel RelativeTo) error {
5555
}
5656
backoff := 1 * time.Millisecond
5757
for {
58-
err := os.WriteFile(fp, []byte(content), 0644)
58+
err := os.WriteFile(fp, content, 0644)
5959
if err != nil {
6060
// This lock file violation is not handled by the robustio package, as it
6161
// indicates a real race condition that could be avoided.
@@ -275,7 +275,7 @@ func (w *Workdir) RenameFile(ctx context.Context, oldPath, newPath string) error
275275
// the error from Rename may be accurate.
276276
return renameErr
277277
}
278-
if writeErr := writeFileData(newPath, []byte(content), w.RelativeTo); writeErr != nil {
278+
if writeErr := writeFileData(newPath, content, w.RelativeTo); writeErr != nil {
279279
// At this point we have tried to actually write the file.
280280
// If it still doesn't exist, assume that the error from Rename was accurate:
281281
// for example, maybe we don't have permission to create the new path.

gopls/internal/lsp/mod/diagnostics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func sortedKeys(m map[string]bool) []string {
440440
func suggestGovulncheckAction(fromGovulncheck bool, uri protocol.DocumentURI) (source.SuggestedFix, error) {
441441
if fromGovulncheck {
442442
resetVulncheck, err := command.NewResetGoModDiagnosticsCommand("Reset govulncheck result", command.ResetGoModDiagnosticsArgs{
443-
URIArg: command.URIArg{URI: protocol.DocumentURI(uri)},
443+
URIArg: command.URIArg{URI: uri},
444444
DiagnosticSource: string(source.Govulncheck),
445445
})
446446
if err != nil {
@@ -449,7 +449,7 @@ func suggestGovulncheckAction(fromGovulncheck bool, uri protocol.DocumentURI) (s
449449
return source.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
450450
}
451451
vulncheck, err := command.NewRunGovulncheckCommand("Run govulncheck to verify", command.VulncheckArgs{
452-
URI: protocol.DocumentURI(uri),
452+
URI: uri,
453453
Pattern: "./...",
454454
})
455455
if err != nil {

gopls/internal/lsp/regtest/marker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ func rename(env *Env, loc protocol.Location, newName string) (map[string][]byte,
19661966
editMap, err := env.Editor.Server.Rename(env.Ctx, &protocol.RenameParams{
19671967
TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI},
19681968
Position: loc.Range.Start,
1969-
NewName: string(newName),
1969+
NewName: newName,
19701970
})
19711971
if err != nil {
19721972
return nil, err

gopls/internal/lsp/source/rename.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func renamePackageName(ctx context.Context, s Snapshot, f FileHandle, newName Pa
701701
replacedPath = filepath.Join(modFileDir, r.New.Path)
702702
}
703703

704-
suffix := strings.TrimPrefix(replacedPath, string(oldBase))
704+
suffix := strings.TrimPrefix(replacedPath, oldBase)
705705

706706
newReplacedPath, err := filepath.Rel(modFileDir, newPkgDir+suffix)
707707
if err != nil {
@@ -807,7 +807,7 @@ func renamePackage(ctx context.Context, s Snapshot, f FileHandle, newName Packag
807807

808808
pkgName := m.Name
809809
if m.PkgPath == oldPkgPath {
810-
pkgName = PackageName(newName)
810+
pkgName = newName
811811

812812
if err := renamePackageClause(ctx, m, s, newName, edits); err != nil {
813813
return nil, err

gopls/internal/lsp/template/completion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func inTemplate(fc *Parsed, pos protocol.Position) int {
9494
}
9595
// If the interval [x,offset] does not contain Left or Right
9696
// then provide completions. (do we need the test for Right?)
97-
if !bytes.Contains(fc.buf[x:offset], []byte(Left)) && !bytes.Contains(fc.buf[x:offset], []byte(Right)) {
97+
if !bytes.Contains(fc.buf[x:offset], Left) && !bytes.Contains(fc.buf[x:offset], Right) {
9898
return x
9999
}
100100
}
@@ -127,7 +127,7 @@ func (c *completer) complete() (*protocol.CompletionList, error) {
127127
if len(words) == 0 {
128128
return nil, nil // if this happens, why were we called?
129129
}
130-
pattern := string(words[len(words)-1])
130+
pattern := words[len(words)-1]
131131
if pattern[0] == '$' {
132132
// should we also return a raw "$"?
133133
for _, s := range c.syms {
@@ -156,7 +156,7 @@ func (c *completer) complete() (*protocol.CompletionList, error) {
156156
// could we get completion attempts in strings or numbers, and if so, do we care?
157157
// globals
158158
for _, kw := range globals {
159-
if weakMatch(kw, string(pattern)) != 0 {
159+
if weakMatch(kw, pattern) != 0 {
160160
ans.Items = append(ans.Items, protocol.CompletionItem{
161161
Label: kw,
162162
Kind: protocol.KeywordCompletion,
@@ -177,7 +177,7 @@ func (c *completer) complete() (*protocol.CompletionList, error) {
177177
// keywords if we're at the beginning
178178
if len(words) <= 1 || len(words[len(words)-2]) == 1 && words[len(words)-2][0] == '|' {
179179
for _, kw := range keywords {
180-
if weakMatch(kw, string(pattern)) != 0 {
180+
if weakMatch(kw, pattern) != 0 {
181181
ans.Items = append(ans.Items, protocol.CompletionItem{
182182
Label: kw,
183183
Kind: protocol.KeywordCompletion,

gopls/internal/lsp/template/implementations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Definition(snapshot source.Snapshot, fh source.FileHandle, loc protocol.Pos
8686
if !s.vardef || s.name != sym {
8787
continue
8888
}
89-
ans = append(ans, protocol.Location{URI: protocol.DocumentURI(k), Range: p.Range(s.start, s.length)})
89+
ans = append(ans, protocol.Location{URI: k, Range: p.Range(s.start, s.length)})
9090
}
9191
}
9292
return ans, nil
@@ -139,7 +139,7 @@ func References(ctx context.Context, snapshot source.Snapshot, fh source.FileHan
139139
if s.vardef && !params.Context.IncludeDeclaration {
140140
continue
141141
}
142-
ans = append(ans, protocol.Location{URI: protocol.DocumentURI(k), Range: p.Range(s.start, s.length)})
142+
ans = append(ans, protocol.Location{URI: k, Range: p.Range(s.start, s.length)})
143143
}
144144
}
145145
// do these need to be sorted? (a.files is a map)

gopls/internal/lsp/template/symbols.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (p *Parsed) findSymbols() {
180180
break
181181
}
182182
// nothing to report, but build one for hover
183-
sz := utf8.RuneCount([]byte(x.Text))
183+
sz := utf8.RuneCount(x.Text)
184184
p.symbols = append(p.symbols, symbol{start: int(x.Pos), length: sz, kind: protocol.Constant})
185185
case *parse.VariableNode:
186186
p.symbols = append(p.symbols, p.fields(x.Ident, x)...)

0 commit comments

Comments
 (0)