From 329c8d646ebe56d31ab9699c2223c7daf1d77991 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 1 Oct 2019 13:15:06 -0400 Subject: [PATCH] internal/lsp: delete unused code Change-Id: Ifda9ebcd3fdbb7457b9b46380e238a6fe0081015 Reviewed-on: https://go-review.googlesource.com/c/tools/+/198258 Run-TryBot: Rebecca Stambler Reviewed-by: Ian Cottrell --- internal/lsp/cache/modfile.go | 14 ----- internal/lsp/cache/sumfile.go | 14 ----- internal/lsp/cache/token.go | 94 ------------------------------ internal/lsp/source/format.go | 2 +- internal/lsp/source/source_test.go | 10 +--- internal/lsp/source/view.go | 12 ---- 6 files changed, 2 insertions(+), 144 deletions(-) delete mode 100644 internal/lsp/cache/modfile.go delete mode 100644 internal/lsp/cache/sumfile.go delete mode 100644 internal/lsp/cache/token.go diff --git a/internal/lsp/cache/modfile.go b/internal/lsp/cache/modfile.go deleted file mode 100644 index 4863e4368b..0000000000 --- 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 f73171dfbf..0000000000 --- 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 aa6abc1ebc..0000000000 --- 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 50563d39fc..7f42daea58 100644 --- a/internal/lsp/source/format.go +++ b/internal/lsp/source/format.go @@ -83,7 +83,7 @@ func formatSource(ctx context.Context, s Snapshot, f File) ([]byte, error) { } // 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 161085d187..4c834fe7e1 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -468,15 +468,7 @@ func (r *runner) Import(t *testing.T, spn span.Span) { 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 90bd1f069b..16b0d9d0e1 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go @@ -60,15 +60,6 @@ const ( 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 @@ type Cache interface { // 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 }