gopls: remove unnecessary conversions
Following up on a few unnecessary conversions noted in CL 545201, remove
unnecessary conversions in the gopls module.
Credit due to https://github.com/mdempsky/unconvert. This CL is just:
unconvert -apply ./...
Change-Id: I201e4869973c40f4bd8c75b45ad28cfceed4d2c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/545558
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/cache/analysis.go b/gopls/internal/lsp/cache/analysis.go
index 8fa7a25..eda58bb 100644
--- a/gopls/internal/lsp/cache/analysis.go
+++ b/gopls/internal/lsp/cache/analysis.go
@@ -1059,12 +1059,12 @@
log.Fatalf("internal error: bad export data: %v", err)
}
for _, path := range paths {
- dep, ok := an.allDeps[PackagePath(path)]
+ dep, ok := an.allDeps[path]
if !ok {
log.Fatalf("%s: missing dependency: %q", an, path)
}
fmt.Fprintf(hash, "%s %s\n", dep.m.PkgPath, dep.summary.DeepExportHash)
- an.exportDeps[PackagePath(path)] = dep
+ an.exportDeps[path] = dep
}
an.exportDeps[m.PkgPath] = an // self
hash.Sum(pkg.deepExportHash[:0])
diff --git a/gopls/internal/lsp/cache/typerefs/refs.go b/gopls/internal/lsp/cache/typerefs/refs.go
index 8146e76..1effb49 100644
--- a/gopls/internal/lsp/cache/typerefs/refs.go
+++ b/gopls/internal/lsp/cache/typerefs/refs.go
@@ -344,7 +344,7 @@
if path == "" {
continue
}
- dep := imports[metadata.ImportPath(path)]
+ dep := imports[path]
if dep == nil {
// Note here that we don't try to "guess"
// the name of an import based on e.g.
diff --git a/gopls/internal/lsp/frob/frob.go b/gopls/internal/lsp/frob/frob.go
index 7d03732..0f3ede2 100644
--- a/gopls/internal/lsp/frob/frob.go
+++ b/gopls/internal/lsp/frob/frob.go
@@ -167,15 +167,15 @@
case reflect.Uint64:
out.uint64(v.Uint())
case reflect.Uintptr:
- out.uint64(uint64(v.Uint()))
+ out.uint64(v.Uint())
case reflect.Float32:
out.uint32(math.Float32bits(float32(v.Float())))
case reflect.Float64:
out.uint64(math.Float64bits(v.Float()))
case reflect.Complex64:
z := complex64(v.Complex())
- out.uint32(uint32(math.Float32bits(real(z))))
- out.uint32(uint32(math.Float32bits(imag(z))))
+ out.uint32(math.Float32bits(real(z)))
+ out.uint32(math.Float32bits(imag(z)))
case reflect.Complex128:
z := v.Complex()
out.uint64(math.Float64bits(real(z)))
diff --git a/gopls/internal/lsp/protocol/mapper_test.go b/gopls/internal/lsp/protocol/mapper_test.go
index d85d878..7725769 100644
--- a/gopls/internal/lsp/protocol/mapper_test.go
+++ b/gopls/internal/lsp/protocol/mapper_test.go
@@ -256,10 +256,10 @@
t.Fatalf("expected result %v; got %v", e.resUTF16col, got)
}
pre, post := getPrePost(e.input, e.offset)
- if string(pre) != e.pre {
+ if pre != e.pre {
t.Fatalf("expected #%d pre %q; got %q", e.offset, e.pre, pre)
}
- if string(post) != e.post {
+ if post != e.post {
t.Fatalf("expected #%d, post %q; got %q", e.offset, e.post, post)
}
})
@@ -269,7 +269,7 @@
func TestFromUTF16(t *testing.T) {
for _, e := range fromUTF16Tests {
t.Run(e.scenario, func(t *testing.T) {
- m := protocol.NewMapper("", []byte(e.input))
+ m := protocol.NewMapper("", e.input)
offset, err := m.PositionOffset(protocol.Position{
Line: uint32(e.line - 1),
Character: uint32(e.utf16col - 1),
@@ -294,10 +294,10 @@
t.Fatalf("expected resulting col %v; got %v", e.resCol, col8)
}
pre, post := getPrePost(e.input, offset)
- if string(pre) != e.pre {
+ if pre != e.pre {
t.Fatalf("expected #%d pre %q; got %q", offset, e.pre, pre)
}
- if string(post) != e.post {
+ if post != e.post {
t.Fatalf("expected #%d post %q; got %q", offset, e.post, post)
}
})
diff --git a/gopls/internal/lsp/semantic.go b/gopls/internal/lsp/semantic.go
index ef8c89b..5f26ae8 100644
--- a/gopls/internal/lsp/semantic.go
+++ b/gopls/internal/lsp/semantic.go
@@ -905,7 +905,7 @@
return
}
// Import strings are implementation defined. Try to match with parse information.
- depID := e.pkg.Metadata().DepsByImpPath[metadata.ImportPath(importPath)]
+ depID := e.pkg.Metadata().DepsByImpPath[importPath]
if depID == "" {
return
}
diff --git a/gopls/internal/lsp/source/hover.go b/gopls/internal/lsp/source/hover.go
index 56b2486..901d1bf 100644
--- a/gopls/internal/lsp/source/hover.go
+++ b/gopls/internal/lsp/source/hover.go
@@ -585,8 +585,8 @@
return protocol.Range{}, nil, nil
}
// Only the rune escape sequence part of the string has to be highlighted, recompute the range.
- runeLen := len(lit.Value) - (int(i) + len(tail))
- start = token.Pos(int(lit.Pos()) + int(i))
+ runeLen := len(lit.Value) - (i + len(tail))
+ start = token.Pos(int(lit.Pos()) + i)
end = token.Pos(int(start) + runeLen)
break
}
diff --git a/gopls/internal/lsp/source/util.go b/gopls/internal/lsp/source/util.go
index a6af6f5..d49d288 100644
--- a/gopls/internal/lsp/source/util.go
+++ b/gopls/internal/lsp/source/util.go
@@ -317,7 +317,7 @@
}
}
if localName, ok := localNames[impPath]; ok && impPath != "" {
- return string(localName)
+ return localName
}
if pkgName != "" {
return string(pkgName)
diff --git a/gopls/internal/regtest/modfile/modfile_test.go b/gopls/internal/regtest/modfile/modfile_test.go
index e371f49..1b8fbf7 100644
--- a/gopls/internal/regtest/modfile/modfile_test.go
+++ b/gopls/internal/regtest/modfile/modfile_test.go
@@ -986,7 +986,7 @@
`
var diagnostics []protocol.Diagnostic
for _, d := range d.Diagnostics {
- if d.Range.Start.Line != uint32(pos.Line) {
+ if d.Range.Start.Line != pos.Line {
continue
}
diagnostics = append(diagnostics, d)