internal/lsp: delete unused code
Change-Id: Ifda9ebcd3fdbb7457b9b46380e238a6fe0081015
Reviewed-on: https://go-review.googlesource.com/c/tools/+/198258
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/cache/modfile.go b/internal/lsp/cache/modfile.go
deleted file mode 100644
index 4863e43..0000000
--- a/internal/lsp/cache/modfile.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package cache
-
-// modFile holds all of the information we know about a mod file.
-type modFile struct {
- fileBase
-}
-
-func (*modFile) setContent(content []byte) {}
-func (*modFile) filename() string { return "" }
-func (*modFile) isActive() bool { return false }
diff --git a/internal/lsp/cache/sumfile.go b/internal/lsp/cache/sumfile.go
deleted file mode 100644
index f73171d..0000000
--- a/internal/lsp/cache/sumfile.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package cache
-
-// sumFile holds all of the information we know about a sum file.
-type sumFile struct {
- fileBase
-}
-
-func (*sumFile) setContent(content []byte) {}
-func (*sumFile) filename() string { return "" }
-func (*sumFile) isActive() bool { return false }
diff --git a/internal/lsp/cache/token.go b/internal/lsp/cache/token.go
deleted file mode 100644
index aa6abc1..0000000
--- a/internal/lsp/cache/token.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package cache
-
-import (
- "context"
- "go/token"
-
- "golang.org/x/tools/internal/lsp/source"
- "golang.org/x/tools/internal/memoize"
- errors "golang.org/x/xerrors"
-)
-
-type tokenKey struct {
- file source.FileIdentity
-}
-
-type tokenHandle struct {
- handle *memoize.Handle
- file source.FileHandle
-}
-
-type tokenData struct {
- memoize.NoCopy
-
- tok *token.File
- err error
-}
-
-func (c *cache) TokenHandle(fh source.FileHandle) source.TokenHandle {
- key := tokenKey{
- file: fh.Identity(),
- }
- h := c.store.Bind(key, func(ctx context.Context) interface{} {
- data := &tokenData{}
- data.tok, data.err = tokenFile(ctx, c, fh)
- return data
- })
- return &tokenHandle{
- handle: h,
- file: fh,
- }
-}
-
-func (h *tokenHandle) File() source.FileHandle {
- return h.file
-}
-
-func (h *tokenHandle) Token(ctx context.Context) (*token.File, error) {
- v := h.handle.Get(ctx)
- if v == nil {
- return nil, ctx.Err()
- }
- data := v.(*tokenData)
- return data.tok, data.err
-}
-
-func tokenFile(ctx context.Context, c *cache, fh source.FileHandle) (*token.File, error) {
- // First, check if we already have a parsed AST for this file's handle.
- for _, mode := range []source.ParseMode{
- source.ParseHeader,
- source.ParseExported,
- source.ParseFull,
- } {
- pk := parseKey{
- file: fh.Identity(),
- mode: mode,
- }
- pd, ok := c.store.Cached(pk).(*parseGoData)
- if !ok {
- continue
- }
- if pd.ast == nil {
- continue
- }
- if !pd.ast.Pos().IsValid() {
- continue
- }
- return c.FileSet().File(pd.ast.Pos()), nil
- }
- // We have not yet parsed this file.
- buf, _, err := fh.Read(ctx)
- if err != nil {
- return nil, err
- }
- tok := c.FileSet().AddFile(fh.Identity().URI.Filename(), -1, len(buf))
- if tok == nil {
- return nil, errors.Errorf("no token.File for %s", fh.Identity().URI)
- }
- tok.SetLinesForContent(buf)
- return tok, nil
-}
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index 50563d3..7f42dae 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -83,7 +83,7 @@
}
// Imports formats a file using the goimports tool.
-func Imports(ctx context.Context, view View, f File, rng span.Range) ([]protocol.TextEdit, error) {
+func Imports(ctx context.Context, view View, f File) ([]protocol.TextEdit, error) {
ctx, done := trace.StartSpan(ctx, "source.Imports")
defer done()
diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go
index 161085d..4c834fe 100644
--- a/internal/lsp/source/source_test.go
+++ b/internal/lsp/source/source_test.go
@@ -468,15 +468,7 @@
t.Fatalf("failed for %v: %v", spn, err)
}
fh := r.view.Snapshot().Handle(r.ctx, f)
- tok, err := r.view.Session().Cache().TokenHandle(fh).Token(ctx)
- if err != nil {
- t.Fatal(err)
- }
- rng, err := spn.Range(span.NewTokenConverter(r.data.Exported.ExpectFileSet, tok))
- if err != nil {
- t.Fatalf("failed for %v: %v", spn, err)
- }
- edits, err := source.Imports(ctx, r.view, f, rng)
+ edits, err := source.Imports(ctx, r.view, f)
if err != nil {
if goimported != "" {
t.Error(err)
diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go
index 90bd1f0..16b0d9d 100644
--- a/internal/lsp/source/view.go
+++ b/internal/lsp/source/view.go
@@ -60,15 +60,6 @@
UnknownKind
)
-// TokenHandle represents a handle to the *token.File for a file.
-type TokenHandle interface {
- // File returns a file handle for which to get the *token.File.
- File() FileHandle
-
- // Token returns the *token.File for the file.
- Token(ctx context.Context) (*token.File, error)
-}
-
// ParseGoHandle represents a handle to the AST for a file.
type ParseGoHandle interface {
// File returns a file handle for which to get the AST.
@@ -147,9 +138,6 @@
// FileSet returns the shared fileset used by all files in the system.
FileSet() *token.FileSet
- // TokenHandle returns a TokenHandle for the given file handle.
- TokenHandle(fh FileHandle) TokenHandle
-
// ParseGoHandle returns a ParseGoHandle for the given file handle.
ParseGoHandle(fh FileHandle, mode ParseMode) ParseGoHandle
}