xgo

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FeatASTCache enables AST cache building.
	FeatASTCache = 1 << iota

	// FeatTypeInfoCache enables TypeInfo cache building.
	FeatTypeInfoCache

	// FeatPkgDocCache enables PkgDoc cache building.
	FeatPkgDocCache

	// FeatAll enables all features.
	FeatAll = FeatASTCache | FeatTypeInfoCache | FeatPkgDocCache
)

Variables

View Source
var ErrUnknownCacheKind = errors.New("unknown cache kind")

ErrUnknownCacheKind represents an error of unknown cache kind.

Functions

func SetClassfileAutoImportedPackages

func SetClassfileAutoImportedPackages(id string, pkgs map[string]string)

SetClassfileAutoImportedPackages sets the auto-imported packages for the classfile specified by id.

Types

type CacheBuilder added in v0.7.0

type CacheBuilder = func(proj *Project) (any, error)

CacheBuilder represents a project level cache builder.

type CacheKind added in v0.7.0

type CacheKind = any

CacheKind represents a kind of cache.

type File

type File struct {
	Content []byte
	// Deprecated: ModTime is no longer supported due to lsp text sync specification. Use Version instead.
	ModTime time.Time
	Version int
}

File represents a file in an XGo project.

type FileCacheBuilder added in v0.7.0

type FileCacheBuilder = func(proj *Project, path string, file *File) (any, error)

FileCacheBuilder represents a file level cache builder.

type Project

type Project struct {
	PkgPath  string
	Mod      *xgomod.Module
	Importer types.Importer
	Fset     *token.FileSet
	// contains filtered or unexported fields
}

Project represents an XGo project.

func NewProject

func NewProject(fset *token.FileSet, files map[string]*File, feats uint) *Project

NewProject creates a new project with optional static files and features.

func (*Project) ASTFile added in v0.7.0

func (p *Project) ASTFile(path string) (*ast.File, error)

ASTFile retrieves the ast.File for the specified source file from the project. The returned ast.File is nil only if building failed.

NOTE: Both the returned ast.File and error can be non-nil, which indicates that only part of the file was parsed successfully.

func (*Project) ASTPackage

func (p *Project) ASTPackage() (*ast.Package, error)

ASTPackage retrieves the ast.Package from the project. The returned ast.Package is nil only if building failed.

NOTE: Both the returned ast.Package and error can be non-nil, which indicates that only part of the project was parsed successfully.

func (*Project) Cache

func (p *Project) Cache(kind CacheKind) (any, error)

Cache gets a project level cache. It builds the cache if it doesn't exist.

The kind must be the same comparable value that was used with Project.RegisterCacheBuilder.

func (*Project) DeleteFile

func (p *Project) DeleteFile(path string) error

DeleteFile deletes a file from the project.

func (*Project) File

func (p *Project) File(path string) (file *File, ok bool)

File gets a file from the project.

func (*Project) FileCache

func (p *Project) FileCache(kind CacheKind, path string) (any, error)

FileCache gets a file level cache. It builds the cache if it doesn't exist.

The kind must be the same comparable value that was used with Project.RegisterFileCacheBuilder.

func (*Project) Files added in v0.7.0

func (p *Project) Files() iter.Seq2[string, *File]

Files returns an iterator over all file path-content pairs in the project.

func (*Project) PkgDoc

func (p *Project) PkgDoc() (*pkgdoc.PkgDoc, error)

PkgDoc retrieves the pkgdoc.PkgDoc from the project.

func (*Project) PutFile

func (p *Project) PutFile(path string, file *File)

PutFile puts a file into the project.

func (*Project) RegisterCacheBuilder added in v0.7.0

func (p *Project) RegisterCacheBuilder(kind CacheKind, builder func(root *Project) (any, error))

RegisterCacheBuilder registers a project level cache builder.

The kind should be a comparable type to avoid conflicts between packages. It is recommended to use a private type defined in your package:

type myCacheKind struct{}

proj.RegisterCacheBuilder(myCacheKind{}, myBuilder)

func (*Project) RegisterFileCacheBuilder added in v0.7.0

func (p *Project) RegisterFileCacheBuilder(kind CacheKind, builder func(proj *Project, path string, file *File) (any, error))

RegisterFileCacheBuilder registers a file level cache builder.

The kind should be a comparable type to avoid conflicts between packages. It is recommended to use a private type defined in your package:

type myCacheKind struct{}

proj.RegisterFileCacheBuilder(myCacheKind{}, myBuilder)

func (*Project) RenameFile added in v0.7.0

func (p *Project) RenameFile(oldPath, newPath string) error

RenameFile renames a file in the project.

func (*Project) Snapshot

func (p *Project) Snapshot() *Project

Snapshot creates a snapshot of the project.

func (*Project) SnapshotWithOverlay added in v0.9.0

func (p *Project) SnapshotWithOverlay(overlay map[string]*File) *Project

SnapshotWithOverlay creates a snapshot with overlay files applied.

func (*Project) TypeInfo

func (p *Project) TypeInfo() (*xgotypes.Info, error)

TypeInfo retrieves the xgotypes.Info from the project. The returned xgotypes.Info is nil only if building failed.

NOTE: Both the returned xgotypes.Info and error can be non-nil, which indicates that only part of the project was type checked successfully.

func (*Project) UpdateFiles

func (p *Project) UpdateFiles(newFiles map[string]*File)

UpdateFiles updates all files in the project with the provided map of files. It removes existing files not present in the new map and updates files from the new map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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