inspector

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 4 Imported by: 0

README

Inspector Module

The inspector module builds code inspection information for the Playground, providing detailed AST, Type, Symbol, Signature, and Flow information.

Architecture Overview

┌─────────────────────────────────────────────────────────────────────────┐
│                           Frontend (React)                              │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│  ┌──────────────┐      ┌─────────────────────────────────────────────┐  │
│  │   Editor     │      │              AstInfoPanel                   │  │
│  │              │      │  ┌───────┬───────┬────────┬───────┐        │  │
│  │  cursor ─────┼──────┼─▶│ Node  │ Type  │ Symbol │ Flow  │ Tabs   │  │
│  │  position    │      │  └───┬───┴───┬───┴────┬───┴───┬───┘        │  │
│  │              │      │      ▼       ▼        ▼       ▼            │  │
│  │  ◀───────────┼──────┼─ InfoView  InfoView  InfoView  InfoView    │  │
│  │  highlight   │      │      │       │        │       │            │  │
│  └──────────────┘      └──────┼───────┼────────┼───────┼────────────┘  │
│                               │       │        │       │               │
│                               └───────┴────────┴───────┘               │
│                                       │                                │
│  ┌────────────────────────────────────┴────────────────────────────┐   │
│  │                    Lazy Loading Components                      │   │
│  │                                                                 │   │
│  │  LazyNodeView / LazyTypeView / LazySymbolView / LazySignatureView   │
│  │  ┌───────────────────────────────────────────────────────────┐  │   │
│  │  │ • Show shallow info initially (kind, pos, preview)        │  │   │
│  │  │ • On expand: fetch full info via context                  │  │   │
│  │  │ • Pass fileName for external file nodes                   │  │   │
│  │  │ • Highlight on hover (skip for external files)            │  │   │
│  │  └───────────────────────────────────────────────────────────┘  │   │
│  │                                                                 │   │
│  │  AstInfoContext: fetchAstInfo(pos, end, kind, fileName?)        │   │
│  └─────────────────────────────────────────────────────────────────┘   │
│                                    │                                   │
└────────────────────────────────────┼───────────────────────────────────┘
                                     │ IPC (JSON)
                                     ▼
┌────────────────────────────────────────────────────────────────────────┐
│                            Backend (Go)                                │
├────────────────────────────────────────────────────────────────────────┤
│                                                                        │
│  cmd/rslint/api.go: HandleGetAstInfo                                   │
│  ┌──────────────────────────────────────────────────────────────────┐  │
│  │ 1. Get/create cached Program                                     │  │
│  │ 2. Find node: FindNodeAtPosition(sourceFile, pos, end, kind)     │  │
│  │ 3. If fileName set → load external file, find node there         │  │
│  │ 4. Build response via inspector.Builder                          │  │
│  └──────────────────────────────────────────────────────────────────┘  │
│                                    │                                   │
│                                    ▼                                   │
│  internal/inspector/Builder                                            │
│  ┌──────────────────────────────────────────────────────────────────┐  │
│  │                                                                  │  │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────┐  │  │
│  │  │ builder_    │ │ builder_    │ │ builder_    │ │ builder_   │  │  │
│  │  │ node.go     │ │ type.go     │ │ symbol.go   │ │ flow.go    │  │  │
│  │  │             │ │             │ │             │ │            │  │  │
│  │  │ BuildNode-  │ │ BuildType-  │ │ BuildSymbol-│ │ BuildFlow- │  │  │
│  │  │ Info()      │ │ Info()      │ │ Info()      │ │ Info()     │  │  │
│  │  │ BuildShallow│ │ BuildShallow│ │ BuildShallow│ │ BuildFlow- │  │  │
│  │  │ NodeInfo()  │ │ TypeInfo()  │ │ SymbolInfo()│ │ Graph()    │  │  │
│  │  └─────────────┘ └─────────────┘ └─────────────┘ └────────────┘  │  │
│  │                                                                  │  │
│  │  helpers.go: FindNodeAtPosition, GetTypeAtNode, etc.             │  │
│  │  flags.go: GetNodeFlagNames, GetTypeFlagNames, etc.              │  │
│  └──────────────────────────────────────────────────────────────────┘  │
│                                    │                                   │
│                                    ▼                                   │
│  TypeScript-Go (checker.Checker, ast.Node, checker.Type, etc.)         │
└────────────────────────────────────────────────────────────────────────┘

Lazy Loading Data Flow

Initial Request                          Lazy Expand Request
─────────────────                        ───────────────────

User clicks code                         User expands "Parent" node
       │                                        │
       ▼                                        ▼
