Documentation ¶
Index ¶
- Variables
- func ResolveEdge[T Node](parent Node, key TypedEdgeKey[T]) (def T)
- func Walk(node Node, walkFn WalkFunc) error
- type BaseGraph
- func (g *BaseGraph) Add(n Node)
- func (g *BaseGraph) Edges() EdgeIterator
- func (g *BaseGraph) Init(self Graph)
- func (g *BaseGraph) NextEdgeID() EdgeID
- func (g *BaseGraph) NextNodeID() int64
- func (g *BaseGraph) Nodes() NodeIterator
- func (g *BaseGraph) OnNodeInvalidated(n Node)
- func (g *BaseGraph) OnNodeUpdated(n Node)
- func (g *BaseGraph) Remove(n Node)
- func (g *BaseGraph) Replace(old, new Node)
- func (g *BaseGraph) SetEdge(e Edge)
- func (g *BaseGraph) UnsetEdge(self Edge)
- type Cursor
- type Edge
- type EdgeBase
- type EdgeID
- type EdgeIterator
- type EdgeKey
- type EdgeKind
- type EdgeReference
- type Freezer
- type Graph
- type InvalidationListener
- type Language
- type LanguageID
- type NamedNode
- type Node
- type NodeBase
- func (n *NodeBase) AddChildNode(child Node)
- func (n *NodeBase) Attributes() map[string]interface{}
- func (n *NodeBase) CanonicalPath() (res Path)
- func (n *NodeBase) Children() []Node
- func (n *NodeBase) ChildrenIterator() NodeIterator
- func (n *NodeBase) ChildrenList() collectionsfx.ObservableList[Node]
- func (n *NodeBase) Comments() []string
- func (n *NodeBase) Edges() EdgeIterator
- func (n *NodeBase) GetAttribute(key string) (value any, ok bool)
- func (n *NodeBase) GetEdge(key EdgeReference) Edge
- func (n *NodeBase) ID() int64
- func (n *NodeBase) IndexOfChild(node Node) int
- func (n *NodeBase) Init(self Node, uid string)
- func (n *NodeBase) InsertChildAfter(anchor, node Node)
- func (n *NodeBase) InsertChildBefore(anchor, node Node)
- func (n *NodeBase) InsertChildrenAt(idx int, child Node)
- func (n *NodeBase) Invalidate()
- func (n *NodeBase) InvalidateTree()
- func (n *NodeBase) IsContainer() bool
- func (n *NodeBase) IsLeaf() bool
- func (n *NodeBase) IsValid() bool
- func (n *NodeBase) NextSibling() Node
- func (n *NodeBase) Parent() Node
- func (n *NodeBase) ParentProperty() obsfx.ObservableValue[Node]
- func (n *NodeBase) PreviousSibling() Node
- func (n *NodeBase) PsiNode() Node
- func (n *NodeBase) PsiNodeBase() *NodeBase
- func (n *NodeBase) PsiNodeType() NodeType
- func (n *NodeBase) PsiNodeVersion() int64
- func (n *NodeBase) RemoveAttribute(key string) (value any, ok bool)
- func (n *NodeBase) RemoveChildNode(child Node)
- func (n *NodeBase) ReplaceChildNode(old, new Node)
- func (n *NodeBase) ResolveChild(component PathElement) Node
- func (n *NodeBase) SetAttribute(key string, value any)
- func (n *NodeBase) SetEdge(key EdgeReference, to Node)
- func (n *NodeBase) SetParent(parent Node)
- func (n *NodeBase) String() string
- func (n *NodeBase) UUID() string
- func (n *NodeBase) UnsetEdge(key EdgeReference)
- func (n *NodeBase) Update(ctx context.Context) error
- type NodeClass
- type NodeID
- type NodeIterator
- type NodeLike
- type NodeLikeBase
- type NodeType
- type NodeTypeOption
- type Path
- func (p Path) Child(name PathElement) (res Path)
- func (p Path) Components() []PathElement
- func (p Path) IsEmpty() bool
- func (p Path) Join(other Path) (res Path)
- func (p Path) MarshalJSON() ([]byte, error)
- func (p Path) Parent() Path
- func (p Path) Root() Node
- func (p Path) String() (res string)
- func (p *Path) UnmarshalJSON(data []byte) error
- func (p Path) WithRoot(root Node) Path
- type PathElement
- type PhysAddr
- type RawAttribute
- type RawEdge
- type RawNode
- type RawNodeEntry
- type RawPointer
- type Scope
- type SourceFile
- type TypedEdgeKey
- type TypedEdgeKind
- type TypedNodeType
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
var EdgeKindChild = EdgeKind("child")
var ErrAbort = errors.New("abort")
var ErrNodeNotFound = errors.New("node not found")
Functions ¶
func ResolveEdge ¶
func ResolveEdge[T Node](parent Node, key TypedEdgeKey[T]) (def T)
Types ¶
type BaseGraph ¶
type BaseGraph struct {
// contains filtered or unexported fields
}
func (*BaseGraph) Edges ¶
func (g *BaseGraph) Edges() EdgeIterator
func (*BaseGraph) NextEdgeID ¶
func (*BaseGraph) NextNodeID ¶
func (*BaseGraph) Nodes ¶
func (g *BaseGraph) Nodes() NodeIterator
func (*BaseGraph) OnNodeInvalidated ¶
func (*BaseGraph) OnNodeUpdated ¶
type Cursor ¶
type Cursor interface { Depth() int // Current returns the current node. Node() Node // SetCurrent sets the current node. SetCurrent(node Node) SetNext(node Node) // WalkChildren walks the children of the current node. WalkChildren() // SkipChildren skips the children of the current node. SkipChildren() // WalkEdges walks the edges of the current node. WalkEdges() // SkipEdges skips the edges of the current node. SkipEdges() // Replace replaces the current node with the given node, modifying the AST. // If this operation happens during the enter phase, the children of the new node will be visited. // If this operation happens during the leave phase, the children of the new node will NOT be visited. Replace(node Node) // InsertBefore inserts the given node before the current node, modifying the AST. // This node will NOT be visited in the current walk. InsertBefore(node Node) // InsertAfter inserts the given node before the current node, modifying the AST. // This node might be visited in the current walk. InsertAfter(node Node) }
Cursor is a stateful tree traversal interface.
type EdgeBase ¶
type EdgeBase struct {
// contains filtered or unexported fields
}
func NewEdgeBase ¶
func NewEdgeBase(key EdgeReference, from Node, to Node) *EdgeBase
func (*EdgeBase) Key ¶
func (e *EdgeBase) Key() EdgeReference
func (*EdgeBase) ReplaceFrom ¶
type EdgeIterator ¶
type EdgeKey ¶
type EdgeReference ¶
type Freezer ¶
type Freezer struct { Cas map[cid.Cid][]byte `json:"Cas"` Cache map[cid.Cid]RawNode `json:"-"` IdMap map[NodeID]cid.Cid `json:"IdMap"` }
func (*Freezer) Add ¶
func (f *Freezer) Add(n Node) (entry RawNodeEntry)
type InvalidationListener ¶
type InvalidationListener interface {
OnInvalidated(n Node)
}
func InvalidationListenerFunc ¶
func InvalidationListenerFunc(f func(n Node)) InvalidationListener
type Language ¶
type Language interface { Name() LanguageID Extensions() []string CreateSourceFile(fileName string, fileHandle repofs.FileHandle) SourceFile Parse(fileName string, code string) (SourceFile, error) ParseCodeBlock(name string, block mdutils.CodeBlock) (SourceFile, error) }
type LanguageID ¶
type LanguageID string
type Node ¶
type Node interface { NodeLike ID() int64 UUID() NodeID CanonicalPath() Path Parent() Node PreviousSibling() Node NextSibling() Node // SetParent sets the parent node of the current node. // If the parent node is already set to the given parent, no action is taken. // If the current node has a parent, it is first removed from its parent node. // Then, the parent node is set to the given parent. // If the parent node is not nil, the current node is added as a child to the parent node. // If the parent node is nil, the current node is detached from the graph. SetParent(parent Node) Children() []Node ChildrenList() collectionsfx.ObservableList[Node] ChildrenIterator() NodeIterator Comments() []string IsContainer() bool IsLeaf() bool ResolveChild(component PathElement) Node // Edges returns the edges of the current node. Edges() EdgeIterator // SetEdge sets the edge with the given key to the given node. SetEdge(key EdgeReference, to Node) // UnsetEdge removes the edge with the given key. UnsetEdge(key EdgeReference) // GetEdge returns the edge with the given key. GetEdge(key EdgeReference) Edge // Attributes returns the attributes of the current node. Attributes() map[string]interface{} // SetAttribute sets the attribute with the given key to the given value. SetAttribute(key string, value any) // GetAttribute returns the attribute with the given key. GetAttribute(key string) (any, bool) // RemoveAttribute removes the attribute with the given key. RemoveAttribute(key string) (any, bool) IsValid() bool Invalidate() Update(context.Context) error AddChildNode(node Node) RemoveChildNode(node Node) ReplaceChildNode(old Node, node Node) InsertChildrenAt(idx int, child Node) InsertChildBefore(anchor Node, node Node) InsertChildAfter(anchor Node, node Node) String() string // contains filtered or unexported methods }
Node represents a PSI element in the graph.
type NodeBase ¶
type NodeBase struct {
// contains filtered or unexported fields
}
func (*NodeBase) AddChildNode ¶
AddChildNode adds a child node to the current node. If the child node is already a child of the current node, no action is taken. The child node is appended to the list of children nodes of the current node. Then, the child node is attached to the same graph as the parent node.
Parameters: - child: The child node to be added.
func (*NodeBase) Attributes ¶
func (*NodeBase) CanonicalPath ¶
func (*NodeBase) ChildrenIterator ¶
func (n *NodeBase) ChildrenIterator() NodeIterator
func (*NodeBase) ChildrenList ¶
func (n *NodeBase) ChildrenList() collectionsfx.ObservableList[Node]
func (*NodeBase) Edges ¶
func (n *NodeBase) Edges() EdgeIterator
func (*NodeBase) GetEdge ¶
func (n *NodeBase) GetEdge(key EdgeReference) Edge
func (*NodeBase) IndexOfChild ¶
func (*NodeBase) Init ¶
Init initializes the NodeBase struct with the given self node and uid string. It sets the self node, uuid, and initializes the edges map. If the uuid is an empty string, it generates a new UUID using the github.com/google/uuid package.
Parameters: - self: The self node to be set. - uid: The UUID string to be set.
func (*NodeBase) InsertChildAfter ¶
func (*NodeBase) InsertChildBefore ¶
func (*NodeBase) InsertChildrenAt ¶
func (*NodeBase) Invalidate ¶
func (n *NodeBase) Invalidate()
func (*NodeBase) InvalidateTree ¶
func (n *NodeBase) InvalidateTree()
func (*NodeBase) IsContainer ¶
func (*NodeBase) NextSibling ¶
func (*NodeBase) ParentProperty ¶
func (n *NodeBase) ParentProperty() obsfx.ObservableValue[Node]
func (*NodeBase) PreviousSibling ¶
func (*NodeBase) PsiNodeBase ¶
func (*NodeBase) PsiNodeType ¶
func (*NodeBase) PsiNodeVersion ¶
func (*NodeBase) RemoveAttribute ¶
func (*NodeBase) RemoveChildNode ¶
RemoveChildNode removes the child node from the current node. If the child node is not a child of the current node, no action is taken.
Parameters: - child: The child node to be removed.
func (*NodeBase) ReplaceChildNode ¶
ReplaceChildNode replaces an old child node with a new child node in the current node. If the old child node is not a child of the current node, no action is taken. The old child node is first removed from its parent node and detached from the graph. Then, the new child node is set as the replacement at the same index in the list of children nodes of the current node. The new child node is attached to the same graph as the parent node. Finally, any edges in the current node that reference the old child node as the destination node are updated to reference the new child node.
Parameters: - old: The old child node to be replaced. - new: The new child node to replace the old child node.
func (*NodeBase) ResolveChild ¶
func (n *NodeBase) ResolveChild(component PathElement) Node
func (*NodeBase) SetAttribute ¶
func (*NodeBase) SetEdge ¶
func (n *NodeBase) SetEdge(key EdgeReference, to Node)
func (*NodeBase) UnsetEdge ¶
func (n *NodeBase) UnsetEdge(key EdgeReference)
type NodeIterator ¶
func AppendNodeIterator ¶
func AppendNodeIterator(iterators ...NodeIterator) NodeIterator
type NodeLikeBase ¶
type NodeLikeBase struct {
NodeBase NodeBase
}
func (*NodeLikeBase) PsiNode ¶
func (n *NodeLikeBase) PsiNode() Node
func (*NodeLikeBase) PsiNodeBase ¶
func (n *NodeLikeBase) PsiNodeBase() *NodeBase
func (*NodeLikeBase) PsiNodeType ¶
func (n *NodeLikeBase) PsiNodeType() NodeType
func (*NodeLikeBase) PsiNodeVersion ¶
func (n *NodeLikeBase) PsiNodeVersion() int64
type NodeTypeOption ¶
type NodeTypeOption func(*nodeType)
func WithNodeClass ¶
func WithNodeClass(class NodeClass) NodeTypeOption
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
func MustParsePath ¶
func PathFromComponents ¶
func PathFromComponents(components ...PathElement) Path
func ResolveChild ¶
func ResolveChild(parent Path, child PathElement) Path
func (Path) Child ¶
func (p Path) Child(name PathElement) (res Path)
func (Path) Components ¶
func (p Path) Components() []PathElement
func (Path) MarshalJSON ¶
func (*Path) UnmarshalJSON ¶
type PathElement ¶
func ParsePathComponent ¶
func ParsePathComponent(str string) (e PathElement, err error)
func (PathElement) IsEmpty ¶
func (p PathElement) IsEmpty() bool
func (PathElement) String ¶
func (p PathElement) String() string
type RawAttribute ¶
type RawNode ¶
type RawNode struct { ID int64 `json:"ID"` UUID string `json:"UUID"` Attributes []RawAttribute `json:"Attributes"` Edges []RawEdge `json:"Edges"` Children []RawNodeEntry `json:"Children"` }
type RawNodeEntry ¶
type RawPointer ¶
type SourceFile ¶
type SourceFile interface { Node Name() string Language() Language Root() Node Error() error Load() error Replace(code string) error OriginalText() string ToCode(node Node) (mdutils.CodeBlock, error) MergeCompletionResults(ctx context.Context, scope Scope, cursor Cursor, newSource SourceFile, newAst Node) error }
type TypedEdgeKey ¶
type TypedEdgeKey[T Node] struct { Kind TypedEdgeKind[T] `json:"Kind"` Name string `json:"Name"` Index int64 `json:"Index"` }
func (TypedEdgeKey[T]) GetIndex ¶
func (k TypedEdgeKey[T]) GetIndex() int64
func (TypedEdgeKey[T]) GetKey ¶
func (k TypedEdgeKey[T]) GetKey() EdgeKey
func (TypedEdgeKey[T]) GetKind ¶
func (k TypedEdgeKey[T]) GetKind() EdgeKind
func (TypedEdgeKey[T]) GetName ¶
func (k TypedEdgeKey[T]) GetName() string
func (TypedEdgeKey[T]) String ¶
func (k TypedEdgeKey[T]) String() string
type TypedEdgeKind ¶
func (TypedEdgeKind[T]) Singleton ¶
func (f TypedEdgeKind[T]) Singleton() TypedEdgeKey[T]
type TypedNodeType ¶
func RegisterNodeType ¶
func RegisterNodeType[T Node](name string, options ...NodeTypeOption) TypedNodeType[T]