1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package source
6
7import (
8	"context"
9	"go/ast"
10	"go/token"
11	"go/types"
12
13	"golang.org/x/tools/go/analysis"
14	"golang.org/x/tools/go/packages"
15)
16
17// View abstracts the underlying architecture of the package using the source
18// package. The view provides access to files and their contents, so the source
19// package does not directly access the file system.
20type View interface {
21	GetFile(ctx context.Context, uri URI) (File, error)
22	SetContent(ctx context.Context, uri URI, content []byte) error
23	FileSet() *token.FileSet
24}
25
26// File represents a Go source file that has been type-checked. It is the input
27// to most of the exported functions in this package, as it wraps up the
28// building blocks for most queries. Users of the source package can abstract
29// the loading of packages into their own caching systems.
30type File interface {
31	GetAST(ctx context.Context) *ast.File
32	GetFileSet(ctx context.Context) *token.FileSet
33	GetPackage(ctx context.Context) Package
34	GetToken(ctx context.Context) *token.File
35	GetContent(ctx context.Context) []byte
36}
37
38// Package represents a Go package that has been type-checked. It maintains
39// only the relevant fields of a *go/packages.Package.
40type Package interface {
41	GetFilenames() []string
42	GetSyntax() []*ast.File
43	GetErrors() []packages.Error
44	GetTypes() *types.Package
45	GetTypesInfo() *types.Info
46	GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error)
47}
48
49// Range represents a start and end position.
50// Because Range is based purely on two token.Pos entries, it is not self
51// contained. You need access to a token.FileSet to regain the file
52// information.
53type Range struct {
54	Start token.Pos
55	End   token.Pos
56}
57
58// TextEdit represents a change to a section of a document.
59// The text within the specified range should be replaced by the supplied new text.
60type TextEdit struct {
61	Range   Range
62	NewText string
63}
64