Documentation
¶
Index ¶
- Constants
- Variables
- func SetClassfileAutoImportedPackages(id string, pkgs map[string]string)
- type CacheBuilder
- type CacheKind
- type File
- type FileCacheBuilder
- type Project
- func (p *Project) ASTFile(path string) (*ast.File, error)
- func (p *Project) ASTPackage() (*ast.Package, error)
- func (p *Project) Cache(kind CacheKind) (any, error)
- func (p *Project) DeleteFile(path string) error
- func (p *Project) File(path string) (file *File, ok bool)
- func (p *Project) FileCache(kind CacheKind, path string) (any, error)
- func (p *Project) Files() iter.Seq2[string, *File]
- func (p *Project) PkgDoc() (*pkgdoc.PkgDoc, error)
- func (p *Project) PutFile(path string, file *File)
- func (p *Project) RegisterCacheBuilder(kind CacheKind, builder func(root *Project) (any, error))
- func (p *Project) RegisterFileCacheBuilder(kind CacheKind, ...)
- func (p *Project) RenameFile(oldPath, newPath string) error
- func (p *Project) Snapshot() *Project
- func (p *Project) SnapshotWithOverlay(overlay map[string]*File) *Project
- func (p *Project) TypeInfo() (*xgotypes.Info, error)
- func (p *Project) UpdateFiles(newFiles map[string]*File)
Constants ¶
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 ¶
var ErrUnknownCacheKind = errors.New("unknown cache kind")
ErrUnknownCacheKind represents an error of unknown cache kind.
Functions ¶
func SetClassfileAutoImportedPackages ¶
SetClassfileAutoImportedPackages sets the auto-imported packages for the classfile specified by id.
Types ¶
type CacheBuilder ¶ added in v0.7.0
CacheBuilder represents a project level cache builder.
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
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 ¶
NewProject creates a new project with optional static files and features.
func (*Project) ASTFile ¶ added in v0.7.0
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 ¶
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 ¶
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 ¶
DeleteFile deletes a file from the project.
func (*Project) FileCache ¶
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
Files returns an iterator over all file path-content pairs in the project.
func (*Project) PkgDoc ¶
PkgDoc retrieves the pkgdoc.PkgDoc from the project.
func (*Project) RegisterCacheBuilder ¶ added in v0.7.0
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
RenameFile renames a file in the project.
func (*Project) SnapshotWithOverlay ¶ added in v0.9.0
SnapshotWithOverlay creates a snapshot with overlay files applied.
func (*Project) TypeInfo ¶
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 ¶
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.