source

package
v0.0.0-...-421f03a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: BSD-3-Clause Imports: 16 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 Diagnostics

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

Types

type CompletionItem

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

func Completion

func Completion(ctx context.Context, f File, pos token.Pos) (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 {
	Range
	Message string
}

type File

type File interface {
	GetAST() (*ast.File, error)
	GetFileSet() (*token.FileSet, error)
	GetPackage() (*packages.Package, error)
	GetToken() (*token.File, error)
	Read() ([]byte, error)
}

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 ParameterInformation

type ParameterInformation struct {
	Label string
}

type Range

type Range struct {
	Start token.Pos
	End   token.Pos
}

Range represents a start and end position. Because Range is based purely on two token.Pos entries, it is not self contained. You need access to a token.FileSet to regain the file information.

func Definition

func Definition(ctx context.Context, v View, f File, pos token.Pos) (Range, error)

func Hover

func Hover(ctx context.Context, f File, pos token.Pos) (string, Range, error)

func TypeDefinition

func TypeDefinition(ctx context.Context, v View, f File, pos token.Pos) (Range, error)

type SignatureInformation

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

func SignatureHelp

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

type TextEdit

type TextEdit struct {
	Range   Range
	NewText string
}

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

func Format

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

Format formats a file with a given range.

func Imports

func Imports(ctx context.Context, filename string, content []byte, rng 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 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 URI) (File, error)
	SetContent(ctx context.Context, uri URI, content []byte) (View, 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.

Jump to

Keyboard shortcuts

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