Documentation
¶
Index ¶
- Constants
- func LangMapFileToModule(file SourceFile, repo SourceRepository, lang SourceLanguage, ...) (string, error)
- func NewCodeGraphBuilder(config CodeGraphBuilderConfig, repository SourceRepository, ...) (*codeGraphBuilder, error)
- func TSExecQuery(query string, lang *sitter.Language, source []byte, node *sitter.Node, ...) error
- type CodeGraphBuilderConfig
- type CodeGraphBuilderEvent
- type CodeGraphBuilderEventHandler
- type CodeGraphBuilderMetrics
- type FileSystemSourceRepositoryConfig
- type SourceFile
- type SourceLanguage
- type SourceLanguageMeta
- type SourceRepository
Constants ¶
const ( CodeGraphBuilderEventFileQueued = "file_queued" CodeGraphBuilderEventFileProcessed = "file_processed" CodeGraphBuilderEventImportProcessed = "import_processed" CodeGraphBuilderEventFunctionProcessed = "function_processed" )
Variables ¶
This section is empty.
Functions ¶
func LangMapFileToModule ¶
func LangMapFileToModule(file SourceFile, repo SourceRepository, lang SourceLanguage, includeImports bool) (string, error)
Maps a file path to a module name. This is an important operation because it serves as the bridge between FS and Language domain
func NewCodeGraphBuilder ¶
func NewCodeGraphBuilder(config CodeGraphBuilderConfig, repository SourceRepository, lang SourceLanguage, storage graph.Graph) (*codeGraphBuilder, error)
Types ¶
type CodeGraphBuilderConfig ¶
type CodeGraphBuilderEvent ¶
type CodeGraphBuilderEvent struct {
Kind string
Data interface{}
}
type CodeGraphBuilderEventHandler ¶
type CodeGraphBuilderEventHandler func(CodeGraphBuilderEvent, CodeGraphBuilderMetrics) error
The event handler is invoked from its own go routine. Handler functions must be thread safe.
type CodeGraphBuilderMetrics ¶
type FileSystemSourceRepositoryConfig ¶
type FileSystemSourceRepositoryConfig struct {
// List of paths to search for source code
SourcePaths []string
// Glob patterns to exclude from source code search
ExcludedGlobs []string
// Glob patterns to include in source code search
IncludedGlobs []string
// List of paths to search for imported source code
ImportPaths []string
}
type SourceFile ¶
type SourceFile struct {
// Identifier for the source file. This is dependent on the
// language on how to uniquely identify a source file
Id string
// Repository specific path to the file
Path string
// contains filtered or unexported fields
}
Represents a source file. This is required because import resolution algorithm may need to know the path of the current file
func LangMapModuleToFile ¶
func LangMapModuleToFile(moduleName string, currentFile SourceFile, repo SourceRepository, lang SourceLanguage, includeImports bool) (SourceFile, error)
Maps a module name back to a file path that must exist in the repository
func (SourceFile) IsImportedFile ¶
func (f SourceFile) IsImportedFile() bool
Check if the source file is imported. Returns true if the source file is relative to the source directories without considering any import directories
func (SourceFile) Open ¶
func (f SourceFile) Open() (io.ReadCloser, error)
func (SourceFile) Repository ¶
func (f SourceFile) Repository() SourceRepository
type SourceLanguage ¶
type SourceLanguage interface {
// Get metadata for the source language
GetMeta() SourceLanguageMeta
// Parse a source file and return the CST (tree-sitter concrete syntax tree)
ParseSource(file SourceFile) (*nodes.CST, error)
// Get import nodes from the CST
GetImportNodes(cst *nodes.CST) ([]nodes.CSTImportNode, error)
// Get function declaration nodes from the CST
GetFunctionDeclarationNodes(cst *nodes.CST) ([]nodes.CSTFunctionNode, error)
// Get function call nodes from the CST
GetFunctionCallNodes(cst *nodes.CST) ([]nodes.CSTFunctionCallNode, error)
// Resolve the import module / package name from relative path
ResolveImportNameFromPath(relPath string) (string, error)
// Resolve import name to possible relative file names
// Multiple paths are possible because an import such
// as a.b can resolve to a/b.py or a/b/__init__.py depending
// on language and file system
ResolveImportPathsFromName(currentFile SourceFile, importName string, includeImports bool) ([]string, error)
}
Any source language implementation must support these primitives for integration with the code analysis system
type SourceLanguageMeta ¶
type SourceLanguageMeta struct {
SourceFileGlobs []string
}
Declarative metadata for the source language
type SourceRepository ¶
type SourceRepository interface {
// Name of the repository
Name() string
// Enumerate all source files in the repository. This can be multiple
// directories for a local source repository
EnumerateSourceFiles(handler sourceFileHandlerFn) error
// Get a source file by path. This function enumerates all directories
// available in the repository to check for existence of the source file by path
GetSourceFileByPath(path string, includeImports bool) (SourceFile, error)
// Open a source file for reading
OpenSourceFile(file SourceFile) (io.ReadCloser, error)
// Configure the repository for a source language
ConfigureForLanguage(language SourceLanguage)
// Get relative path of the source file from the repository root
// This is useful for constructing the import path. The first match is returned
GetRelativePath(path string, includeImport bool) (string, error)
}
SourceRepository is a repository of source files. It can be a local repository such as a directory or a remote repository such as a git repository. The concept of repository is just to find 1P and 3P code while abstracting the underlying storage mechanism (e.g. local file system or remote git repository)
func NewFileSystemSourceRepository ¶
func NewFileSystemSourceRepository(config FileSystemSourceRepositoryConfig) (SourceRepository, error)