internal/lsp: address some staticcheck warning
Change-Id: I5eea4d35ef6ad4159ca96ba2765477c4603a1ca6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324396
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: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go
index 3827cac..3e61ece 100644
--- a/internal/lsp/cache/parse.go
+++ b/internal/lsp/cache/parse.go
@@ -120,8 +120,7 @@
return nil, err
}
astHandle := s.generation.Bind(astCacheKey{pkgHandle.key, pgf.URI}, func(ctx context.Context, arg memoize.Arg) interface{} {
- snapshot := arg.(*snapshot)
- return buildASTCache(ctx, snapshot, pgf)
+ return buildASTCache(pgf)
}, nil)
d, err := astHandle.Get(ctx, s.generation, s)
@@ -160,7 +159,7 @@
// buildASTCache builds caches to aid in quickly going from the typed
// world to the syntactic world.
-func buildASTCache(ctx context.Context, snapshot *snapshot, pgf *source.ParsedGoFile) *astCacheData {
+func buildASTCache(pgf *source.ParsedGoFile) *astCacheData {
var (
// path contains all ancestors, including n.
path []ast.Node
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index 087c210..ca76d20 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -241,7 +241,7 @@
// comment by scanning the content of the file.
startOffset := tok.Offset(c.Pos())
if startLine != endLine && bytes.Contains(src[startOffset:], []byte("\r")) {
- if commentEnd := scanForCommentEnd(tok, src[startOffset:]); commentEnd > 0 {
+ if commentEnd := scanForCommentEnd(src[startOffset:]); commentEnd > 0 {
end = startOffset + commentEnd
}
}
@@ -257,7 +257,7 @@
// scanForCommentEnd returns the offset of the end of the multi-line comment
// at the start of the given byte slice.
-func scanForCommentEnd(tok *token.File, src []byte) int {
+func scanForCommentEnd(src []byte) int {
var s scanner.Scanner
s.Init(bytes.NewReader(src))
s.Mode ^= scanner.SkipComments
diff --git a/internal/lsp/source/types_format.go b/internal/lsp/source/types_format.go
index fdc76f6..c3f17b0 100644
--- a/internal/lsp/source/types_format.go
+++ b/internal/lsp/source/types_format.go
@@ -252,11 +252,7 @@
if field == nil {
return nil, fmt.Errorf("no declaration for object %s", obj.Name())
}
- typ, ok := field.Type.(ast.Expr)
- if !ok {
- return nil, fmt.Errorf("unexpected type for node (%T)", field.Type)
- }
- return typ, nil
+ return field.Type, nil
}
// qualifyExpr applies the "pkgName." prefix to any *ast.Ident in the expr.