getAstInfo({ pos: 42 })                  getAstInfo({
       │                                   pos: 10,      ← from shallow
       ▼                                   end: 100,     ← from shallow
┌─────────────────────┐                    kind: 80,     ← from shallow
│ Response:           │                    fileName: ""  ← from shallow
│                     │                  })
│ node: { FULL }      │                         │
│ type: { FULL }      │                         ▼
│ symbol: { FULL }    │                  ┌─────────────────────┐
│                     │                  │ Response:           │
│ node.parent:        │                  │ node: { FULL }      │
│   { SHALLOW }  ─────┼─────────────────▶│ type: { FULL }      │
│ type.properties:    │                  │ ...                 │
│   [{ SHALLOW }]     │                  └─────────────────────┘
└─────────────────────┘

Shallow vs Full Info

Aspect Full Info Shallow Info
Built by BuildNodeInfo() BuildShallowNodeInfo()
Contains All fields + nested objects Basic fields only
Nested refs Shallow info None
Use case Top-level display Lazy-loadable references
Full Info Example:                    Shallow Info Example:
{                                     {
  id: 12345,                            kind: 211,
  kind: 80,                             kindName: "CallExpression",
  kindName: "Identifier",               pos: 0,
  pos: 42,                              end: 100,
  end: 49,                              fileName: "",  // optional
  text: "console",                      text: "log"    // optional
  parent: { shallow... },             }
  locals: [...],
  ...
}

External File Handling

When a node references external files (e.g., lib.d.ts):

Click on "console"
       │
       ▼
┌──────────────────────────────────────────────────┐
│ symbol.valueDeclaration: {                       │
│   kind: 260,                                     │
│   pos: 21850,        ← position in lib.dom.d.ts │
│   end: 21869,                                    │
│   fileName: "bundled:///libs/lib.dom.d.ts" ◀──── │
│ }                                                │
└──────────────────────────────────────────────────┘
       │
       │ User expands valueDeclaration
       ▼
┌──────────────────────────────────────────────────┐
│ getAstInfo({                                     │
│   pos: 21850,                                    │
│   end: 21869,                                    │
│   kind: 260,                                     │
│   fileName: "bundled:///libs/lib.dom.d.ts" ◀──── │
│ })                                               │
└──────────────────────────────────────────────────┘
       │
       ▼
Backend loads lib.dom.d.ts → finds node → returns full info

Note: Highlighting is disabled for external file nodes since positions don't correspond to the current editor content.

Symbol vs Type.Symbol

For an identifier like console, there are two different symbols:

Symbol Panel Type.Symbol
Source checker.GetSymbolAtLocation(node) type.Symbol()
Represents The value (variable console) The type (interface Console)
Flags Variable Interface
Declaration declare var console: Console interface Console { ... }

This reflects TypeScript's separation of values and types - they are intentionally different.

Directory Structure

internal/inspector/
├── types.go              # Data type definitions
├── builder.go            # Builder entry point
├── builder_node.go       # AST node info builder
├── builder_type.go       # Type info builder
├── builder_symbol.go     # Symbol info builder
├── builder_signature.go  # Signature info builder
├── builder_flow.go       # Control flow info builder
├── flags.go              # Flag name resolvers
└── helpers.go            # Helper functions

Core Types

Request/Response
// Request for AST info
type GetAstInfoRequest struct {
    FileContent     string         // Source code content
    Position        int            // Start position
    End             int            // End position (optional, for exact matching)
    Kind            int            // Node kind filter (optional)
    FileName        string         // Target file (empty for user file, external path for lib.d.ts etc.)
    CompilerOptions map[string]any // TypeScript compiler options
}

// Response
type GetAstInfoResponse struct {
    Node      *NodeInfo      // AST node info
    Type      *TypeInfo      // Type info
    Symbol    *SymbolInfo    // Symbol info
    Signature *SignatureInfo // Signature info
    Flow      *FlowInfo      // Control flow info
}
NodeInfo

Contains detailed AST node information:

Field Type Description
Id uint64 Node ID
Kind int Node kind (SyntaxKind)
KindName string Kind name (e.g., "Identifier")
Pos int Start position
End int End position
Flags int Node flags
FlagNames []string Flag name list
Text string Text content (identifiers/literals)
FileName string External file path (only for external nodes)
Parent *NodeInfo Parent node (shallow)
Name *NodeInfo Name node
Expression *NodeInfo Expression node
... More node-specific properties
TypeInfo

Contains TypeScript type information:

Field Type Description
Id uint32 Type ID
Flags uint32 TypeFlags
FlagNames []string Flag names
ObjectFlags uint32 ObjectFlags
TypeString string Type string representation
Symbol *SymbolInfo Associated symbol
TypeArguments []*TypeInfo Generic type arguments
Properties []*SymbolInfo Type properties
CallSignatures []*SignatureInfo Call signatures
... More type-specific properties
SymbolInfo

