golang

package
v0.0.0-...-7b96089 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const EdgeKindDeclarations psi.EdgeKind = "Decls"
View Source
const LanguageID psi.LanguageID = "go"

Variables

This section is empty.

Functions

func MergeFiles

func MergeFiles(file1, file2 *dst.File) *dst.File

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)

func (BufferFileHandle) Put

func (b BufferFileHandle) Put(src io.Reader) error

type Container

type Container struct {
	NodeBase[dst.Node]
}

func NewContainer

func NewContainer(node dst.Node) *Container

func (*Container) IsContainer

func (c *Container) IsContainer() bool

func (*Container) IsLeaf

func (c *Container) IsLeaf() bool

type Language

type Language struct {
	// contains filtered or unexported fields
}

func NewLanguage

func NewLanguage(p project2.Project) *Language

func (*Language) CreateSourceFile

func (l *Language) CreateSourceFile(fileName string, fileHandle repofs.FileHandle) psi.SourceFile

func (*Language) Extensions

func (l *Language) Extensions() []string

func (*Language) Name

func (l *Language) Name() psi.LanguageID

func (*Language) Parse

func (l *Language) Parse(fileName string, code string) (psi.SourceFile, error)

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

type Leaf struct {
	NodeBase[dst.Node]
}

func NewLeaf

func NewLeaf(node dst.Node) *Leaf

func (*Leaf) IsContainer

func (f *Leaf) IsContainer() bool

func (*Leaf) IsLeaf

func (f *Leaf) IsLeaf() bool

type Node

type Node interface {
	psi.Node

	Ast() dst.Node
	Initialize(self Node)
}

func AstToPsi

func AstToPsi(root dst.Node) (result Node)

func NewNodeFor

func NewNodeFor(node dst.Node) Node

type NodeBase

type NodeBase[T dst.Node] struct {
	psi.NodeBase
	// contains filtered or unexported fields
}

func (*NodeBase[T]) Ast

func (nb *NodeBase[T]) Ast() dst.Node

func (*NodeBase[T]) Comments

func (nb *NodeBase[T]) Comments() []string

func (*NodeBase[T]) Initialize

func (nb *NodeBase[T]) Initialize(self Node)

func (*NodeBase[T]) String

func (nb *NodeBase[T]) String() string

func (*NodeBase[T]) Update

func (nb *NodeBase[T]) Update(context.Context) error

type SourceFile

type SourceFile struct {
	psi.NodeBase
	// contains filtered or unexported fields
}

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

func (sf *SourceFile) InsertDeclarationAt(cursor psi.Cursor, name string, decl psi.Node)

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

func (sf *SourceFile) MergeDeclarations(cursor psi.Cursor, node psi.Node) bool

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) Parse

func (sf *SourceFile) Parse(filename string, sourceCode string) (result psi.Node, err error)

func (*SourceFile) Path

func (sf *SourceFile) Path() string

func (*SourceFile) Replace

func (sf *SourceFile) Replace(code string) error

func (*SourceFile) ReplaceDeclarationAt

func (sf *SourceFile) ReplaceDeclarationAt(cursor psi.Cursor, decl psi.Node, name string)

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

func (*SourceFile) SetRoot

func (sf *SourceFile) SetRoot(node *dst.File) error

func (*SourceFile) ToCode

func (sf *SourceFile) ToCode(node psi.Node) (mdutils.CodeBlock, error)

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

Jump to

Keyboard shortcuts

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