1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:14:47 -07:00

internal/lsp: remove source.Cache

snapshot.View().Session().Cache().FileSet() has been driving me crazy
for a while. Add it to snapshot. Along the way, discover that the Cache
interface is now totally unused and delete it.

I also changed a bunch of View arguments to Snapshot while I was in the
area.

Change-Id: I1064d0020b1567c2ed28d2d55e0f4649eb94c060
Reviewed-on: https://go-review.googlesource.com/c/tools/+/245324
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Heschi Kreinick 2020-07-28 17:00:10 -04:00
parent b4d825fe35
commit f29cbc7105
24 changed files with 133 additions and 152 deletions

View File

@ -134,7 +134,7 @@ func (s *Session) Shutdown(ctx context.Context) {
event.Log(ctx, "Shutdown session", KeyShutdownSession.Of(s))
}
func (s *Session) Cache() source.Cache {
func (s *Session) Cache() interface{} {
return s.cache
}

View File

@ -110,6 +110,10 @@ func (s *snapshot) View() source.View {
return s.view
}
func (s *snapshot) FileSet() *token.FileSet {
return s.view.session.cache.fset
}
// config returns the configuration used for the snapshot's interaction with the
// go/packages API.
func (s *snapshot) config(ctx context.Context) *packages.Config {

View File

@ -45,8 +45,6 @@ func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLink
}
func modLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle) ([]protocol.DocumentLink, error) {
view := snapshot.View()
pm, err := snapshot.ParseMod(ctx, fh)
if err != nil {
return nil, err
@ -69,8 +67,8 @@ func modLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandl
// Shift the start position to the location of the
// dependency within the require statement.
start, end := token.Pos(s+i), token.Pos(s+i+len(dep))
target := fmt.Sprintf("https://%s/mod/%s", view.Options().LinkTarget, req.Mod.String())
l, err := toProtocolLink(view, pm.Mapper, target, start, end, source.Mod)
target := fmt.Sprintf("https://%s/mod/%s", snapshot.View().Options().LinkTarget, req.Mod.String())
l, err := toProtocolLink(snapshot, pm.Mapper, target, start, end, source.Mod)
if err != nil {
return nil, err
}
@ -88,7 +86,7 @@ func modLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandl
}
for _, section := range [][]modfile.Comment{comments.Before, comments.Suffix, comments.After} {
for _, comment := range section {
l, err := findLinksInString(ctx, view, comment.Token, token.Pos(comment.Start.Byte), pm.Mapper, source.Mod)
l, err := findLinksInString(ctx, snapshot, comment.Token, token.Pos(comment.Start.Byte), pm.Mapper, source.Mod)
if err != nil {
return nil, err
}
@ -149,7 +147,7 @@ func goLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle
start := imp.Path.Pos() + 1
end := imp.Path.End() - 1
target = fmt.Sprintf("https://%s/%s", view.Options().LinkTarget, target)
l, err := toProtocolLink(view, pgf.Mapper, target, start, end, source.Go)
l, err := toProtocolLink(snapshot, pgf.Mapper, target, start, end, source.Go)
if err != nil {
return nil, err
}
@ -157,7 +155,7 @@ func goLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle
}
}
for _, s := range str {
l, err := findLinksInString(ctx, view, s.Value, s.Pos(), pgf.Mapper, source.Go)
l, err := findLinksInString(ctx, snapshot, s.Value, s.Pos(), pgf.Mapper, source.Go)
if err != nil {
return nil, err
}
@ -165,7 +163,7 @@ func goLinks(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle
}
for _, commentGroup := range pgf.File.Comments {
for _, comment := range commentGroup.List {
l, err := findLinksInString(ctx, view, comment.Text, comment.Pos(), pgf.Mapper, source.Go)
l, err := findLinksInString(ctx, snapshot, comment.Text, comment.Pos(), pgf.Mapper, source.Go)
if err != nil {
return nil, err
}
@ -190,9 +188,9 @@ func moduleAtVersion(ctx context.Context, snapshot source.Snapshot, target strin
return modpath, version, true
}
func findLinksInString(ctx context.Context, view source.View, src string, pos token.Pos, m *protocol.ColumnMapper, fileKind source.FileKind) ([]protocol.DocumentLink, error) {
func findLinksInString(ctx context.Context, snapshot source.Snapshot, src string, pos token.Pos, m *protocol.ColumnMapper, fileKind source.FileKind) ([]protocol.DocumentLink, error) {
var links []protocol.DocumentLink
for _, index := range view.Options().URLRegexp.FindAllIndex([]byte(src), -1) {
for _, index := range snapshot.View().Options().URLRegexp.FindAllIndex([]byte(src), -1) {
start, end := index[0], index[1]
startPos := token.Pos(int(pos) + start)
endPos := token.Pos(int(pos) + end)
@ -210,7 +208,7 @@ func findLinksInString(ctx context.Context, view source.View, src string, pos to
if linkURL.Scheme == "" {
linkURL.Scheme = "https"
}
l, err := toProtocolLink(view, m, linkURL.String(), startPos, endPos, fileKind)
l, err := toProtocolLink(snapshot, m, linkURL.String(), startPos, endPos, fileKind)
if err != nil {
return nil, err
}
@ -228,7 +226,7 @@ func findLinksInString(ctx context.Context, view source.View, src string, pos to
}
org, repo, number := matches[1], matches[2], matches[3]
target := fmt.Sprintf("https://github.com/%s/%s/issues/%s", org, repo, number)
l, err := toProtocolLink(view, m, target, startPos, endPos, fileKind)
l, err := toProtocolLink(snapshot, m, target, startPos, endPos, fileKind)
if err != nil {
return nil, err
}
@ -249,11 +247,11 @@ var (
issueRegexp *regexp.Regexp
)
func toProtocolLink(view source.View, m *protocol.ColumnMapper, target string, start, end token.Pos, fileKind source.FileKind) (protocol.DocumentLink, error) {
func toProtocolLink(snapshot source.Snapshot, m *protocol.ColumnMapper, target string, start, end token.Pos, fileKind source.FileKind) (protocol.DocumentLink, error) {
var rng protocol.Range
switch fileKind {
case source.Go:
spn, err := span.NewRange(view.Session().Cache().FileSet(), start, end).Span()
spn, err := span.NewRange(snapshot.FileSet(), start, end).Span()
if err != nil {
return protocol.DocumentLink{}, err
}

View File

@ -62,8 +62,7 @@ func runTestCodeLens(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
if !ok {
continue
}
fset := snapshot.View().Session().Cache().FileSet()
rng, err := newMappedRange(fset, pgf.Mapper, d.Pos(), d.Pos()).Range()
rng, err := newMappedRange(snapshot.FileSet(), pgf.Mapper, d.Pos(), d.Pos()).Range()
if err != nil {
return nil, err
}
@ -150,8 +149,7 @@ func goGenerateCodeLens(ctx context.Context, snapshot Snapshot, fh FileHandle) (
if !strings.HasPrefix(l.Text, ggDirective) {
continue
}
fset := snapshot.View().Session().Cache().FileSet()
rng, err := newMappedRange(fset, pgf.Mapper, l.Pos(), l.Pos()+token.Pos(len(ggDirective))).Range()
rng, err := newMappedRange(snapshot.FileSet(), pgf.Mapper, l.Pos(), l.Pos()+token.Pos(len(ggDirective))).Range()
if err != nil {
return nil, err
}
@ -202,8 +200,7 @@ func regenerateCgoLens(ctx context.Context, snapshot Snapshot, fh FileHandle) ([
if c == nil {
return nil, nil
}
fset := snapshot.View().Session().Cache().FileSet()
rng, err := newMappedRange(fset, pgf.Mapper, c.Pos(), c.EndPos).Range()
rng, err := newMappedRange(snapshot.FileSet(), pgf.Mapper, c.Pos(), c.EndPos).Range()
if err != nil {
return nil, err
}
@ -228,8 +225,7 @@ func toggleDetailsCodeLens(ctx context.Context, snapshot Snapshot, fh FileHandle
if err != nil {
return nil, err
}
fset := snapshot.View().Session().Cache().FileSet()
rng, err := newMappedRange(fset, pgf.Mapper, pgf.File.Package, pgf.File.Package).Range()
rng, err := newMappedRange(snapshot.FileSet(), pgf.Mapper, pgf.File.Package, pgf.File.Package).Range()
if err != nil {
return nil, err
}

View File

@ -212,6 +212,5 @@ func getAllSuggestedFixInputs(ctx context.Context, snapshot Snapshot, fh FileHan
if err != nil {
return nil, span.Range{}, nil, nil, nil, nil, nil, err
}
fset := snapshot.View().Session().Cache().FileSet()
return fset, rng, src, pgf.File, pgf.Mapper, pkg.GetTypes(), pkg.GetTypesInfo(), nil
return snapshot.FileSet(), rng, src, pgf.File, pgf.Mapper, pkg.GetTypes(), pkg.GetTypesInfo(), nil
}

View File

@ -261,7 +261,7 @@ func (c *completer) setSurrounding(ident *ast.Ident) {
content: ident.Name,
cursor: c.pos,
// Overwrite the prefix only.
mappedRange: newMappedRange(c.snapshot.View().Session().Cache().FileSet(), c.mapper, ident.Pos(), ident.End()),
mappedRange: newMappedRange(c.snapshot.FileSet(), c.mapper, ident.Pos(), ident.End()),
}
switch c.opts.matcher {
@ -279,7 +279,7 @@ func (c *completer) getSurrounding() *Selection {
c.surrounding = &Selection{
content: "",
cursor: c.pos,
mappedRange: newMappedRange(c.snapshot.View().Session().Cache().FileSet(), c.mapper, c.pos, c.pos),
mappedRange: newMappedRange(c.snapshot.FileSet(), c.mapper, c.pos, c.pos),
}
}
return c.surrounding
@ -653,7 +653,7 @@ func (c *completer) containingIdent(src []byte) *ast.Ident {
// scanToken scans pgh's contents for the token containing pos.
func (c *completer) scanToken(contents []byte) (token.Pos, token.Token, string) {
tok := c.snapshot.View().Session().Cache().FileSet().File(c.pos)
tok := c.snapshot.FileSet().File(c.pos)
var s scanner.Scanner
s.Init(tok, contents, nil, 0)
@ -703,8 +703,7 @@ func (c *completer) emptySwitchStmt() bool {
func (c *completer) populateCommentCompletions(ctx context.Context, comment *ast.CommentGroup) {
// Using the comment position find the line after
fset := c.snapshot.View().Session().Cache().FileSet()
file := fset.File(comment.End())
file := c.snapshot.FileSet().File(comment.End())
if file == nil {
return
}
@ -802,7 +801,7 @@ func (c *completer) setSurroundingForComment(comments *ast.CommentGroup) {
c.surrounding = &Selection{
content: cursorComment.Text[start:end],
cursor: c.pos,
mappedRange: newMappedRange(c.snapshot.View().Session().Cache().FileSet(), c.mapper,
mappedRange: newMappedRange(c.snapshot.FileSet(), c.mapper,
token.Pos(int(cursorComment.Slash)+start), token.Pos(int(cursorComment.Slash)+end)),
}
}
@ -1031,8 +1030,7 @@ func (c *completer) lexical(ctx context.Context) error {
node = c.path[i-1]
}
if node != nil {
fset := c.snapshot.View().Session().Cache().FileSet()
if resolved := resolveInvalid(fset, obj, node, c.pkg.GetTypesInfo()); resolved != nil {
if resolved := resolveInvalid(c.snapshot.FileSet(), obj, node, c.pkg.GetTypesInfo()); resolved != nil {
obj = resolved
}
}

View File

@ -142,7 +142,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
if prefixOp != "" {
// If we are in a selector, add an edit to place prefix before selector.
if sel := enclosingSelector(c.path, c.pos); sel != nil {
edits, err := prependEdit(c.snapshot.View().Session().Cache().FileSet(), c.mapper, sel, prefixOp)
edits, err := prependEdit(c.snapshot.FileSet(), c.mapper, sel, prefixOp)
if err != nil {
return CompletionItem{}, err
}
@ -171,7 +171,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
if !c.opts.documentation {
return item, nil
}
pos := c.snapshot.View().Session().Cache().FileSet().Position(obj.Pos())
pos := c.snapshot.FileSet().Position(obj.Pos())
// We ignore errors here, because some types, like "unsafe" or "error",
// may not have valid positions that we can use to get documentation.
@ -187,7 +187,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
searchPkg = cand.imp.pkg
}
pgf, pkg, err := findPosInPackage(c.snapshot.View(), searchPkg, obj.Pos())
pgf, pkg, err := findPosInPackage(c.snapshot, searchPkg, obj.Pos())
if err != nil {
return item, nil
}
@ -224,7 +224,7 @@ func (c *completer) importEdits(ctx context.Context, imp *importInfo) ([]protoco
return nil, err
}
return computeOneImportFixEdits(ctx, c.snapshot.View(), pgf, &imports.ImportFix{
return computeOneImportFixEdits(ctx, c.snapshot, pgf, &imports.ImportFix{
StmtInfo: imports.ImportInfo{
ImportPath: imp.importPath,
Name: imp.name,

View File

@ -115,7 +115,7 @@ func (c *completer) literal(ctx context.Context, literalType types.Type, imp *im
// If we are in a selector we must place the "&" before the selector.
// For example, "foo.B<>" must complete to "&foo.Bar{}", not
// "foo.&Bar{}".
edits, err := prependEdit(c.snapshot.View().Session().Cache().FileSet(), c.mapper, sel, "&")
edits, err := prependEdit(c.snapshot.FileSet(), c.mapper, sel, "&")
if err != nil {
event.Error(ctx, "error making edit for literal pointer completion", err)
return

View File

@ -41,7 +41,7 @@ func (c *completer) structFieldSnippet(label, detail string) *snippet.Builder {
}
})
fset := c.snapshot.View().Session().Cache().FileSet()
fset := c.snapshot.FileSet()
// If the cursor position is on a different line from the literal's opening brace,
// we are in a multiline literal.

View File

@ -53,7 +53,7 @@ func (c *completer) addAssignAppend() {
// needsLHS is true if we need to prepend the LHS slice name and
// "=" to our candidate.
needsLHS = false
fset = c.snapshot.View().Session().Cache().FileSet()
fset = c.snapshot.FileSet()
)
switch n := c.path[1].(type) {
@ -205,7 +205,7 @@ func (c *completer) addErrCheckAndReturn() {
var (
// errText is e.g. "err" in "foo, err := bar()".
errText = formatNode(c.snapshot.View().Session().Cache().FileSet(), lastAssignee)
errText = formatNode(c.snapshot.FileSet(), lastAssignee)
// Whether we need to include the "if" keyword in our candidate.
needsIf = true

View File

@ -23,7 +23,7 @@ func FoldingRange(ctx context.Context, snapshot Snapshot, fh FileHandle, lineFol
if err != nil {
return nil, err
}
fset := snapshot.View().Session().Cache().FileSet()
fset := snapshot.FileSet()
// Get folding ranges for comments separately as they are not walked by ast.Inspect.
ranges = append(ranges, commentsFoldingRange(fset, pgf.Mapper, pgf.File)...)

View File

@ -38,10 +38,10 @@ func Format(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]protocol.T
if err != nil {
return nil, err
}
return computeTextEdits(ctx, snapshot.View(), pgf, string(formatted))
return computeTextEdits(ctx, snapshot, pgf, string(formatted))
}
fset := snapshot.View().Session().Cache().FileSet()
fset := snapshot.FileSet()
// format.Node changes slightly from one release to another, so the version
// of Go used to build the LSP server will determine how it formats code.
@ -62,7 +62,7 @@ func Format(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]protocol.T
}
formatted = string(b)
}
return computeTextEdits(ctx, snapshot.View(), pgf, formatted)
return computeTextEdits(ctx, snapshot, pgf, formatted)
}
func formatSource(ctx context.Context, fh FileHandle) ([]byte, error) {
@ -94,7 +94,7 @@ func AllImportsFixes(ctx context.Context, snapshot Snapshot, fh FileHandle) (all
return nil, nil, err
}
if err := snapshot.View().RunProcessEnvFunc(ctx, func(opts *imports.Options) error {
allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot.View(), pgf, opts)
allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot, pgf, opts)
return err
}); err != nil {
return nil, nil, fmt.Errorf("AllImportsFixes: %v", err)
@ -104,7 +104,7 @@ func AllImportsFixes(ctx context.Context, snapshot Snapshot, fh FileHandle) (all
// computeImportEdits computes a set of edits that perform one or all of the
// necessary import fixes.
func computeImportEdits(ctx context.Context, view View, pgf *ParsedGoFile, options *imports.Options) (allFixEdits []protocol.TextEdit, editsPerFix []*ImportFix, err error) {
func computeImportEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFile, options *imports.Options) (allFixEdits []protocol.TextEdit, editsPerFix []*ImportFix, err error) {
filename := pgf.URI.Filename()
// Build up basic information about the original file.
@ -113,7 +113,7 @@ func computeImportEdits(ctx context.Context, view View, pgf *ParsedGoFile, optio
return nil, nil, err
}
allFixEdits, err = computeFixEdits(view, pgf, options, allFixes)
allFixEdits, err = computeFixEdits(snapshot, pgf, options, allFixes)
if err != nil {
return nil, nil, err
}
@ -121,7 +121,7 @@ func computeImportEdits(ctx context.Context, view View, pgf *ParsedGoFile, optio
// Apply all of the import fixes to the file.
// Add the edits for each fix to the result.
for _, fix := range allFixes {
edits, err := computeFixEdits(view, pgf, options, []*imports.ImportFix{fix})
edits, err := computeFixEdits(snapshot, pgf, options, []*imports.ImportFix{fix})
if err != nil {
return nil, nil, err
}
@ -133,9 +133,9 @@ func computeImportEdits(ctx context.Context, view View, pgf *ParsedGoFile, optio
return allFixEdits, editsPerFix, nil
}
func computeOneImportFixEdits(ctx context.Context, view View, pgf *ParsedGoFile, fix *imports.ImportFix) ([]protocol.TextEdit, error) {
func computeOneImportFixEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFile, fix *imports.ImportFix) ([]protocol.TextEdit, error) {
options := &imports.Options{
LocalPrefix: view.Options().LocalPrefix,
LocalPrefix: snapshot.View().Options().LocalPrefix,
// Defaults.
AllErrors: true,
Comments: true,
@ -144,10 +144,10 @@ func computeOneImportFixEdits(ctx context.Context, view View, pgf *ParsedGoFile,
TabIndent: true,
TabWidth: 8,
}
return computeFixEdits(view, pgf, options, []*imports.ImportFix{fix})
return computeFixEdits(snapshot, pgf, options, []*imports.ImportFix{fix})
}
func computeFixEdits(view View, pgf *ParsedGoFile, options *imports.Options, fixes []*imports.ImportFix) ([]protocol.TextEdit, error) {
func computeFixEdits(snapshot Snapshot, pgf *ParsedGoFile, options *imports.Options, fixes []*imports.ImportFix) ([]protocol.TextEdit, error) {
// trim the original data to match fixedData
left := importPrefix(pgf.Src)
extra := !strings.Contains(left, "\n") // one line may have more than imports
@ -171,7 +171,7 @@ func computeFixEdits(view View, pgf *ParsedGoFile, options *imports.Options, fix
if fixedData == nil || fixedData[len(fixedData)-1] != '\n' {
fixedData = append(fixedData, '\n') // ApplyFixes may miss the newline, go figure.
}
edits := view.Options().ComputeEdits(pgf.URI, left, string(fixedData))
edits := snapshot.View().Options().ComputeEdits(pgf.URI, left, string(fixedData))
return ToProtocolEdits(pgf.Mapper, edits)
}
@ -236,11 +236,11 @@ func importPrefix(src []byte) string {
return string(src[:importEnd])
}
func computeTextEdits(ctx context.Context, view View, pgf *ParsedGoFile, formatted string) ([]protocol.TextEdit, error) {
func computeTextEdits(ctx context.Context, snapshot Snapshot, pgf *ParsedGoFile, formatted string) ([]protocol.TextEdit, error) {
_, done := event.Start(ctx, "source.computeTextEdits")
defer done()
edits := view.Options().ComputeEdits(pgf.URI, string(pgf.Src), formatted)
edits := snapshot.View().Options().ComputeEdits(pgf.URI, string(pgf.Src), formatted)
return ToProtocolEdits(pgf.Mapper, edits)
}

View File

@ -56,7 +56,7 @@ func Highlight(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protoc
}
var ranges []protocol.Range
for rng := range result {
mRng, err := posToMappedRange(snapshot.View(), pkg, rng.start, rng.end)
mRng, err := posToMappedRange(snapshot, pkg, rng.start, rng.end)
if err != nil {
return nil, err
}

View File

@ -82,7 +82,7 @@ func HoverIdentifier(ctx context.Context, i *IdentifierInfo) (*HoverInformation,
ctx, done := event.Start(ctx, "source.Hover")
defer done()
fset := i.Snapshot.View().Session().Cache().FileSet()
fset := i.Snapshot.FileSet()
h, err := hover(ctx, fset, i.pkg, i.Declaration)
if err != nil {
return nil, err

View File

@ -74,11 +74,11 @@ func Identifier(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto
var ErrNoIdentFound = errors.New("no identifier found")
func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File, pos token.Pos) (*IdentifierInfo, error) {
func findIdentifier(ctx context.Context, snapshot Snapshot, pkg Package, file *ast.File, pos token.Pos) (*IdentifierInfo, error) {
// Handle import specs separately, as there is no formal position for a
// package declaration.
if result, err := importSpec(s, pkg, file, pos); result != nil || err != nil {
if s.View().Options().ImportShortcut.ShowDefinition() {
if result, err := importSpec(snapshot, pkg, file, pos); result != nil || err != nil {
if snapshot.View().Options().ImportShortcut.ShowDefinition() {
return result, err
}
return nil, nil
@ -88,7 +88,6 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
return nil, ErrNoIdentFound
}
view := s.View()
qf := qualifier(file, pkg.GetTypes(), pkg.GetTypesInfo())
ident, _ := path[0].(*ast.Ident)
@ -98,7 +97,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
// Special case for package declarations, since they have no
// corresponding types.Object.
if ident == file.Name {
rng, err := posToMappedRange(view, pkg, file.Name.Pos(), file.Name.End())
rng, err := posToMappedRange(snapshot, pkg, file.Name.Pos(), file.Name.End())
if err != nil {
return nil, err
}
@ -112,7 +111,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
if declAST == nil {
declAST = file
}
declRng, err := posToMappedRange(view, pkg, declAST.Name.Pos(), declAST.Name.End())
declRng, err := posToMappedRange(snapshot, pkg, declAST.Name.Pos(), declAST.Name.End())
if err != nil {
return nil, err
}
@ -122,7 +121,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
mappedRange: rng,
pkg: pkg,
qf: qf,
Snapshot: s,
Snapshot: snapshot,
Declaration: Declaration{
node: declAST.Name,
MappedRange: []mappedRange{declRng},
@ -131,7 +130,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
}
result := &IdentifierInfo{
Snapshot: s,
Snapshot: snapshot,
qf: qf,
pkg: pkg,
ident: ident,
@ -148,7 +147,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
result.Name = result.ident.Name
var err error
if result.mappedRange, err = posToMappedRange(view, pkg, result.ident.Pos(), result.ident.End()); err != nil {
if result.mappedRange, err = posToMappedRange(snapshot, pkg, result.ident.Pos(), result.ident.End()); err != nil {
return nil, err
}
@ -171,7 +170,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
// Handle builtins separately.
if result.Declaration.obj.Parent() == types.Universe {
builtin, err := s.BuiltinPackage(ctx)
builtin, err := snapshot.BuiltinPackage(ctx)
if err != nil {
return nil, err
}
@ -187,7 +186,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
// The builtin package isn't in the dependency graph, so the usual utilities
// won't work here.
rng := newMappedRange(view.Session().Cache().FileSet(), builtin.ParsedFile.Mapper, decl.Pos(), decl.Pos()+token.Pos(len(result.Name)))
rng := newMappedRange(snapshot.FileSet(), builtin.ParsedFile.Mapper, decl.Pos(), decl.Pos()+token.Pos(len(result.Name)))
result.Declaration.MappedRange = append(result.Declaration.MappedRange, rng)
return result, nil
@ -203,13 +202,13 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
}
}
rng, err := objToMappedRange(view, pkg, result.Declaration.obj)
rng, err := objToMappedRange(snapshot, pkg, result.Declaration.obj)
if err != nil {
return nil, err
}
result.Declaration.MappedRange = append(result.Declaration.MappedRange, rng)
if result.Declaration.node, err = objToDecl(ctx, s, pkg, result.Declaration.obj); err != nil {
if result.Declaration.node, err = objToDecl(ctx, snapshot, pkg, result.Declaration.obj); err != nil {
return nil, err
}
typ := pkg.GetTypesInfo().TypeOf(result.ident)
@ -223,7 +222,7 @@ func findIdentifier(ctx context.Context, s Snapshot, pkg Package, file *ast.File
if hasErrorType(result.Type.Object) {
return result, nil
}
if result.Type.mappedRange, err = objToMappedRange(view, pkg, result.Type.Object); err != nil {
if result.Type.mappedRange, err = objToMappedRange(snapshot, pkg, result.Type.Object); err != nil {
return nil, err
}
}
@ -285,7 +284,7 @@ func hasErrorType(obj types.Object) bool {
}
func objToDecl(ctx context.Context, snapshot Snapshot, srcPkg Package, obj types.Object) (ast.Decl, error) {
pgf, _, err := findPosInPackage(snapshot.View(), srcPkg, obj.Pos())
pgf, _, err := findPosInPackage(snapshot, srcPkg, obj.Pos())
if err != nil {
return nil, err
}
@ -297,7 +296,7 @@ func objToDecl(ctx context.Context, snapshot Snapshot, srcPkg Package, obj types
}
// importSpec handles positions inside of an *ast.ImportSpec.
func importSpec(s Snapshot, pkg Package, file *ast.File, pos token.Pos) (*IdentifierInfo, error) {
func importSpec(snapshot Snapshot, pkg Package, file *ast.File, pos token.Pos) (*IdentifierInfo, error) {
var imp *ast.ImportSpec
for _, spec := range file.Imports {
if spec.Path.Pos() <= pos && pos < spec.Path.End() {
@ -312,11 +311,11 @@ func importSpec(s Snapshot, pkg Package, file *ast.File, pos token.Pos) (*Identi
return nil, errors.Errorf("import path not quoted: %s (%v)", imp.Path.Value, err)
}
result := &IdentifierInfo{
Snapshot: s,
Snapshot: snapshot,
Name: importPath,
pkg: pkg,
}
if result.mappedRange, err = posToMappedRange(s.View(), pkg, imp.Path.Pos(), imp.Path.End()); err != nil {
if result.mappedRange, err = posToMappedRange(snapshot, pkg, imp.Path.Pos(), imp.Path.End()); err != nil {
return nil, err
}
// Consider the "declaration" of an import spec to be the imported package.
@ -326,7 +325,7 @@ func importSpec(s Snapshot, pkg Package, file *ast.File, pos token.Pos) (*Identi
}
// Return all of the files in the package as the definition of the import spec.
for _, dst := range importedPkg.GetSyntax() {
rng, err := posToMappedRange(s.View(), pkg, dst.Pos(), dst.End())
rng, err := posToMappedRange(snapshot, pkg, dst.Pos(), dst.End())
if err != nil {
return nil, err
}

View File

@ -16,11 +16,11 @@ import (
"golang.org/x/tools/internal/lsp/protocol"
)
func Implementation(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Position) ([]protocol.Location, error) {
func Implementation(ctx context.Context, snapshot Snapshot, f FileHandle, pp protocol.Position) ([]protocol.Location, error) {
ctx, done := event.Start(ctx, "source.Implementation")
defer done()
impls, err := implementations(ctx, s, f, pp)
impls, err := implementations(ctx, snapshot, f, pp)
if err != nil {
return nil, err
}
@ -29,7 +29,7 @@ func Implementation(ctx context.Context, s Snapshot, f FileHandle, pp protocol.P
if impl.pkg == nil || len(impl.pkg.CompiledGoFiles()) == 0 {
continue
}
rng, err := objToMappedRange(s.View(), impl.pkg, impl.obj)
rng, err := objToMappedRange(snapshot, impl.pkg, impl.obj)
if err != nil {
return nil, err
}
@ -53,7 +53,7 @@ func implementations(ctx context.Context, s Snapshot, f FileHandle, pp protocol.
var (
impls []qualifiedObject
seen = make(map[token.Position]bool)
fset = s.View().Session().Cache().FileSet()
fset = s.FileSet()
)
qos, err := qualifiedObjsAtProtocolPos(ctx, s, f, pp)

View File

@ -45,21 +45,20 @@ func References(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Posit
// references is a helper function used by both References and Rename,
// to avoid recomputing qualifiedObjsAtProtocolPos.
func references(ctx context.Context, s Snapshot, qos []qualifiedObject, includeDeclaration bool) ([]*ReferenceInfo, error) {
func references(ctx context.Context, snapshot Snapshot, qos []qualifiedObject, includeDeclaration bool) ([]*ReferenceInfo, error) {
var (
references []*ReferenceInfo
seen = make(map[token.Position]bool)
fset = s.View().Session().Cache().FileSet()
)
// Make sure declaration is the first item in the response.
if includeDeclaration {
filename := s.View().Session().Cache().FileSet().Position(qos[0].obj.Pos()).Filename
filename := snapshot.FileSet().Position(qos[0].obj.Pos()).Filename
pgf, err := qos[0].pkg.File(span.URIFromPath(filename))
if err != nil {
return nil, err
}
ident, err := findIdentifier(ctx, s, qos[0].pkg, pgf.File, qos[0].obj.Pos())
ident, err := findIdentifier(ctx, snapshot, qos[0].pkg, pgf.File, qos[0].obj.Pos())
if err != nil {
return nil, err
}
@ -77,7 +76,7 @@ func references(ctx context.Context, s Snapshot, qos []qualifiedObject, includeD
// Only search dependents if the object is exported.
if qo.obj.Exported() {
reverseDeps, err := s.GetReverseDependencies(ctx, qo.pkg.ID())
reverseDeps, err := snapshot.GetReverseDependencies(ctx, qo.pkg.ID())
if err != nil {
return nil, err
}
@ -90,12 +89,12 @@ func references(ctx context.Context, s Snapshot, qos []qualifiedObject, includeD
if obj != qo.obj {
continue
}
pos := fset.Position(ident.Pos())
pos := snapshot.FileSet().Position(ident.Pos())
if seen[pos] {
continue
}
seen[pos] = true
rng, err := posToMappedRange(s.View(), pkg, ident.Pos(), ident.End())
rng, err := posToMappedRange(snapshot, pkg, ident.Pos(), ident.End())
if err != nil {
return nil, err
}

View File

@ -42,16 +42,16 @@ type PrepareItem struct {
Text string
}
func PrepareRename(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Position) (*PrepareItem, error) {
func PrepareRename(ctx context.Context, snapshot Snapshot, f FileHandle, pp protocol.Position) (*PrepareItem, error) {
ctx, done := event.Start(ctx, "source.PrepareRename")
defer done()
qos, err := qualifiedObjsAtProtocolPos(ctx, s, f, pp)
qos, err := qualifiedObjsAtProtocolPos(ctx, snapshot, f, pp)
if err != nil {
return nil, err
}
node, obj, pkg := qos[0].node, qos[0].obj, qos[0].sourcePkg
mr, err := posToMappedRange(s.View(), pkg, node.Pos(), node.End())
mr, err := posToMappedRange(snapshot, pkg, node.Pos(), node.End())
if err != nil {
return nil, err
}
@ -97,7 +97,7 @@ func Rename(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Position,
}
r := renamer{
ctx: ctx,
fset: s.View().Session().Cache().FileSet(),
fset: s.FileSet(),
refs: refs,
objsToUpdate: make(map[types.Object]bool),
from: obj.Name(),

View File

@ -99,7 +99,7 @@ FindCall:
if err != nil {
return nil, 0, err
}
rng, err := objToMappedRange(snapshot.View(), pkg, obj)
rng, err := objToMappedRange(snapshot, pkg, obj)
if err != nil {
return nil, 0, err
}
@ -108,7 +108,7 @@ FindCall:
node: node,
}
decl.MappedRange = append(decl.MappedRange, rng)
d, err := hover(ctx, snapshot.View().Session().Cache().FileSet(), pkg, decl)
d, err := hover(ctx, snapshot.FileSet(), pkg, decl)
if err != nil {
return nil, 0, err
}

View File

@ -32,7 +32,7 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
switch decl := decl.(type) {
case *ast.FuncDecl:
if obj := info.ObjectOf(decl.Name); obj != nil {
fs, err := funcSymbol(snapshot.View(), pkg, decl, obj, q)
fs, err := funcSymbol(snapshot, pkg, decl, obj, q)
if err != nil {
return nil, err
}
@ -48,7 +48,7 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
switch spec := spec.(type) {
case *ast.TypeSpec:
if obj := info.ObjectOf(spec.Name); obj != nil {
ts, err := typeSymbol(snapshot.View(), pkg, info, spec, obj, q)
ts, err := typeSymbol(snapshot, pkg, info, spec, obj, q)
if err != nil {
return nil, err
}
@ -58,7 +58,7 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
case *ast.ValueSpec:
for _, name := range spec.Names {
if obj := info.ObjectOf(name); obj != nil {
vs, err := varSymbol(snapshot.View(), pkg, decl, name, obj, q)
vs, err := varSymbol(snapshot, pkg, decl, name, obj, q)
if err != nil {
return nil, err
}
@ -72,17 +72,17 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
return symbols, nil
}
func funcSymbol(view View, pkg Package, decl *ast.FuncDecl, obj types.Object, q types.Qualifier) (protocol.DocumentSymbol, error) {
func funcSymbol(snapshot Snapshot, pkg Package, decl *ast.FuncDecl, obj types.Object, q types.Qualifier) (protocol.DocumentSymbol, error) {
s := protocol.DocumentSymbol{
Name: obj.Name(),
Kind: protocol.Function,
}
var err error
s.Range, err = nodeToProtocolRange(view, pkg, decl)
s.Range, err = nodeToProtocolRange(snapshot, pkg, decl)
if err != nil {
return protocol.DocumentSymbol{}, err
}
s.SelectionRange, err = nodeToProtocolRange(view, pkg, decl.Name)
s.SelectionRange, err = nodeToProtocolRange(snapshot, pkg, decl.Name)
if err != nil {
return protocol.DocumentSymbol{}, err
}
@ -108,7 +108,7 @@ func funcSymbol(view View, pkg Package, decl *ast.FuncDecl, obj types.Object, q
return s, nil
}
func typeSymbol(view View, pkg Package, info *types.Info, spec *ast.TypeSpec, obj types.Object, qf types.Qualifier) (protocol.DocumentSymbol, error) {
func typeSymbol(snapshot Snapshot, pkg Package, info *types.Info, spec *ast.TypeSpec, obj types.Object, qf types.Qualifier) (protocol.DocumentSymbol, error) {
s := protocol.DocumentSymbol{
Name: obj.Name(),
}
@ -116,11 +116,11 @@ func typeSymbol(view View, pkg Package, info *types.Info, spec *ast.TypeSpec, ob
s.Kind = typeToKind(obj.Type())
var err error
s.Range, err = nodeToProtocolRange(view, pkg, spec)
s.Range, err = nodeToProtocolRange(snapshot, pkg, spec)
if err != nil {
return protocol.DocumentSymbol{}, err
}
s.SelectionRange, err = nodeToProtocolRange(view, pkg, spec.Name)
s.SelectionRange, err = nodeToProtocolRange(snapshot, pkg, spec.Name)
if err != nil {
return protocol.DocumentSymbol{}, err
}
@ -136,10 +136,10 @@ func typeSymbol(view View, pkg Package, info *types.Info, spec *ast.TypeSpec, ob
child.Detail, _ = formatType(f.Type(), qf)
spanNode, selectionNode := nodesForStructField(i, st)
if span, err := nodeToProtocolRange(view, pkg, spanNode); err == nil {
if span, err := nodeToProtocolRange(snapshot, pkg, spanNode); err == nil {
child.Range = span
}
if span, err := nodeToProtocolRange(view, pkg, selectionNode); err == nil {
if span, err := nodeToProtocolRange(snapshot, pkg, selectionNode); err == nil {
child.SelectionRange = span
}
s.Children = append(s.Children, child)
@ -166,11 +166,11 @@ func typeSymbol(view View, pkg Package, info *types.Info, spec *ast.TypeSpec, ob
}
}
}
child.Range, err = nodeToProtocolRange(view, pkg, spanNode)
child.Range, err = nodeToProtocolRange(snapshot, pkg, spanNode)
if err != nil {
return protocol.DocumentSymbol{}, err
}
child.SelectionRange, err = nodeToProtocolRange(view, pkg, selectionNode)
child.SelectionRange, err = nodeToProtocolRange(snapshot, pkg, selectionNode)
if err != nil {
return protocol.DocumentSymbol{}, err
}
@ -200,11 +200,11 @@ func typeSymbol(view View, pkg Package, info *types.Info, spec *ast.TypeSpec, ob
break Embeddeds
}
}
child.Range, err = nodeToProtocolRange(view, pkg, spanNode)
child.Range, err = nodeToProtocolRange(snapshot, pkg, spanNode)
if err != nil {
return protocol.DocumentSymbol{}, err
}
child.SelectionRange, err = nodeToProtocolRange(view, pkg, selectionNode)
child.SelectionRange, err = nodeToProtocolRange(snapshot, pkg, selectionNode)
if err != nil {
return protocol.DocumentSymbol{}, err
}
@ -234,7 +234,7 @@ func nodesForStructField(i int, st *ast.StructType) (span, selection ast.Node) {
return nil, nil
}
func varSymbol(view View, pkg Package, decl ast.Node, name *ast.Ident, obj types.Object, q types.Qualifier) (protocol.DocumentSymbol, error) {
func varSymbol(snapshot Snapshot, pkg Package, decl ast.Node, name *ast.Ident, obj types.Object, q types.Qualifier) (protocol.DocumentSymbol, error) {
s := protocol.DocumentSymbol{
Name: obj.Name(),
Kind: protocol.Variable,
@ -243,11 +243,11 @@ func varSymbol(view View, pkg Package, decl ast.Node, name *ast.Ident, obj types
s.Kind = protocol.Constant
}
var err error
s.Range, err = nodeToProtocolRange(view, pkg, decl)
s.Range, err = nodeToProtocolRange(snapshot, pkg, decl)
if err != nil {
return protocol.DocumentSymbol{}, err
}
s.SelectionRange, err = nodeToProtocolRange(view, pkg, name)
s.SelectionRange, err = nodeToProtocolRange(snapshot, pkg, name)
if err != nil {
return protocol.DocumentSymbol{}, err
}

View File

@ -98,8 +98,8 @@ func newBuiltinSignature(ctx context.Context, snapshot Snapshot, name string) (*
variadic = true
}
}
params, _ := formatFieldList(ctx, snapshot.View(), decl.Type.Params, variadic)
results, needResultParens := formatFieldList(ctx, snapshot.View(), decl.Type.Results, false)
params, _ := formatFieldList(ctx, snapshot, decl.Type.Params, variadic)
results, needResultParens := formatFieldList(ctx, snapshot, decl.Type.Results, false)
return &signature{
doc: decl.Doc.Text(),
name: name,
@ -116,7 +116,7 @@ var replacer = strings.NewReplacer(
`IntegerType`, `int`,
)
func formatFieldList(ctx context.Context, view View, list *ast.FieldList, variadic bool) ([]string, bool) {
func formatFieldList(ctx context.Context, snapshot Snapshot, list *ast.FieldList, variadic bool) ([]string, bool) {
if list == nil {
return nil, false
}
@ -129,7 +129,7 @@ func formatFieldList(ctx context.Context, view View, list *ast.FieldList, variad
p := list.List[i]
cfg := printer.Config{Mode: printer.UseSpaces | printer.TabIndent, Tabwidth: 4}
b := &bytes.Buffer{}
if err := cfg.Fprint(b, view.Session().Cache().FileSet(), p.Type); err != nil {
if err := cfg.Fprint(b, snapshot.FileSet(), p.Type); err != nil {
event.Error(ctx, "unable to print type", nil, tag.Type.Of(p.Type))
continue
}
@ -198,13 +198,13 @@ func newSignature(ctx context.Context, s Snapshot, pkg Package, file *ast.File,
// formatVarType formats a *types.Var, accounting for type aliases.
// To do this, it looks in the AST of the file in which the object is declared.
// On any errors, it always fallbacks back to types.TypeString.
func formatVarType(ctx context.Context, s Snapshot, srcpkg Package, srcfile *ast.File, obj *types.Var, qf types.Qualifier) string {
pgf, pkg, err := findPosInPackage(s.View(), srcpkg, obj.Pos())
func formatVarType(ctx context.Context, snapshot Snapshot, srcpkg Package, srcfile *ast.File, obj *types.Var, qf types.Qualifier) string {
pgf, pkg, err := findPosInPackage(snapshot, srcpkg, obj.Pos())
if err != nil {
return types.TypeString(obj.Type(), qf)
}
expr, err := varType(ctx, s, pgf, obj)
expr, err := varType(ctx, snapshot, pgf, obj)
if err != nil {
return types.TypeString(obj.Type(), qf)
}
@ -218,8 +218,8 @@ func formatVarType(ctx context.Context, s Snapshot, srcpkg Package, srcfile *ast
// If the request came from a different package than the one in which the
// types are defined, we may need to modify the qualifiers.
qualified = qualifyExpr(s.View().Session().Cache().FileSet(), qualified, srcpkg, pkg, srcfile, clonedInfo)
fmted := formatNode(s.View().Session().Cache().FileSet(), qualified)
qualified = qualifyExpr(snapshot.FileSet(), qualified, srcpkg, pkg, srcfile, clonedInfo)
fmted := formatNode(snapshot.FileSet(), qualified)
return fmted
}

View File

@ -133,7 +133,7 @@ func IsGenerated(ctx context.Context, snapshot Snapshot, uri span.URI) bool {
if err != nil {
return false
}
tok := snapshot.View().Session().Cache().FileSet().File(pgf.File.Pos())
tok := snapshot.FileSet().File(pgf.File.Pos())
if tok == nil {
return false
}
@ -150,15 +150,15 @@ func IsGenerated(ctx context.Context, snapshot Snapshot, uri span.URI) bool {
return false
}
func nodeToProtocolRange(view View, pkg Package, n ast.Node) (protocol.Range, error) {
mrng, err := posToMappedRange(view, pkg, n.Pos(), n.End())
func nodeToProtocolRange(snapshot Snapshot, pkg Package, n ast.Node) (protocol.Range, error) {
mrng, err := posToMappedRange(snapshot, pkg, n.Pos(), n.End())
if err != nil {
return protocol.Range{}, err
}
return mrng.Range()
}
func objToMappedRange(v View, pkg Package, obj types.Object) (mappedRange, error) {
func objToMappedRange(snapshot Snapshot, pkg Package, obj types.Object) (mappedRange, error) {
if pkgName, ok := obj.(*types.PkgName); ok {
// An imported Go package has a package-local, unqualified name.
// When the name matches the imported package name, there is no
@ -171,18 +171,18 @@ func objToMappedRange(v View, pkg Package, obj types.Object) (mappedRange, error
// When the identifier does not appear in the source, have the range
// of the object be the import path, including quotes.
if pkgName.Imported().Name() == pkgName.Name() {
return posToMappedRange(v, pkg, obj.Pos(), obj.Pos()+token.Pos(len(pkgName.Imported().Path())+2))
return posToMappedRange(snapshot, pkg, obj.Pos(), obj.Pos()+token.Pos(len(pkgName.Imported().Path())+2))
}
}
return nameToMappedRange(v, pkg, obj.Pos(), obj.Name())
return nameToMappedRange(snapshot, pkg, obj.Pos(), obj.Name())
}
func nameToMappedRange(v View, pkg Package, pos token.Pos, name string) (mappedRange, error) {
return posToMappedRange(v, pkg, pos, pos+token.Pos(len(name)))
func nameToMappedRange(snapshot Snapshot, pkg Package, pos token.Pos, name string) (mappedRange, error) {
return posToMappedRange(snapshot, pkg, pos, pos+token.Pos(len(name)))
}
func posToMappedRange(v View, pkg Package, pos, end token.Pos) (mappedRange, error) {
logicalFilename := v.Session().Cache().FileSet().File(pos).Position(pos).Filename
func posToMappedRange(snapshot Snapshot, pkg Package, pos, end token.Pos) (mappedRange, error) {
logicalFilename := snapshot.FileSet().File(pos).Position(pos).Filename
pgf, _, err := findFileInDeps(pkg, span.URIFromPath(logicalFilename))
if err != nil {
return mappedRange{}, err
@ -193,7 +193,7 @@ func posToMappedRange(v View, pkg Package, pos, end token.Pos) (mappedRange, err
if !end.IsValid() {
return mappedRange{}, errors.Errorf("invalid position for %v", end)
}
return newMappedRange(v.Session().Cache().FileSet(), pgf.Mapper, pos, end), nil
return newMappedRange(snapshot.FileSet(), pgf.Mapper, pos, end), nil
}
// Matches cgo generated comment as well as the proposed standard:
@ -511,8 +511,8 @@ func CompareDiagnostic(a, b *Diagnostic) int {
return 1
}
func findPosInPackage(v View, searchpkg Package, pos token.Pos) (*ParsedGoFile, Package, error) {
tok := v.Session().Cache().FileSet().File(pos)
func findPosInPackage(snapshot Snapshot, searchpkg Package, pos token.Pos) (*ParsedGoFile, Package, error) {
tok := snapshot.FileSet().File(pos)
if tok == nil {
return nil, nil, errors.Errorf("no file for pos in package %s", searchpkg.ID())
}

View File

@ -30,6 +30,9 @@ type Snapshot interface {
// View returns the View associated with this snapshot.
View() View
// Fileset returns the Fileset used to parse all the Go files in this snapshot.
FileSet() *token.FileSet
// FindFile returns the FileHandle for the given URI, if it is already
// in the given snapshot.
FindFile(uri span.URI) VersionedFileHandle
@ -221,8 +224,8 @@ type Session interface {
// NewView creates a new View, returning it and its first snapshot.
NewView(ctx context.Context, name string, folder span.URI, options Options) (View, Snapshot, func(), error)
// Cache returns the cache that created this session.
Cache() Cache
// Cache returns the cache that created this session, for debugging only.
Cache() interface{}
// View returns a view with a matching name, if the session has one.
View(name string) View
@ -313,21 +316,6 @@ func (a FileAction) String() string {
}
}
// Cache abstracts the core logic of dealing with the environment from the
// higher level logic that processes the information to produce results.
// The cache provides access to files and their contents, so the source
// package does not directly access the file system.
// A single cache is intended to be process wide, and is the primary point of
// sharing between all consumers.
// A cache may have many active sessions at any given time.
type Cache interface {
// FileSet returns the shared fileset used by all files in the system.
FileSet() *token.FileSet
// GetFile returns a file handle for the given URI.
GetFile(ctx context.Context, uri span.URI) (FileHandle, error)
}
var ErrTmpModfileUnsupported = errors.New("-modfile is unsupported for this Go version")
// ParseMode controls the content of the AST produced when parsing a source file.

View File

@ -65,7 +65,7 @@ outer:
seen[pkg.PkgPath()] = struct{}{}
for _, pgf := range pkg.CompiledGoFiles() {
for _, si := range findSymbol(pgf.File.Decls, pkg.GetTypesInfo(), symbolMatcher) {
mrng, err := posToMappedRange(view, pkg, si.node.Pos(), si.node.End())
mrng, err := posToMappedRange(snapshot, pkg, si.node.Pos(), si.node.End())
if err != nil {
event.Error(ctx, "Error getting mapped range for node", err)
continue