Contains symbol table information:

Field Type Description
Id uint64 Symbol ID
Name string Symbol name
EscapedName string Escaped name
Flags uint32 SymbolFlags
FlagNames []string Flag names
Declarations []*NodeInfo Declaration node list
ValueDeclaration *NodeInfo Primary value declaration
Members []*SymbolInfo Member symbols
Exports []*SymbolInfo Exported symbols
SignatureInfo

Contains function/method signature information:

Field Type Description
Flags uint32 SignatureFlags
MinArgumentCount int Minimum argument count
Parameters []*SymbolInfo Parameter symbol list
TypeParameters []*TypeInfo Type parameters
ReturnType *TypeInfo Return type
Declaration *NodeInfo Declaration node
FlowInfo

Contains control flow analysis information:

Field Type Description
Flags uint32 FlowFlags
FlagNames []string Flag names
Node *NodeInfo Associated AST node
Antecedent *FlowInfo Predecessor node
Antecedents []*FlowInfo Multiple predecessors (branch merge)
Graph *FlowGraph Complete flow graph (top-level only)

Builder Usage

import (
    "github.com/web-infra-dev/rslint/internal/inspector"
)

// Create Builder
builder := inspector.NewBuilder(typeChecker, sourceFile)

// Build node info
nodeInfo := builder.BuildNodeInfo(node)

// Build type info
typeInfo := builder.BuildTypeInfo(t)

// Build symbol info
symbolInfo := builder.BuildSymbolInfo(symbol)

// Build signature info
signatureInfo := builder.BuildSignatureInfo(sig)

// Build flow info
flowInfo := builder.BuildFlowInfo(flowNode)

Helper Functions

// Find node at specified position
node := inspector.FindNodeAtPosition(sourceFile, start, end, kind)

// Get type of a node
t := inspector.GetTypeAtNode(checker, node)

// Get signature of a node
sig := inspector.GetSignatureOfNode(checker, node)

// Get flow node of a node
flow := inspector.GetFlowNodeOfNode(node)

Lazy Loading Support

To support frontend lazy loading, info is built in two forms:

  1. Full info: Built via BuildNodeInfo, BuildTypeInfo, etc. Contains all fields.
  2. Shallow info: Built via BuildShallowNodeInfo, BuildShallowTypeInfo, etc. Contains only basic fields and position info.

Shallow info includes Pos, End, Kind, FileName fields, allowing the frontend to make new requests for full info.

External File Support

