mirror of
https://github.com/golang/go
synced 2024-11-18 14:14:46 -07:00
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>
This commit is contained in:
parent
4414aad16c
commit
329c8d646e
14
internal/lsp/cache/modfile.go
vendored
14
internal/lsp/cache/modfile.go
vendored
@ -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 }
|
|
14
internal/lsp/cache/sumfile.go
vendored
14
internal/lsp/cache/sumfile.go
vendored
@ -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 }
|
|
94
internal/lsp/cache/token.go
vendored
94
internal/lsp/cache/token.go
vendored
@ -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
|
|
||||||
}
|
|
@ -83,7 +83,7 @@ func formatSource(ctx context.Context, s Snapshot, f File) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Imports formats a file using the goimports tool.
|
// 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")
|
ctx, done := trace.StartSpan(ctx, "source.Imports")
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
|
@ -468,15 +468,7 @@ func (r *runner) Import(t *testing.T, spn span.Span) {
|
|||||||
t.Fatalf("failed for %v: %v", spn, err)
|
t.Fatalf("failed for %v: %v", spn, err)
|
||||||
}
|
}
|
||||||
fh := r.view.Snapshot().Handle(r.ctx, f)
|
fh := r.view.Snapshot().Handle(r.ctx, f)
|
||||||
tok, err := r.view.Session().Cache().TokenHandle(fh).Token(ctx)
|
edits, err := source.Imports(ctx, r.view, f)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if goimported != "" {
|
if goimported != "" {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -60,15 +60,6 @@ const (
|
|||||||
UnknownKind
|
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.
|
// ParseGoHandle represents a handle to the AST for a file.
|
||||||
type ParseGoHandle interface {
|
type ParseGoHandle interface {
|
||||||
// File returns a file handle for which to get the AST.
|
// 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 returns the shared fileset used by all files in the system.
|
||||||
FileSet() *token.FileSet
|
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 returns a ParseGoHandle for the given file handle.
|
||||||
ParseGoHandle(fh FileHandle, mode ParseMode) ParseGoHandle
|
ParseGoHandle(fh FileHandle, mode ParseMode) ParseGoHandle
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user