source

package
v0.0.0-...-76bcd77 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2019 License: MIT Imports: 48 Imported by: 0

Documentation

Overview

Package source provides core features for use by Go editors and tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallExpr

func CallExpr(fset *token.FileSet, nodes []ast.Node) *ast.CallExpr

CallExpr climbs AST tree up until call expression

func Deref

func Deref(typ types.Type) types.Type

Deref returns a pointer's element type; otherwise it returns typ.

func Diagnostics

func Diagnostics(ctx context.Context, v View, uri span.URI) (map[span.URI][]Diagnostic, error)

func FetchIdentFromPathNodes

func FetchIdentFromPathNodes(fset *token.FileSet, nodes []ast.Node) (*ast.Ident, error)

func FindComments

func FindComments(pkg Package, fset *token.FileSet, o types.Object, name string) (string, error)

func FindIdentObject

func FindIdentObject(pkg Package, ident *ast.Ident) types.Object

func FindIdentType

func FindIdentType(pkg Package, ident *ast.Ident) types.Type

func FindObject

func FindObject(pkg Package, o types.Object) types.Object

FindObject find object

func GetObjectPathNode

func GetObjectPathNode(pkg Package, fset *token.FileSet, o types.Object) (nodes []ast.Node, ident *ast.Ident, err error)

func GetPathNodes

func GetPathNodes(pkg Package, fset *token.FileSet, start, end token.Pos) ([]ast.Node, error)

func GetSyntaxFile

func GetSyntaxFile(pkg Package, filename string) *ast.File

func JoinCommentGroups

func JoinCommentGroups(a, b *ast.CommentGroup) string

JoinCommentGroups joins the resultant non-empty comment text from two CommentGroups with a newline.

func PackageDoc

func PackageDoc(files []*ast.File, pkgName string) string

PackageDoc finds the documentation for the named package from its files or additional files.

func PathEnclosingInterval

func PathEnclosingInterval(pkg Package, fset *token.FileSet, start, end token.Pos) (path []ast.Node, exact bool)

PathEnclosingInterval returns the PackageInfo and ast.Node that contain source interval [start, end), and all the node's ancestors up to the AST root. It searches all ast.Files of all packages in prog. exact is defined as for astutil.PathEnclosingInterval.

The zero value is returned if not found.

func PullComments

func PullComments(pathNodes []ast.Node) string

func TypeLookup

func TypeLookup(typ types.Type) *types.TypeName

TypeLookup looks for a named type, but will search through any number of type qualifiers (chan/array/slice/pointer) which have an unambiguous base type. If no named type is found, we are not interested, because this is only used for finding a type's definition.

Types

type Action

type Action struct {
	Analyzer *analysis.Analyzer
	Pkg      Package
	Deps     []*Action
	// contains filtered or unexported fields
}

An action represents one unit of analysis work: the application of one analysis to one package. Actions form a DAG, both within a package (as different analyzers are applied, either in sequence or parallel), and across packages (as dependencies are analyzed).

func (*Action) String

func (act *Action) String() string

type Cache

type Cache interface {
	Walk(walkFunc WalkFunc, ranks []string) error
}

type CompletionItem

type CompletionItem struct {
	Label, Detail string
	Kind          CompletionItemKind
	Score         float64
	Documentation string
}

func Completion

func Completion(ctx context.Context, f File, pos token.Pos, cache Cache) (items []CompletionItem, prefix string, err error)

Completion returns a list of possible candidates for completion, given a a file and a position. The prefix is computed based on the preceding identifier and can be used by the client to score the quality of the completion. For instance, some clients may tolerate imperfect matches as valid completion results, since users may make typos.

type CompletionItemKind

type CompletionItemKind int
const (
	Unknown CompletionItemKind = iota
	InterfaceCompletionItem
	StructCompletionItem
	TypeCompletionItem
	ConstantCompletionItem
	FieldCompletionItem
	ParameterCompletionItem
	VariableCompletionItem
	FunctionCompletionItem
	MethodCompletionItem
	PackageCompletionItem
)

type Diagnostic

type Diagnostic struct {
	span.Span
	Message  string
	Source   string
	Severity DiagnosticSeverity
}

type DiagnosticSeverity

type DiagnosticSeverity int
const (
	SeverityWarning DiagnosticSeverity = iota
	SeverityError
)

type File

type File interface {
	URI() span.URI
	GetAST(ctx context.Context) *ast.File
	GetFileSet(ctx context.Context) *token.FileSet
	GetPackage(ctx context.Context) Package
	GetToken(ctx context.Context) *token.File
	GetContent(ctx context.Context) []byte
}

File represents a Go source file that has been type-checked. It is the input to most of the exported functions in this package, as it wraps up the building blocks for most queries. Users of the source package can abstract the loading of packages into their own caching systems.

type InvalidNodeError

type InvalidNodeError struct {
	Node ast.Node
	// contains filtered or unexported fields
}

func NewInvalidNodeError

func NewInvalidNodeError(fset *token.FileSet, node ast.Node) *InvalidNodeError

func (*InvalidNodeError) Error

func (e *InvalidNodeError) Error() string

type Package

type Package interface {
	GetFilenames() []string
	GetSyntax() []*ast.File
	GetErrors() []packages.Error
	GetTypes() *types.Package
	GetTypesInfo() *types.Info
	IsIllTyped() bool
	GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error)
	GetPkgPath() string
	GetName() string
	GetImport(pkgPath string) Package
	GetFileSet() *token.FileSet
}

Package represents a Go package that has been type-checked. It maintains only the relevant fields of a *go/packages.Package.

type ParameterInformation

type ParameterInformation struct {
	Label string
}

type SignatureInformation

type SignatureInformation struct {
	Label           string
	Parameters      []ParameterInformation
	ActiveParameter int
}

func SignatureHelp

func SignatureHelp(ctx context.Context, f File, pos token.Pos, builtinPkg Package, enhance bool) (*SignatureInformation, error)

type TextEdit

type TextEdit struct {
	Span    span.Span
	NewText string
}

TextEdit represents a change to a section of a document. The text within the specified span should be replaced by the supplied new text.

func Format

func Format(ctx context.Context, f File, rng span.Range) ([]TextEdit, error)

Format formats a file with a given range.

func Imports

func Imports(ctx context.Context, f File, rng span.Range) ([]TextEdit, error)

Imports formats a file using the goimports tool.

type URI

type URI string

URI represents the full uri for a file.

func FromDocumentURI

func FromDocumentURI(uri lsp.DocumentURI) URI

FromDocumentURI create a URI from lsp.DocumentURI

func ToURI

func ToURI(path string) URI

ToURI returns a protocol URI for the supplied path. It will always have the file scheme.

func (URI) Filename

func (uri URI) Filename() (string, error)

Filename gets the file path for the URI. It will return an error if the uri is not valid, or if the URI was not a file URI

type View

type View interface {
	GetFile(ctx context.Context, uri span.URI) (File, error)
	SetContent(ctx context.Context, uri span.URI, content []byte) error
	FileSet() *token.FileSet
}

View abstracts the underlying architecture of the package using the source package. The view provides access to files and their contents, so the source package does not directly access the file system.

type WalkFunc

type WalkFunc func(p Package) error

WalkFunc walk function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL