Documentation
¶
Overview ¶
Package parser provides a protocol-independent intermediate representation (IR) for parsed YAML/JSON documents. It defines SemanticNode (a tree of typed nodes with source ranges), PointerIndex (O(1) JSON pointer to range lookup), and VirtualDocument (embedded content such as YAML literal blocks with position mapping back to the parent document). This package does not import any LSP or gossip types; it depends only on core/types for Range and Position.
Index ¶
- Constants
- Variables
- type ASTBuilder
- type CodeSampleProvider
- func (p *CodeSampleProvider) Complete(_ VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
- func (p *CodeSampleProvider) Diagnostics(_ VirtualDocument) ([]ctypes.Diagnostic, error)
- func (p *CodeSampleProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
- func (p *CodeSampleProvider) Hover(_ VirtualDocument, _ ctypes.Position) (*HoverResult, error)
- func (p *CodeSampleProvider) LanguageID() string
- type CompletionItem
- type EmbeddedLanguageProvider
- type ExampleProvider
- func (p *ExampleProvider) Complete(_ VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
- func (p *ExampleProvider) Diagnostics(_ VirtualDocument) ([]ctypes.Diagnostic, error)
- func (p *ExampleProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
- func (p *ExampleProvider) Hover(_ VirtualDocument, _ ctypes.Position) (*HoverResult, error)
- func (p *ExampleProvider) LanguageID() string
- type FoldedBlockMapper
- type HoverResult
- type IdentityMapper
- type LiteralBlockMapper
- type MarkdownProvider
- func (p *MarkdownProvider) Complete(vdoc VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
- func (p *MarkdownProvider) Diagnostics(vdoc VirtualDocument) ([]ctypes.Diagnostic, error)
- func (p *MarkdownProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
- func (p *MarkdownProvider) Hover(vdoc VirtualDocument, _ ctypes.Position) (*HoverResult, error)
- func (p *MarkdownProvider) LanguageID() string
- type NodeKind
- type OffsetMapper
- type Parser
- type PointerIndex
- type QuotedStringMapper
- type SemanticNode
- type VirtualDocument
- type VirtualDocumentManager
- func (m *VirtualDocumentManager) FindAtPosition(parentURI string, pos ctypes.Position) *VirtualDocument
- func (m *VirtualDocumentManager) ForParent(parentURI string) []VirtualDocument
- func (m *VirtualDocumentManager) Get(uri string) *VirtualDocument
- func (m *VirtualDocumentManager) Providers() []EmbeddedLanguageProvider
- func (m *VirtualDocumentManager) Remove(parentURI string)
- func (m *VirtualDocumentManager) Update(parentURI string, root *SemanticNode)
Constants ¶
const ( NodeMapping = navigator.NodeMapping NodeSequence = navigator.NodeSequence NodeScalar = navigator.NodeScalar NodeNull = navigator.NodeNull )
NodeKind constants.
Variables ¶
var BuildPointerIndex = navigator.BuildPointerIndex
BuildPointerIndex delegates to navigator.BuildPointerIndex.
var NewPointerIndex = navigator.NewPointerIndex
NewPointerIndex delegates to navigator.NewPointerIndex.
Functions ¶
This section is empty.
Types ¶
type ASTBuilder ¶
type ASTBuilder struct {
// contains filtered or unexported fields
}
ASTBuilder converts a tree-sitter CST into a SemanticNode IR tree.
type CodeSampleProvider ¶
type CodeSampleProvider struct{}
CodeSampleProvider extracts x-codeSamples source content for syntax validation.
func (*CodeSampleProvider) Complete ¶
func (p *CodeSampleProvider) Complete(_ VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
func (*CodeSampleProvider) Diagnostics ¶
func (p *CodeSampleProvider) Diagnostics(_ VirtualDocument) ([]ctypes.Diagnostic, error)
func (*CodeSampleProvider) Extract ¶
func (p *CodeSampleProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
func (*CodeSampleProvider) Hover ¶
func (p *CodeSampleProvider) Hover(_ VirtualDocument, _ ctypes.Position) (*HoverResult, error)
func (*CodeSampleProvider) LanguageID ¶
func (p *CodeSampleProvider) LanguageID() string
type CompletionItem ¶
type CompletionItem struct {
Label string
Detail string
InsertText string
Kind int // maps to LSP CompletionItemKind
}
CompletionItem is a completion suggestion from an embedded language provider.
type EmbeddedLanguageProvider ¶
type EmbeddedLanguageProvider interface {
// LanguageID returns the embedded language identifier (e.g. "markdown").
LanguageID() string
// Extract finds all embedded content regions in the given node tree.
Extract(root *SemanticNode, parentURI string) []VirtualDocument
// Hover returns hover information for a position within a virtual document.
Hover(vdoc VirtualDocument, pos ctypes.Position) (*HoverResult, error)
// Complete returns completion items for a position within a virtual document.
Complete(vdoc VirtualDocument, pos ctypes.Position) ([]CompletionItem, error)
// Diagnostics validates the virtual document content and returns diagnostics.
Diagnostics(vdoc VirtualDocument) ([]ctypes.Diagnostic, error)
}
EmbeddedLanguageProvider detects and extracts embedded content from a semantic node.
type ExampleProvider ¶
type ExampleProvider struct{}
ExampleProvider validates example values embedded in OpenAPI specs against their surrounding schema context.
func (*ExampleProvider) Complete ¶
func (p *ExampleProvider) Complete(_ VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
func (*ExampleProvider) Diagnostics ¶
func (p *ExampleProvider) Diagnostics(_ VirtualDocument) ([]ctypes.Diagnostic, error)
func (*ExampleProvider) Extract ¶
func (p *ExampleProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
func (*ExampleProvider) Hover ¶
func (p *ExampleProvider) Hover(_ VirtualDocument, _ ctypes.Position) (*HoverResult, error)
func (*ExampleProvider) LanguageID ¶
func (p *ExampleProvider) LanguageID() string
type FoldedBlockMapper ¶
type FoldedBlockMapper struct {
StartLine uint32 // source line where content begins (after > indicator)
IndentCols uint32 // columns of indentation stripped
}
FoldedBlockMapper handles YAML folded block scalars (>). Lines are folded (newlines become spaces except for blank-line-separated paragraphs).
type HoverResult ¶
HoverResult is a hover response from an embedded language provider.
type IdentityMapper ¶
IdentityMapper passes positions through unchanged (for quoted/flow scalars).
type LiteralBlockMapper ¶
type LiteralBlockMapper struct {
StartLine uint32 // source line where content begins (after | indicator)
IndentCols uint32 // columns of indentation stripped
}
LiteralBlockMapper handles YAML literal block scalars (|).
type MarkdownProvider ¶
type MarkdownProvider struct{}
MarkdownProvider extracts Markdown content from description fields.
func (*MarkdownProvider) Complete ¶
func (p *MarkdownProvider) Complete(vdoc VirtualDocument, _ ctypes.Position) ([]CompletionItem, error)
func (*MarkdownProvider) Diagnostics ¶
func (p *MarkdownProvider) Diagnostics(vdoc VirtualDocument) ([]ctypes.Diagnostic, error)
func (*MarkdownProvider) Extract ¶
func (p *MarkdownProvider) Extract(root *SemanticNode, parentURI string) []VirtualDocument
func (*MarkdownProvider) Hover ¶
func (p *MarkdownProvider) Hover(vdoc VirtualDocument, _ ctypes.Position) (*HoverResult, error)
func (*MarkdownProvider) LanguageID ¶
func (p *MarkdownProvider) LanguageID() string
type OffsetMapper ¶
type OffsetMapper interface {
ToSource(virtual ctypes.Position) ctypes.Position
ToVirtual(source ctypes.Position) ctypes.Position
}
OffsetMapper translates positions between a virtual document and its source.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser wraps tree-sitter YAML and JSON grammars for incremental parsing.
type PointerIndex ¶
type PointerIndex = navigator.PointerIndex
PointerIndex is an alias for navigator.PointerIndex.
type QuotedStringMapper ¶
type QuotedStringMapper struct {
StartLine uint32 // source line of the opening quote
StartCol uint32 // source column after the opening quote character
}
QuotedStringMapper handles quoted YAML strings with escape sequences.
type SemanticNode ¶
type SemanticNode = navigator.SemanticNode
SemanticNode is an alias for navigator.SemanticNode.
func BuildFromCST ¶
func BuildFromCST(root *sitter.Node, source []byte) (*SemanticNode, error)
BuildFromCST creates a SemanticNode tree from a tree-sitter root node.
func BuildFromRaw ¶
func BuildFromRaw(content []byte, format string) *SemanticNode
BuildFromRaw creates a SemanticNode from raw YAML/JSON bytes without tree-sitter. This fallback uses gopkg.in/yaml.v3 to produce a basic semantic tree.
type VirtualDocument ¶
type VirtualDocument struct {
URI string // synthetic URI (e.g., "vdoc://file.yaml#/paths/~1users/get/description")
LanguageID string // e.g. "markdown"
Content string
SourceURI string // parent document URI
SourceRange ctypes.Range // range in parent document
Mapper OffsetMapper
}
func ExtractVirtualDocuments ¶
func ExtractVirtualDocuments(node *SemanticNode, uri string, providers []EmbeddedLanguageProvider) []VirtualDocument
ExtractVirtualDocuments aggregates results from all providers into a single sorted slice.
type VirtualDocumentManager ¶
type VirtualDocumentManager struct {
// contains filtered or unexported fields
}
VirtualDocumentManager maintains the set of virtual documents for all source documents.
func NewVirtualDocumentManager ¶
func NewVirtualDocumentManager(providers ...EmbeddedLanguageProvider) *VirtualDocumentManager
NewVirtualDocumentManager creates a manager with the given providers.
func (*VirtualDocumentManager) FindAtPosition ¶
func (m *VirtualDocumentManager) FindAtPosition(parentURI string, pos ctypes.Position) *VirtualDocument
FindAtPosition finds the virtual document containing the given position in the parent document.
func (*VirtualDocumentManager) ForParent ¶
func (m *VirtualDocumentManager) ForParent(parentURI string) []VirtualDocument
ForParent returns all virtual documents for a parent URI.
func (*VirtualDocumentManager) Get ¶
func (m *VirtualDocumentManager) Get(uri string) *VirtualDocument
Get returns the virtual document for a URI.
func (*VirtualDocumentManager) Providers ¶
func (m *VirtualDocumentManager) Providers() []EmbeddedLanguageProvider
Providers returns the registered embedded language providers.
func (*VirtualDocumentManager) Remove ¶
func (m *VirtualDocumentManager) Remove(parentURI string)
Remove removes all virtual documents for a parent URI.
func (*VirtualDocumentManager) Update ¶
func (m *VirtualDocumentManager) Update(parentURI string, root *SemanticNode)
Update regenerates virtual documents for a parent document.