Documentation ¶
Overview ¶
Package packageloader defines functions and types for loading and parsing source from disk or VCS.
Index ¶
- Constants
- type Config
- type DirectoryEntry
- type Entrypoint
- func (e Entrypoint) EntrypointDirectoryPath(pathloader PathLoader) string
- func (e Entrypoint) EntrypointPaths(pathloader PathLoader) ([]string, error)
- func (e Entrypoint) IsSourceFile(pathloader PathLoader) bool
- func (e Entrypoint) IsValid(pathloader PathLoader) (bool, error)
- func (e Entrypoint) Path() string
- type ErrorReporter
- type ImportHandler
- type Library
- type LoadResult
- type LoadedPackageMap
- type LocalFilePathLoader
- func (lfpl LocalFilePathLoader) Exists(path string) (bool, error)
- func (lfpl LocalFilePathLoader) GetRevisionID(path string) (int64, error)
- func (lfpl LocalFilePathLoader) IsSourceFile(path string) bool
- func (lfpl LocalFilePathLoader) LoadDirectory(path string) ([]DirectoryEntry, error)
- func (lfpl LocalFilePathLoader) LoadSourceFile(path string) ([]byte, error)
- func (lfpl LocalFilePathLoader) VCSPackageDirectory(entrypoint Entrypoint) string
- type ModuleOrPackage
- type PackageImport
- type PackageImportType
- type PackageInfo
- type PackageLoader
- func (p *PackageLoader) ListSubModulesAndPackages(packagePath string) ([]ModuleOrPackage, error)
- func (p *PackageLoader) Load(libraries ...Library) LoadResult
- func (p *PackageLoader) LocalPackageInfoForPath(path string, sourceKind string, isVCSPath bool) (PackageInfo, error)
- func (p *PackageLoader) PathLoader() PathLoader
- type PathLoader
- type PositionType
- type SourceHandler
- type SourceHandlerParser
- type SourceTracker
- func (st SourceTracker) DiffFromTracked(path compilercommon.InputSource) ([]diffmatchpatch.Diff, error)
- func (st SourceTracker) GetPositionOffset(position compilercommon.SourcePosition, positionType PositionType) (compilercommon.SourcePosition, error)
- func (st SourceTracker) HasModifiedSourcePaths() (bool, error)
- func (st SourceTracker) LineAndColToRunePosition(lineNumber int, colPosition int, path compilercommon.InputSource, ...) (int, error)
- func (st SourceTracker) LoadedContents(path compilercommon.InputSource) ([]byte, bool)
- func (st SourceTracker) RunePositionToLineAndCol(runePosition int, path compilercommon.InputSource, ...) (int, int, error)
- func (st SourceTracker) TextForLine(lineNumber int, path compilercommon.InputSource, ...) (string, error)
- type WarningReporter
Constants ¶
const SerulianPackageDirectory = ".pkg"
SerulianPackageDirectory is the directory under the root directory holding cached packages.
const SerulianTestSuffix = "_test"
SerulianTestSuffix is the suffix for all testing modules. Testing modules will not be loaded when loading a package.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // The entrypoint from which loading will begin. Can be a file or a directory. Entrypoint Entrypoint // Paths of directories to check for local copies of remote packages // before performing VCS checkout. VCSDevelopmentDirectories []string // The source handlers to use to parse and import the loaded source files. SourceHandlers []SourceHandler // The path loader to use to load source files and directories. PathLoader PathLoader // If true, validation will always be called. AlwaysValidate bool // If true, VCS forced refresh (for branches and HEAD) will be skipped if cache // exists. SkipVCSRefresh bool // contains filtered or unexported fields }
Config defines configuration for a PackageLoader.
func NewBasicConfig ¶
func NewBasicConfig(rootSourceFilePath string, sourceHandlers ...SourceHandler) Config
NewBasicConfig returns PackageLoader Config for a root source file and source handlers.
func (Config) WithCancel ¶ added in v0.3.0
func (c Config) WithCancel() (Config, compilerutil.CancelFunction)
WithCancel returns the config with added support for cancelation.
func (Config) WithCancelationHandle ¶ added in v0.3.0
func (c Config) WithCancelationHandle(handle compilerutil.CancelationHandle) Config
WithCancelationHandle returns the config with the cancelation handle set to that given.
type DirectoryEntry ¶
DirectoryEntry represents a single entry under a directory.
type Entrypoint ¶
type Entrypoint string
Entrypoint defines an entrypoint for the package loader.
func (Entrypoint) EntrypointDirectoryPath ¶
func (e Entrypoint) EntrypointDirectoryPath(pathloader PathLoader) string
EntrypointDirectoryPath returns the directory under which all package resolution should occur. If the entrypoint is a file, this will return its parent directory. If a directory, the entrypoint itself will be returned.
func (Entrypoint) EntrypointPaths ¶
func (e Entrypoint) EntrypointPaths(pathloader PathLoader) ([]string, error)
EntrypointPaths returns all paths for entrypoint source files under this entrypoint. If the entrypoint is a single file, only that file is returned. Otherwise, all files under the directory are returned.
func (Entrypoint) IsSourceFile ¶
func (e Entrypoint) IsSourceFile(pathloader PathLoader) bool
IsSourceFile returns true if the entrypoint is a source file (instead of a directory).
func (Entrypoint) IsValid ¶
func (e Entrypoint) IsValid(pathloader PathLoader) (bool, error)
IsValid returns if the entrypoint is a valid path that exists.
func (Entrypoint) Path ¶
func (e Entrypoint) Path() string
Path returns the path that this entrypoint represents.
type ErrorReporter ¶
type ErrorReporter func(err compilercommon.SourceError)
ErrorReporter is a callback for reporting any errors during verification.
type ImportHandler ¶
type ImportHandler func(sourceKind string, importPath string, importType PackageImportType, importSource compilercommon.InputSource, runePosition int) string
ImportHandler is a function called for registering imports encountered. The function returns a reference string for the package or file location of the import after the full set of packages is parsed.
type Library ¶
type Library struct { PathOrURL string // The file location or SCM URL of the library's package. IsSCM bool // If true, the PathOrURL is treated as a remote SCM package. Kind string // The kind of the library. Leave empty for Serulian files. Alias string // The import alias for this library. }
Library contains a reference to an external library to load, in addition to those referenced by the root source file.
type LoadResult ¶
type LoadResult struct { Status bool // True on success, false otherwise Errors []compilercommon.SourceError // The errors encountered, if any Warnings []compilercommon.SourceWarning // The warnings encountered, if any PackageMap LoadedPackageMap // Map of packages loaded. SourceTracker SourceTracker // Tracker of all source loaded. }
LoadResult contains the result of attempting to load all packages and source files for this project.
type LoadedPackageMap ¶
type LoadedPackageMap struct {
// contains filtered or unexported fields
}
LoadedPackageMap defines an immutable view of the loaded packages.
func (LoadedPackageMap) Get ¶
func (lpm LoadedPackageMap) Get(sourceKind string, packagePath string) (PackageInfo, bool)
Get returns the package information for the package of the given kind and path, if any.
type LocalFilePathLoader ¶
type LocalFilePathLoader struct{}
func (LocalFilePathLoader) Exists ¶
func (lfpl LocalFilePathLoader) Exists(path string) (bool, error)
func (LocalFilePathLoader) GetRevisionID ¶
func (lfpl LocalFilePathLoader) GetRevisionID(path string) (int64, error)
func (LocalFilePathLoader) IsSourceFile ¶
func (lfpl LocalFilePathLoader) IsSourceFile(path string) bool
func (LocalFilePathLoader) LoadDirectory ¶
func (lfpl LocalFilePathLoader) LoadDirectory(path string) ([]DirectoryEntry, error)
func (LocalFilePathLoader) LoadSourceFile ¶
func (lfpl LocalFilePathLoader) LoadSourceFile(path string) ([]byte, error)
func (LocalFilePathLoader) VCSPackageDirectory ¶
func (lfpl LocalFilePathLoader) VCSPackageDirectory(entrypoint Entrypoint) string
type ModuleOrPackage ¶
type ModuleOrPackage struct { // Name is the name of the module or package. Name string // Path is the on-disk path of the module or package. Path string // SourceKind is the kind source for the module or package. Packages will always be // empty. SourceKind string }
ModuleOrPackage defines a reference to a module or package.
type PackageImport ¶
type PackageImport struct { Kind string // The kind of the import. Must match the code returned by a SourceHandler. Path string ImportType PackageImportType SourceRange compilercommon.SourceRange }
PackageImport defines the import of a package as exported by a SourceHandler.
type PackageImportType ¶
type PackageImportType int
PackageImportType identifies the types of imports.
const ( // ImportTypeLocal indicates the import is a local module or package. ImportTypeLocal PackageImportType = iota // ImportTypeAlias indicates that the import is a library alias. ImportTypeAlias // ImportTypeVCS indicates the import is a VCS package. ImportTypeVCS )
type PackageInfo ¶
type PackageInfo struct {
// contains filtered or unexported fields
}
PackageInfo holds information about a loaded package.
func PackageInfoForTesting ¶
func PackageInfoForTesting(kind string, modulePaths []compilercommon.InputSource) PackageInfo
PackageInfoForTesting returns a PackageInfo for testing.
func (PackageInfo) Kind ¶
func (pi PackageInfo) Kind() string
Kind returns the source kind of this package.
func (PackageInfo) ModulePaths ¶
func (pi PackageInfo) ModulePaths() []compilercommon.InputSource
ModulePaths returns the list of full paths of the modules in this package.
func (PackageInfo) ReferenceID ¶ added in v0.3.0
func (pi PackageInfo) ReferenceID() string
ReferenceId returns the unique reference ID for this package.
type PackageLoader ¶
type PackageLoader struct {
// contains filtered or unexported fields
}
PackageLoader helps to fully and recursively load a Serulian package and its dependencies from a directory or set of directories.
func NewPackageLoader ¶
func NewPackageLoader(config Config) *PackageLoader
NewPackageLoader creates and returns a new package loader for the given config.
func (*PackageLoader) ListSubModulesAndPackages ¶
func (p *PackageLoader) ListSubModulesAndPackages(packagePath string) ([]ModuleOrPackage, error)
ListSubModulesAndPackages lists all modules or packages found *directly* under the given path.
func (*PackageLoader) Load ¶
func (p *PackageLoader) Load(libraries ...Library) LoadResult
Load performs the loading of a Serulian package found at the directory path. Any libraries specified will be loaded as well.
func (*PackageLoader) LocalPackageInfoForPath ¶
func (p *PackageLoader) LocalPackageInfoForPath(path string, sourceKind string, isVCSPath bool) (PackageInfo, error)
LocalPackageInfoForPath returns the package information for the given path. Note that VCS paths will be converted into their local package equivalent. If the path refers to a source file instead of a directory, a package containing the single module will be returned.
func (*PackageLoader) PathLoader ¶
func (p *PackageLoader) PathLoader() PathLoader
PathLoader returns the path loader used by this package manager.
type PathLoader ¶
type PathLoader interface { // Exists returns if the given path exists. Exists(path string) (bool, error) // LoadSourceFile attempts to load the source file from the given path. Returns the contents. LoadSourceFile(path string) ([]byte, error) // GetRevisionID returns an ID representing the current revision of the given file. // The revision ID is typically a version number or a ctime. GetRevisionID(path string) (int64, error) // IsSourceFile returns true if the given path refers to a source file. Must return false // if the path refers to a directory. IsSourceFile(path string) bool // LoadDirectory returns the files and sub-directories in the directory at the given path. LoadDirectory(path string) ([]DirectoryEntry, error) // VCSPackageDirectory returns the directory into which VCS packages will be loaded. VCSPackageDirectory(entrypoint Entrypoint) string }
PathLoader defines the interface for loading source files (modules) and directories (packages) in the package loader. Note that VCS checkout will still be done locally, regardless of the path loader configured.
type PositionType ¶
type PositionType int
PositionType defines the type of positions given to GetPositionOffsetFromTracked.
const ( // TrackedFilePosition indicates a position in the tracked file contents. TrackedFilePosition PositionType = 1 // CurrentFilePosition indicates a position in the current file contents. CurrentFilePosition = -1 )
type SourceHandler ¶
type SourceHandler interface { // Kind returns the kind code for the kind of packages this handler will parse. // The default handler for Serulian source will return empty string. Kind() string // PackageFileExtension returns the file extension for all parsed files handled by this // handler under packages. PackageFileExtension() string // NewParser returns a new SourceHandlerParser for parsing source files into the graph. // NOTE: SourceHandlers will typically open a modifier when this method is called, so it // is *critical* that callers make sure to call the `Apply` method, or the modifier will // be left open. NewParser() SourceHandlerParser }
SourceHandler defines an interface for handling source files of a particular kind.
type SourceHandlerParser ¶ added in v0.3.0
type SourceHandlerParser interface { // Parse parses the given source file, typically applying the AST to the underlying // graph being constructed by this handler. importHandler should be invoked for any // imports found, to indicate to the package loader that the imports should be followed // and themselves loaded. Parse(source compilercommon.InputSource, input string, importHandler ImportHandler) // Apply performs final application of all changes in the source handler. This method is called // synchronously, and is typically used to apply the parsed structure to the underlying graph. Apply(packageMap LoadedPackageMap, sourceTracker SourceTracker, cancelationHandle compilerutil.CancelationHandle) // Verify performs verification of the loaded source. Any errors or warnings encountered // should be reported via the given reporter callbacks. Verify(errorReporter ErrorReporter, warningReporter WarningReporter, cancelationHandle compilerutil.CancelationHandle) // Cancel is called to cancel the parsing operation. Cancel() }
SourceHandlerParser defines a handle for parsing zero or more source files into the underlying graph.
type SourceTracker ¶
type SourceTracker struct {
// contains filtered or unexported fields
}
SourceTracker is a helper struct for tracking the contents and versioning of all source files encountered by the package loader.
func (SourceTracker) DiffFromTracked ¶
func (st SourceTracker) DiffFromTracked(path compilercommon.InputSource) ([]diffmatchpatch.Diff, error)
DiffFromTracked returns the diff of the current version of the path (as loaded via the path loader) from the contents stored in the tracker.
func (SourceTracker) GetPositionOffset ¶
func (st SourceTracker) GetPositionOffset(position compilercommon.SourcePosition, positionType PositionType) (compilercommon.SourcePosition, error)
GetPositionOffset returns the given position, offset by any changes that occured since the source file referenced in the position has been tracked.
func (SourceTracker) HasModifiedSourcePaths ¶ added in v0.3.2
func (st SourceTracker) HasModifiedSourcePaths() (bool, error)
HasModifiedSourcePaths returns whether any of the source paths have been modified since originally read.
func (SourceTracker) LineAndColToRunePosition ¶
func (st SourceTracker) LineAndColToRunePosition(lineNumber int, colPosition int, path compilercommon.InputSource, sourceOption compilercommon.SourceMappingOption) (int, error)
LineAndColToRunePosition returns the rune position of the line number and column position in the source of the given path.
func (SourceTracker) LoadedContents ¶
func (st SourceTracker) LoadedContents(path compilercommon.InputSource) ([]byte, bool)
LoadedContents returns the contents of the given source path when loaded by the packageloader, if any.
func (SourceTracker) RunePositionToLineAndCol ¶
func (st SourceTracker) RunePositionToLineAndCol(runePosition int, path compilercommon.InputSource, sourceOption compilercommon.SourceMappingOption) (int, int, error)
RunePositionToLineAndCol returns the line number and column position of the rune position in the source of the given path.
func (SourceTracker) TextForLine ¶
func (st SourceTracker) TextForLine(lineNumber int, path compilercommon.InputSource, sourceOption compilercommon.SourceMappingOption) (string, error)
TextForLine returns all the text found on the given (0-indexed) line in the source of the given path.
type WarningReporter ¶
type WarningReporter func(warning compilercommon.SourceWarning)
WarningReporter is a callback for reporting any warnings during verification.