When a node comes from an external file (e.g., lib.d.ts):

  1. The FileName field is set to the external file path (e.g., bundled:///libs/lib.dom.d.ts)
  2. Frontend can request node info from that file by passing the FileName parameter
  3. Builder automatically handles position calculation for external file nodes

Documentation

Overview

Package inspector provides code inspection types and builders for the Playground

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddListMeta

func AddListMeta(info *NodeInfo, name string, list *ast.NodeList)

AddListMeta adds NodeList metadata for an array property

func FindNodeAtPosition

func FindNodeAtPosition(sourceFile *ast.SourceFile, start int, end int, kind int) *ast.Node

FindNodeAtPosition finds a node at the specified position in a source file. If end > 0, it uses exact matching (nodePos == start && nodeEnd == end) If kind > 0, it also checks that the node kind matches Otherwise, it finds the deepest node containing the position

func GetCheckFlagNames

func GetCheckFlagNames(flags ast.CheckFlags) []string

GetCheckFlagNames converts CheckFlags to a slice of flag names with package prefix

func GetFlowFlagNames

func GetFlowFlagNames(flags ast.FlowFlags) []string

GetFlowFlagNames converts FlowFlags to a slice of flag names with package prefix Note: Referenced and Shared are internal bookkeeping flags, not semantic flow types, so we exclude them

func GetFlowNodeOfNode

func GetFlowNodeOfNode(node *ast.Node) *ast.FlowNode

GetFlowNodeOfNode gets the FlowNode associated with an AST node

func GetNodeFlagNames

func GetNodeFlagNames(flags ast.NodeFlags) []string

GetNodeFlagNames converts NodeFlags to a slice of flag names with package prefix

func GetNodeText

func GetNodeText(node *ast.Node) string

GetNodeText extracts text content from simple nodes (identifiers and literals) For complex expressions, use scanner.GetSourceTextOfNodeFromSourceFile instead

func GetObjectFlagNames

func GetObjectFlagNames(flags checker.ObjectFlags) []string

GetObjectFlagNames converts ObjectFlags to a slice of flag names with package prefix

func GetSignatureFlagNames

func GetSignatureFlagNames(flags checker.SignatureFlags) []string

GetSignatureFlagNames converts SignatureFlags to a slice of flag names with package prefix

func GetSignatureOfNode

func GetSignatureOfNode(c *checker.Checker, node *ast.Node) *checker.Signature

GetSignatureOfNode gets the signature associated with a node

func GetSymbolFlagNames

func GetSymbolFlagNames(flags ast.SymbolFlags) []string

GetSymbolFlagNames converts SymbolFlags to a slice of flag names with package prefix

func GetTypeAtNode

func GetTypeAtNode(c *checker.Checker, node *ast.Node) *checker.Type

GetTypeAtNode gets the type of a node using the type checker

func GetTypeFlagNames

func GetTypeFlagNames(flags checker.TypeFlags) []string

GetTypeFlagNames converts TypeFlags to a slice of flag names with package prefix

func IsInternalSymbol

func IsInternalSymbol(symbol *ast.Symbol) bool

IsInternalSymbol checks if a symbol is an internal/synthetic symbol (like __call__, __new__, etc.)

func KindToString

func KindToString(kind ast.Kind) string

KindToString converts an AST Kind to a string representation with package prefix

func SafeCall

func SafeCall(fn func())

SafeCall executes a function and recovers from any panic

Types

type Builder

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

Builder builds AST info responses from TypeScript AST nodes

func NewBuilder

func NewBuilder(c *checker.Checker, sf *ast.SourceFile) *Builder

NewBuilder creates a new AST info builder

func (*Builder) BuildFlowGraph

func (b *Builder) BuildFlowGraph(flow *ast.FlowNode) *FlowGraph

BuildFlowGraph builds the complete flow graph by traversing all nodes

func (*Builder) BuildFlowInfo

func (b *Builder) BuildFlowInfo(flow *ast.FlowNode) *FlowInfo

BuildFlowInfo builds FlowInfo from a FlowNode Uses depth=4 for the top-level flow to show a reasonable chain while avoiding cycles Also builds the complete flow graph for visualization

func (*Builder) BuildFlowInfoWithDepth

func (b *Builder) BuildFlowInfoWithDepth(flow *ast.FlowNode, depth int) *FlowInfo

BuildFlowInfoWithDepth builds FlowInfo with a depth limit to avoid infinite recursion Flow graphs can have cycles (loops), so we need to limit how deep we go

func (*Builder) BuildNodeInfo

func (b *Builder) BuildNodeInfo(node *ast.Node) *NodeInfo

BuildNodeInfo builds NodeInfo from an AST node

func (*Builder) BuildShallowFlowInfo

func (b *Builder) BuildShallowFlowInfo(flow *ast.FlowNode) *FlowInfo

BuildShallowFlowInfo builds minimal FlowInfo for nested flow nodes (depth=1, no antecedents)

func (*Builder) BuildShallowNodeInfo

func (b *Builder) BuildShallowNodeInfo(node *ast.Node) *NodeInfo

BuildShallowNodeInfo builds minimal NodeInfo (only kind, pos, end) for nested nodes Note: ID is not included in shallow info as it changes on each request

func (*Builder) BuildShallowSignatureInfo

func (b *Builder) BuildShallowSignatureInfo(sig *checker.Signature) *SignatureInfo

BuildShallowSignatureInfo builds minimal SignatureInfo for nested signatures

func (*Builder) BuildShallowSymbolInfo

func (b *Builder) BuildShallowSymbolInfo(symbol *ast.Symbol) *SymbolInfo

BuildShallowSymbolInfo builds minimal SymbolInfo for nested symbols Returns nil for internal/synthetic symbols (compiler-generated virtual symbols)

func (*Builder) BuildShallowTypeInfo

func (b *Builder) BuildShallowTypeInfo(t *checker.Type) *TypeInfo

BuildShallowTypeInfo builds minimal TypeInfo for nested types Note: ID is not included in shallow info as it changes on each request

func (*Builder) BuildSignatureInfo

func (b *Builder) BuildSignatureInfo(sig *checker.Signature) *SignatureInfo

BuildSignatureInfo builds SignatureInfo from a Signature

func (*Builder) BuildSourceFileNodeInfo

func (b *Builder) BuildSourceFileNodeInfo(sf *ast.SourceFile) *NodeInfo

BuildSourceFileNodeInfo builds NodeInfo directly from a SourceFile without Node conversion

func (*Builder) BuildSymbolInfo

func (b *Builder) BuildSymbolInfo(symbol *ast.Symbol) *SymbolInfo

BuildSymbolInfo builds SymbolInfo from a Symbol Returns nil for internal/synthetic symbols (compiler-generated virtual symbols)

func (*Builder) BuildTypeInfo

func (b *Builder) BuildTypeInfo(t *checker.Type) *TypeInfo

BuildTypeInfo builds TypeInfo from a Type

func (*Builder) Checker

func (b *Builder) Checker() *checker.Checker

Checker returns the type checker

func (*Builder) GetTokenPos

func (b *Builder) GetTokenPos(node *ast.Node) int

GetTokenPos returns the actual start position of a node (skipping trivia like whitespace/comments)

func (*Builder) SafeGetTarget

func (b *Builder) SafeGetTarget(t *checker.Type) (result *checker.Type)

SafeGetTarget safely gets the Target of a type, returning nil if it panics or doesn't apply

func (*Builder) SourceFile

func (b *Builder) SourceFile() *ast.SourceFile

SourceFile returns the source file

type FlowEdge

type FlowEdge struct {
	From uint64 `json:"from"` // Antecedent node ID
	To   uint64 `json:"to"`   // Current node ID
}

FlowEdge represents an edge in the flow graph (from antecedent to current)

type FlowGraph

type FlowGraph struct {
	Nodes []*FlowGraphNode `json:"nodes"`
	Edges []*FlowEdge      `json:"edges"`
}

FlowGraph contains the complete flow graph for visualization

type FlowGraphNode

type FlowGraphNode struct {
	Id           uint64   `json:"id"`
	Flags        uint32   `json:"flags"`
	FlagNames    []string `json:"flagNames,omitempty"`
	NodePos      int      `json:"nodePos,omitempty"`
	NodeEnd      int      `json:"nodeEnd,omitempty"`
	NodeKindName string   `json:"nodeKindName,omitempty"`
	NodeText     string   `json:"nodeText,omitempty"` // Text content for identifiers/literals
}

FlowGraphNode represents a node in the flow graph

type FlowInfo

type FlowInfo struct {
	Flags       uint32      `json:"flags"`                 // FlowFlags
	FlagNames   []string    `json:"flagNames,omitempty"`   // Human-readable flag names
	Node        *NodeInfo   `json:"node,omitempty"`        // Associated AST node
	Antecedent  *FlowInfo   `json:"antecedent,omitempty"`  // Single antecedent
	Antecedents []*FlowInfo `json:"antecedents,omitempty"` // Multiple antecedents for labels
	Graph       *FlowGraph  `json:"graph,omitempty"`       // Complete flow graph (only on top-level)
}

FlowInfo contains control flow analysis information

type GetAstInfoRequest

type GetAstInfoRequest struct {
	FileContent     string         `json:"fileContent"`               // Source code content
	Position        int            `json:"position"`                  // Start position (pos)
	End             int            `json:"end,omitempty"`             // End position (optional, for exact node matching)
	Kind            int            `json:"kind,omitempty"`            // Optional: filter by node kind (when multiple nodes at same position)
	FileName        string         `json:"fileName,omitempty"`        // Target file to query (empty or /index.ts for user file, external path like lib.d.ts for external file)
	CompilerOptions map[string]any `json:"compilerOptions,omitempty"` // TypeScript compilerOptions (same as tsconfig.json)
}

GetAstInfoRequest represents a request for AST info at a specific position

type GetAstInfoResponse

type GetAstInfoResponse struct {
	Node      *NodeInfo      `json:"node,omitempty"`
	Type      *TypeInfo      `json:"type,omitempty"`
	Symbol    *SymbolInfo    `json:"symbol,omitempty"`
	Signature *SignatureInfo `json:"signature,omitempty"`
	Flow      *FlowInfo      `json:"flow,omitempty"`
}

GetAstInfoResponse contains detailed AST information at a position

type IndexInfoType

type IndexInfoType struct {
	KeyType    *TypeInfo `json:"keyType"`              // Key type (string, number, symbol)
	ValueType  *TypeInfo `json:"valueType"`            // Value type
	IsReadonly bool      `json:"isReadonly,omitempty"` // Whether the index signature is readonly
}

IndexInfoType contains information about an index signature

type NodeInfo

type NodeInfo struct {
	Id        uint64   `json:"id,omitempty"`        // Node ID
	Kind      int      `json:"kind"`                // AST node kind number
	KindName  string   `json:"kindName"`            // Human-readable kind name
	Pos       int      `json:"pos"`                 // Start position (in FileName if external, otherwise in current file)
	End       int      `json:"end"`                 // End position
	Flags     int      `json:"flags"`               // Node flags
	FlagNames []string `json:"flagNames,omitempty"` // Human-readable flag names
	Text      string   `json:"text,omitempty"`      // Text content for identifiers/literals
	FileName  string   `json:"fileName,omitempty"`  // Source file path (only set for external files like lib.d.ts)

	// Common node properties (shallow - only kind/pos/end for nested nodes)
	Parent        *NodeInfo `json:"parent,omitempty"`        // Parent node
	Name          *NodeInfo `json:"name,omitempty"`          // Name node (for declarations)
	Expression    *NodeInfo `json:"expression,omitempty"`    // Expression node
	Left          *NodeInfo `json:"left,omitempty"`          // Left operand (BinaryExpression)
	Right         *NodeInfo `json:"right,omitempty"`         // Right operand (BinaryExpression)
	OperatorToken *NodeInfo `json:"operatorToken,omitempty"` // Operator token (BinaryExpression)
	Operand       *NodeInfo `json:"operand,omitempty"`       // Operand (UnaryExpression)
	Condition     *NodeInfo `json:"condition,omitempty"`     // Condition (ConditionalExpression, IfStatement)
	WhenTrue      *NodeInfo `json:"whenTrue,omitempty"`      // True branch (ConditionalExpression)
	WhenFalse     *NodeInfo `json:"whenFalse,omitempty"`     // False branch (ConditionalExpression)
	ThenStatement *NodeInfo `json:"thenStatement,omitempty"` // Then branch (IfStatement)
	ElseStatement *NodeInfo `json:"elseStatement,omitempty"` // Else branch (IfStatement)
	Body          *NodeInfo `json:"body,omitempty"`          // Body node (functions, loops, etc.)
	Initializer   *NodeInfo `json:"initializer,omitempty"`   // Initializer (VariableDeclaration, etc.)
	TypeNode      *NodeInfo `json:"type,omitempty"`          // Type annotation node

	// Additional node properties for class/interface/function declarations
	Members         []*NodeInfo `json:"members,omitempty"`         // Members (ClassDeclaration, InterfaceDeclaration)
	HeritageClauses []*NodeInfo `json:"heritageClauses,omitempty"` // Heritage clauses (extends, implements)
	TypeParameters  []*NodeInfo `json:"typeParameters,omitempty"`  // Type parameters (generic declarations)
	Parameters      []*NodeInfo `json:"parameters,omitempty"`      // Parameters (FunctionDeclaration, MethodDeclaration)
	Modifiers       []*NodeInfo `json:"modifiers,omitempty"`       // Modifiers (public, private, static, etc.)
	Arguments       []*NodeInfo `json:"arguments,omitempty"`       // Arguments (CallExpression)
	Statements      []*NodeInfo `json:"statements,omitempty"`      // Statements (Block, SourceFile)
	Properties      []*NodeInfo `json:"properties,omitempty"`      // Properties (ObjectLiteralExpression)
	Elements        []*NodeInfo `json:"elements,omitempty"`        // Elements (ArrayLiteralExpression)

	// Variable/Declaration properties
	DeclarationList *NodeInfo   `json:"declarationList,omitempty"` // Declaration list (VariableStatement)
	Declarations    []*NodeInfo `json:"declarations,omitempty"`    // Declarations (VariableDeclarationList)

	// Import/Export properties
	ImportClause    *NodeInfo `json:"importClause,omitempty"`    // Import clause (ImportDeclaration)
	ModuleSpecifier *NodeInfo `json:"moduleSpecifier,omitempty"` // Module specifier (ImportDeclaration, ExportDeclaration)
	NamedBindings   *NodeInfo `json:"namedBindings,omitempty"`   // Named bindings (ImportClause)
	ExportClause    *NodeInfo `json:"exportClause,omitempty"`    // Export clause (ExportDeclaration)

	// Loop/Control flow properties
	Incrementor *NodeInfo `json:"incrementor,omitempty"` // Incrementor (ForStatement)
	Statement   *NodeInfo `json:"statement,omitempty"`   // Statement (loop body)

	// Switch statement properties
	CaseBlock *NodeInfo   `json:"caseBlock,omitempty"` // Case block (SwitchStatement)
	Clauses   []*NodeInfo `json:"clauses,omitempty"`   // Clauses (CaseBlock)

	// Try/Catch properties
	TryBlock            *NodeInfo `json:"tryBlock,omitempty"`            // Try block
	CatchClause         *NodeInfo `json:"catchClause,omitempty"`         // Catch clause
	FinallyBlock        *NodeInfo `json:"finallyBlock,omitempty"`        // Finally block
	VariableDeclaration *NodeInfo `json:"variableDeclaration,omitempty"` // Variable declaration (CatchClause)
	Block               *NodeInfo `json:"block,omitempty"`               // Block (CatchClause)

	// Property access properties
	ArgumentExpression *NodeInfo `json:"argumentExpression,omitempty"` // Argument expression (ElementAccessExpression)

	// Shorthand property assignment properties
	EqualsToken                 *NodeInfo `json:"equalsToken,omitempty"`                 // Equals token (ShorthandPropertyAssignment)
	ObjectAssignmentInitializer *NodeInfo `json:"objectAssignmentInitializer,omitempty"` // Object assignment initializer

	// Token properties (for optional/rest/generator/arrow/etc.)
	QuestionToken          *NodeInfo `json:"questionToken,omitempty"`          // Optional marker token (?)
	DotDotDotToken         *NodeInfo `json:"dotDotDotToken,omitempty"`         // Rest parameter token (...)
	ExclamationToken       *NodeInfo `json:"exclamationToken,omitempty"`       // Definite assignment token (!)
	AsteriskToken          *NodeInfo `json:"asteriskToken,omitempty"`          // Generator token (*)
	EqualsGreaterThanToken *NodeInfo `json:"equalsGreaterThanToken,omitempty"` // Arrow function token (=>)
	QuestionDotToken       *NodeInfo `json:"questionDotToken,omitempty"`       // Optional chaining token (?.)

	// Type-related node properties
	TypeArguments []*NodeInfo `json:"typeArguments,omitempty"` // Type arguments (CallExpression, NewExpression)
	Constraint    *NodeInfo   `json:"constraint,omitempty"`    // Type constraint (TypeParameterDeclaration)
	DefaultType   *NodeInfo   `json:"defaultType,omitempty"`   // Default type (TypeParameterDeclaration)

	// Template literal properties
	Head          *NodeInfo   `json:"head,omitempty"`          // Template head
	TemplateSpans []*NodeInfo `json:"templateSpans,omitempty"` // Template spans
	Literal       *NodeInfo   `json:"literal,omitempty"`       // Literal (TemplateSpan)
	Tag           *NodeInfo   `json:"tag,omitempty"`           // Tag (TaggedTemplateExpression)
	Template      *NodeInfo   `json:"template,omitempty"`      // Template (TaggedTemplateExpression)

	// Locals - symbols declared in this node's scope (shallow)
	Locals []*SymbolInfo `json:"locals,omitempty"`

	// SourceFile-specific properties
	EndOfFileToken    *NodeInfo   `json:"endOfFileToken,omitempty"`    // End of file token (SourceFile)
	Imports           []*NodeInfo `json:"imports,omitempty"`           // Import declarations (SourceFile)
	IsDeclarationFile bool        `json:"isDeclarationFile,omitempty"` // Whether this is a .d.ts file (SourceFile)
	ScriptKind        int         `json:"scriptKind,omitempty"`        // Script kind: 1=JS, 2=JSX, 3=TS, 4=TSX, 5=External, 6=JSON, 7=Deferred (SourceFile)
	IdentifierCount   int         `json:"identifierCount,omitempty"`   // Number of identifiers in file (SourceFile)
	SymbolCount       int         `json:"symbolCount,omitempty"`       // Number of symbols in file (SourceFile)
	NodeCount         int         `json:"nodeCount,omitempty"`         // Number of nodes in file (SourceFile)

	// List metadata for array properties (Pos, End, HasTrailingComma)
	// Key is the property name e.g. "Parameters", "Arguments", "Members"
	ListMetas map[string]*NodeListMeta `json:"listMetas,omitempty"`
}

NodeInfo contains detailed information about an AST node

type NodeListMeta

type NodeListMeta struct {
	Pos              int  `json:"pos"`
	End              int  `json:"end"`
	HasTrailingComma bool `json:"hasTrailingComma"`
}

NodeListMeta contains metadata about a NodeList

type SignatureInfo

type SignatureInfo struct {
	Flags            uint32   `json:"flags"`               // SignatureFlags
	FlagNames        []string `json:"flagNames,omitempty"` // Human-readable flag names
	MinArgumentCount int      `json:"minArgumentCount"`    // Minimum required arguments

	// Position for on-demand fetching (from declaration)
	Pos      int    `json:"pos,omitempty"`      // Position to fetch full signature info
	FileName string `json:"fileName,omitempty"` // Source file path (only set for external files)

	// Parameters and thisParameter use Symbol data (shallow)
	Parameters    []*SymbolInfo `json:"parameters,omitempty"`    // Parameter symbols (shallow)
	ThisParameter *SymbolInfo   `json:"thisParameter,omitempty"` // Explicit 'this' parameter symbol (shallow)

	// Type parameters, return type, and type predicate use Type data (shallow)
	TypeParameters []*TypeInfo        `json:"typeParameters,omitempty"` // Generic type parameters (shallow)
	ReturnType     *TypeInfo          `json:"returnType,omitempty"`     // Return type (shallow)
	TypePredicate  *TypePredicateInfo `json:"typePredicate,omitempty"`  // Type predicate for type guards

	// Declaration node (shallow)
	Declaration *NodeInfo `json:"declaration,omitempty"` // Source declaration (shallow)
}

SignatureInfo contains detailed information about a function/method signature For nested types, only basic info is included; use the declaration position to fetch full details

type SymbolInfo

type SymbolInfo struct {
	Id             uint64   `json:"id,omitempty"`             // Symbol ID
	Name           string   `json:"name"`                     // Symbol name (formatted for display)
	EscapedName    string   `json:"escapedName,omitempty"`    // Internal escaped name (formatted, only if different from Name)
	Flags          uint32   `json:"flags"`                    // SymbolFlags
	FlagNames      []string `json:"flagNames,omitempty"`      // Human-readable flag names
	CheckFlags     uint32   `json:"checkFlags"`               // CheckFlags (for transient symbols)
	CheckFlagNames []string `json:"checkFlagNames,omitempty"` // Human-readable check flag names

	// Position for on-demand fetching (from valueDeclaration or declarations[0])
	Pos      int    `json:"pos,omitempty"`      // Position to fetch full symbol info
	FileName string `json:"fileName,omitempty"` // Source file path (only set for external files)

	// Declaration nodes (shallow NodeInfo for lazy loading)
	Declarations     []*NodeInfo `json:"declarations,omitempty"`     // All declarations (as nodes)
	ValueDeclaration *NodeInfo   `json:"valueDeclaration,omitempty"` // Primary value declaration (as node)

	// Nested objects (shallow - only basic info included)
	Members []*SymbolInfo `json:"members,omitempty"` // Member symbols (shallow)
	Exports []*SymbolInfo `json:"exports,omitempty"` // Exported symbols (shallow)
}

SymbolInfo contains detailed information about a TypeScript symbol For nested symbols, only basic info is included; use the declaration position to fetch full details

type TypeInfo

type TypeInfo struct {
	Id              uint32   `json:"id,omitempty"`              // Type ID
	Flags           uint32   `json:"flags"`                     // TypeFlags
	FlagNames       []string `json:"flagNames,omitempty"`       // Human-readable flag names
	ObjectFlags     uint32   `json:"objectFlags,omitempty"`     // ObjectFlags for object types
	ObjectFlagNames []string `json:"objectFlagNames,omitempty"` // Human-readable object flag names
	IntrinsicName   string   `json:"intrinsicName,omitempty"`   // Name for intrinsic types
	TypeString      string   `json:"typeString"`                // String representation of the type

	// Position for on-demand fetching (from symbol's declaration)
	Pos      int    `json:"pos,omitempty"`      // Position to fetch full type info
	FileName string `json:"fileName,omitempty"` // Source file path (only set for external files)

	// Literal type properties (only present for literal types)
	Value       any       `json:"value,omitempty"`       // Literal value (string, number, bigint, boolean)
	FreshType   *TypeInfo `json:"freshType,omitempty"`   // Fresh literal type (shallow)
	RegularType *TypeInfo `json:"regularType,omitempty"` // Regular literal type (shallow)

	// Nested objects (shallow - only basic info included)
	Symbol              *SymbolInfo      `json:"symbol,omitempty"`              // Associated symbol (shallow)
	AliasSymbol         *SymbolInfo      `json:"aliasSymbol,omitempty"`         // Type alias symbol (shallow)
	TypeArguments       []*TypeInfo      `json:"typeArguments,omitempty"`       // Generic type arguments (shallow)
	BaseTypes           []*TypeInfo      `json:"baseTypes,omitempty"`           // Base types for class/interface (shallow)
	Properties          []*SymbolInfo    `json:"properties,omitempty"`          // Type properties (shallow)
	CallSignatures      []*SignatureInfo `json:"callSignatures,omitempty"`      // Call signatures
	ConstructSignatures []*SignatureInfo `json:"constructSignatures,omitempty"` // Construct signatures
	IndexInfos          []*IndexInfoType `json:"indexInfos,omitempty"`          // Index signatures
	Types               []*TypeInfo      `json:"types,omitempty"`               // Union/Intersection type members (shallow)
	Constraint          *TypeInfo        `json:"constraint,omitempty"`          // Type parameter constraint (shallow)
	Default             *TypeInfo        `json:"default,omitempty"`             // Type parameter default (shallow)
	Target              *TypeInfo        `json:"target,omitempty"`              // Target type for type references (shallow)
}

TypeInfo contains detailed information about a TypeScript type For nested types, only basic info is included; use the declaration position to fetch full details

type TypePredicateInfo

type TypePredicateInfo struct {
	Kind           int       `json:"kind"`     // TypePredicateKind numeric value
	KindName       string    `json:"kindName"` // Human-readable kind name
	ParameterName  string    `json:"parameterName,omitempty"`
	ParameterIndex int       `json:"parameterIndex"` // 0 is valid (first param), don't use omitempty
	Type           *TypeInfo `json:"type,omitempty"`
}

TypePredicateInfo contains information about a type predicate

Jump to

Keyboard shortcuts

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