Documentation ¶
Index ¶
- Constants
- func MergeFiles(file1, file2 *dst.File) *dst.File
- type BufferFileHandle
- type Container
- type Language
- func (l *Language) CreateSourceFile(fileName string, fileHandle repofs.FileHandle) psi.SourceFile
- func (l *Language) Extensions() []string
- func (l *Language) Name() psi.LanguageID
- func (l *Language) Parse(fileName string, code string) (psi.SourceFile, error)
- func (l *Language) ParseCodeBlock(blockName string, block mdutils.CodeBlock) (psi.SourceFile, error)
- type Leaf
- type Node
- type NodeBase
- type SourceFile
- func (sf *SourceFile) Decorator() *decorator.Decorator
- func (sf *SourceFile) Error() error
- func (sf *SourceFile) FileSet() *token.FileSet
- func (sf *SourceFile) InsertDeclarationAt(cursor psi.Cursor, name string, decl psi.Node)
- func (sf *SourceFile) Language() psi.Language
- func (sf *SourceFile) Load() error
- func (sf *SourceFile) MergeCompletionResults(ctx context.Context, scope psi.Scope, cursor psi.Cursor, ...) error
- func (sf *SourceFile) MergeDeclarations(cursor psi.Cursor, node psi.Node) bool
- func (sf *SourceFile) Name() string
- func (sf *SourceFile) OriginalText() string
- func (sf *SourceFile) Parse(filename string, sourceCode string) (result psi.Node, err error)
- func (sf *SourceFile) Path() string
- func (sf *SourceFile) Replace(code string) error
- func (sf *SourceFile) ReplaceDeclarationAt(cursor psi.Cursor, decl psi.Node, name string)
- func (sf *SourceFile) Root() psi.Node
- func (sf *SourceFile) SetRoot(node *dst.File) error
- func (sf *SourceFile) ToCode(node psi.Node) (mdutils.CodeBlock, error)
- type TypeSystemProvider
- func (tsp *TypeSystemProvider) IntrospectPackage(t *types.Package) *vts.Package
- func (tsp *TypeSystemProvider) IntrospectType(t types.Type) *vts.Type
- func (tsp *TypeSystemProvider) ResolvePackage(name vts.PackageName) *vts.Package
- func (tsp *TypeSystemProvider) ResolveType(name vts.TypeName) *vts.Type
Constants ¶
const EdgeKindDeclarations psi.EdgeKind = "Decls"
const LanguageID psi.LanguageID = "go"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BufferFileHandle ¶
type BufferFileHandle struct {
// contains filtered or unexported fields
}
func (BufferFileHandle) Close ¶
func (b BufferFileHandle) Close() error
func (BufferFileHandle) Get ¶
func (b BufferFileHandle) Get() (io.ReadCloser, error)
type Language ¶
type Language struct {
// contains filtered or unexported fields
}
func NewLanguage ¶
func (*Language) CreateSourceFile ¶
func (l *Language) CreateSourceFile(fileName string, fileHandle repofs.FileHandle) psi.SourceFile
func (*Language) Extensions ¶
func (*Language) Name ¶
func (l *Language) Name() psi.LanguageID
func (*Language) ParseCodeBlock ¶
func (l *Language) ParseCodeBlock(blockName string, block mdutils.CodeBlock) (psi.SourceFile, error)
ParseCodeBlock parses the code block and returns the resulting PSI node. This function unescapes HTML escape sequences, modifies the package declaration, and merges the resulting code with the existing AST. It also handles orphan snippets by wrapping them in a pseudo function.
type Leaf ¶
func (*Leaf) IsContainer ¶
type Node ¶
func NewNodeFor ¶
type NodeBase ¶
func (*NodeBase[T]) Initialize ¶
type SourceFile ¶
func NewSourceFile ¶
func NewSourceFile(l *Language, name string, handle repofs.FileHandle) *SourceFile
func (*SourceFile) Decorator ¶
func (sf *SourceFile) Decorator() *decorator.Decorator
func (*SourceFile) Error ¶
func (sf *SourceFile) Error() error
func (*SourceFile) FileSet ¶
func (sf *SourceFile) FileSet() *token.FileSet
func (*SourceFile) InsertDeclarationAt ¶
InsertDeclarationAt inserts a declaration after the given cursor. It takes a psi.Cursor, a name string, and a decl psi.Node. The process involves the following steps: 1. Calling the InsertAfter method of the cursor and passing decl.Ast() to insert the declaration after the cursor. 2. Getting the current index of decl in the root file's declarations using the slices.Index method. 3. Calling the setExistingDeclaration method of the NodeProcessor to update the existing declaration information.
The purpose of InsertDeclarationAt is to insert a declaration at a specific position in the AST and update the declaration information in the NodeProcessor for further processing and code generation.
func (*SourceFile) Language ¶
func (sf *SourceFile) Language() psi.Language
func (*SourceFile) Load ¶
func (sf *SourceFile) Load() error
func (*SourceFile) MergeCompletionResults ¶
func (sf *SourceFile) MergeCompletionResults(ctx context.Context, scope psi.Scope, cursor psi.Cursor, newSource psi.SourceFile, newAst psi.Node) error
MergeCompletionResults merges the completion results of a code block into the NodeProcessor. It takes a context.Context, a *NodeScope representing the current scope, a *psi.Cursor representing the current cursor position, and a psi.Node representing the completion results. This function merges the completion results into the AST being processed in the NodeProcessor by performing the following steps: 1. Merge the completion results into the current AST by calling the MergeFiles function. 2. Iterate over each declaration in the completion results. 3. Check if the declaration is a function and if its name matches the name of the current scope's function. 4. If the declaration matches, replace the current declaration at the cursor position with the new declaration by calling the ReplaceDeclarationAt function. 5. If the declaration doesn't match, merge the new declaration with the existing declarations by calling the MergeDeclarations function. 6. Return nil, indicating that there were no errors during the merging process.
func (*SourceFile) MergeDeclarations ¶
MergeDeclarations merges the declarations of a node into the NodeProcessor. It takes a psi.Cursor and a psi.Node representing the current node, and returns a boolean value indicating whether the merging was successful or not.
The process of merging declarations involves the following steps: 1. Retrieve all declaration names from the node using the getDeclarationNames function. 2. For each declaration name, check if it already exists in the NodeProcessor. If not, insert the declaration at the cursor position using the InsertDeclarationAt function. 3. If the declaration already exists, check if the current cursor node is the same as the previous node. If so, replace the previous node with the current node's AST representation using the cursor.Replace function. 4. Update the existing declaration with the current node's index, name, and AST representation using the setExistingDeclaration function.
The purpose of MergeDeclarations is to ensure that all declarations within a node are properly merged into the NodeProcessor, allowing further processing and code generation to be performed accurately.
func (*SourceFile) Name ¶
func (sf *SourceFile) Name() string
func (*SourceFile) OriginalText ¶
func (sf *SourceFile) OriginalText() string
func (*SourceFile) Path ¶
func (sf *SourceFile) Path() string
func (*SourceFile) Replace ¶
func (sf *SourceFile) Replace(code string) error
func (*SourceFile) ReplaceDeclarationAt ¶
ReplaceDeclarationAt method replaces a declaration at a specific cursor position with a new declaration.
The ReplaceDeclarationAt method takes three parameters: a psi.Cursor, the declaration node to replace, and the name of the declaration.
The steps involved in the ReplaceDeclarationAt method are as follows: 1. The method replaces the declaration node at the cursor position with the new declaration node using the cursor.Replace method. 2. It gets the index of the new declaration in the root file's declarations using the slices.Index method. 3. It updates the existing declaration information in the NodeProcessor by calling the setExistingDeclaration method.
The purpose of the ReplaceDeclarationAt method is to provide a mechanism for replacing a declaration at a specific position in the AST and updating the declaration information in the NodeProcessor for further processing and code generation.
func (*SourceFile) Root ¶
func (sf *SourceFile) Root() psi.Node
type TypeSystemProvider ¶
type TypeSystemProvider struct {
// contains filtered or unexported fields
}
func NewTypeSystemProvider ¶
func NewTypeSystemProvider() *TypeSystemProvider
func (*TypeSystemProvider) IntrospectPackage ¶
func (tsp *TypeSystemProvider) IntrospectPackage(t *types.Package) *vts.Package
func (*TypeSystemProvider) IntrospectType ¶
func (tsp *TypeSystemProvider) IntrospectType(t types.Type) *vts.Type
func (*TypeSystemProvider) ResolvePackage ¶
func (tsp *TypeSystemProvider) ResolvePackage(name vts.PackageName) *vts.Package
func (*TypeSystemProvider) ResolveType ¶
func (tsp *TypeSystemProvider) ResolveType(name vts.TypeName) *vts.Type