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



    This section is empty.


    This section is empty.


    func Diagnostics

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


    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

      type Diagnostic

      type Diagnostic struct {
      	Message string
      	Source  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 IdentifierInfo

        type IdentifierInfo struct {
        	Name  string
        	Range Range
        	File  File
        	Type  struct {
        		Range  Range
        		Object types.Object
        	Declaration struct {
        		Range  Range
        		Object types.Object
        	// contains filtered or unexported fields

          IdentifierInfo holds information about an identifier in Go source.

          func Identifier

          func Identifier(ctx context.Context, v View, f File, pos token.Pos) (*IdentifierInfo, error)

            Identifier returns identifier information for a position in a file, accounting for a potentially incomplete selector.

            func (*IdentifierInfo) Hover

            func (i *IdentifierInfo) Hover(q types.Qualifier) (string, error)

            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.

              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, tok *token.File, 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.