/** * @packageDocumentation * * Public analysis protocol types and runtime helpers for FormSpec tooling. */ import type { ExtensionDefinition } from '@stripe/formspec-core'; import type { LoggerLike } from '@stripe/formspec-core'; import type { MetadataAnalysisResult } from '@stripe/formspec-core'; import type { MetadataPolicyInput } from '@stripe/formspec-core'; import * as ts from 'typescript'; /** * Analyze shared metadata semantics for a single declaration node. * * @public */ export declare function analyzeMetadataForNode(options: AnalyzeMetadataForNodeOptions): MetadataAnalysisResult | null; /** * Options for analyzing one declaration node. * * @public */ export declare interface AnalyzeMetadataForNodeOptions extends AnalyzeMetadataOptions { /** Declaration node to analyze. */ readonly node: ts.Node; } /** * Analyze shared metadata semantics for all supported declarations in a source file. * * @public */ export declare function analyzeMetadataForSourceFile(options: AnalyzeMetadataForSourceFileOptions): readonly MetadataAnalysisResult[]; /** * Options for analyzing all supported declarations in one source file. * * @public */ export declare interface AnalyzeMetadataForSourceFileOptions extends AnalyzeMetadataOptions { /** Source file whose declarations should be analyzed. */ readonly sourceFile: ts.SourceFile; } /** * Common options for shared metadata analysis entry points. * * @public */ export declare interface AnalyzeMetadataOptions { /** Caller-owned TypeScript program used for analysis. */ readonly program: ts.Program; /** Optional built-in metadata policy for apiName/displayName resolution. */ readonly metadata?: MetadataPolicyInput | undefined; /** Optional extension definitions contributing additional metadata slots. */ readonly extensions?: readonly ExtensionDefinition[] | undefined; /** * Optional logger for diagnostic output. Defaults to a no-op logger so * existing callers produce no output. */ readonly logger?: LoggerLike | undefined; } /** * Zero-based half-open span in the source file. * * @public */ export declare interface CommentSourceSpan { /** Zero-based start offset in the source file. */ readonly start: number; /** One-past-the-end offset in the source file. */ readonly end: number; } /** * Canonical span type used throughout serialized comment analysis. * * @public */ export declare type CommentSpan = CommentSourceSpan; /** * Computes a stable, non-cryptographic hash for document staleness checks * across the plugin/LSP boundary. * * @public */ export declare function computeFormSpecTextHash(text: string): string; /** * Version of the transport protocol shared by analysis producers and consumers. * * @public */ export declare const FORMSPEC_ANALYSIS_PROTOCOL_VERSION = 4; /** * Version of the serialized analysis payload schema. * * @public */ export declare const FORMSPEC_ANALYSIS_SCHEMA_VERSION = 2; /** * Serializable view of one declaration-attached doc comment in a source file. * * @public */ export declare interface FormSpecAnalysisCommentSnapshot { /** Span covering the doc comment itself. */ readonly commentSpan: CommentSpan; /** Span covering the associated declaration. */ readonly declarationSpan: CommentSpan; /** Where the comment was attached in relation to the declaration. */ readonly placement: FormSpecPlacement | null; /** Resolved type of the documented subject, if known. */ readonly subjectType: string | null; /** Resolved host type that owns the comment, if known. */ readonly hostType: string | null; /** Declaration-level applied metadata and constraints derived by FormSpec. */ readonly declarationSummary: FormSpecAnalysisDeclarationSummary; /** Parsed tags contained in the doc comment. */ readonly tags: readonly FormSpecAnalysisTagSnapshot[]; } /** * Public declaration-level semantic summary for one documented declaration. * * @public */ export declare interface FormSpecAnalysisDeclarationSummary { /** Summary text attached to the declaration before the first tag, if present. */ readonly summaryText: string | null; /** Built-in resolved metadata projected for the declaration. */ readonly resolvedMetadata: FormSpecSerializedResolvedMetadata | null; /** Resolved metadata entries, including extension-contributed slots. */ readonly metadataEntries: readonly FormSpecSerializedMetadataEntry[]; /** Structured declaration facts derived by FormSpec. */ readonly facts: readonly FormSpecSerializedDeclarationFact[]; /** Pre-rendered markdown optimized for declaration hover surfaces. */ readonly hoverMarkdown: string; } /** * File-local diagnostic derived from comment parsing or semantic analysis. * * @public */ export declare interface FormSpecAnalysisDiagnostic { /** Stable diagnostic code for programmatic handling. */ readonly code: string; /** Diagnostic family used by the analysis pipeline. */ readonly category: FormSpecAnalysisDiagnosticCategory; /** Human-readable diagnostic message. */ readonly message: string; /** Primary source span for the diagnostic. */ readonly range: CommentSpan; /** Diagnostic severity reported to consumers. */ readonly severity: "error" | "warning" | "info"; /** Additional related source locations. */ readonly relatedLocations: readonly FormSpecAnalysisDiagnosticLocation[]; /** Structured diagnostic metadata. */ readonly data: Record; } /** * Machine-readable diagnostic category used by FormSpec tooling surfaces. * * @public */ export declare type FormSpecAnalysisDiagnosticCategory = "tag-recognition" | "value-parsing" | "type-compatibility" | "target-resolution" | "constraint-validation" | "infrastructure"; /** * Primitive structured values carried in diagnostic facts for white-label * downstream rendering. * * @public */ export declare type FormSpecAnalysisDiagnosticDataValue = string | number | boolean | readonly string[] | readonly number[] | readonly boolean[]; /** * Additional source location associated with a diagnostic. * * @public */ export declare interface FormSpecAnalysisDiagnosticLocation { /** Absolute path to the related source file. */ readonly filePath: string; /** Span associated with the related location. */ readonly range: CommentSpan; /** Optional human-readable note for the location. */ readonly message?: string; } /** * Serializable analysis artifact for a single source file. * * @public */ export declare interface FormSpecAnalysisFileSnapshot { /** Absolute path to the analyzed file. */ readonly filePath: string; /** Stable hash of the file contents. */ readonly sourceHash: string; /** ISO timestamp when the snapshot was generated. */ readonly generatedAt: string; /** Parsed doc comments found in the file. */ readonly comments: readonly FormSpecAnalysisCommentSnapshot[]; /** Diagnostics emitted for the file. */ readonly diagnostics: readonly FormSpecAnalysisDiagnostic[]; } /** * Discovery record written by the tsserver plugin so other FormSpec tooling * can locate and validate the matching semantic service for a workspace. * * @public */ export declare interface FormSpecAnalysisManifest { /** Protocol version expected by consumers of this manifest. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Schema version for the serialized analysis payload. */ readonly analysisSchemaVersion: typeof FORMSPEC_ANALYSIS_SCHEMA_VERSION; /** Absolute root of the workspace being analyzed. */ readonly workspaceRoot: string; /** Stable workspace identifier used for runtime artifacts. */ readonly workspaceId: string; /** IPC endpoint for the active semantic service. */ readonly endpoint: FormSpecIpcEndpoint; /** TypeScript version reported by the host runtime. */ readonly typescriptVersion: string; /** Hash of the active extension set for the workspace. */ readonly extensionFingerprint: string; /** Monotonic generation number for the manifest file. */ readonly generation: number; /** ISO timestamp for the last manifest update. */ readonly updatedAt: string; } /** * Serializable view of a single parsed FormSpec tag within a doc comment. * * @public */ export declare interface FormSpecAnalysisTagSnapshot { /** Raw tag name as written in the comment. */ readonly rawTagName: string; /** Normalized tag name used for lookup. */ readonly normalizedTagName: string; /** Whether the tag was recognized by the registry. */ readonly recognized: boolean; /** Full span covering the parsed tag. */ readonly fullSpan: CommentSpan; /** Span of the tag name itself. */ readonly tagNameSpan: CommentSpan; /** Span of the payload after the tag name. */ readonly payloadSpan: CommentSpan | null; /** Parsed target specifier, if one was present. */ readonly target: FormSpecSerializedCommentTargetSpecifier | null; /** Span covering the argument text, if present. */ readonly argumentSpan: CommentSpan | null; /** Raw argument text. */ readonly argumentText: string; /** Serialized semantic data for the tag. */ readonly semantic: FormSpecSerializedTagSemanticContext; } /** * Cross-process endpoint used by the language server to reach the semantic * tsserver plugin on the current workspace host. * * @public */ export declare interface FormSpecIpcEndpoint { /** Transport kind used to reach the semantic service. */ readonly kind: "unix-socket" | "windows-pipe"; /** Socket path or named-pipe address for the service. */ readonly address: string; } /** * Declaration contexts where a FormSpec tag may appear. * * @public */ export declare type FormSpecPlacement = "class" | "class-field" | "class-method" | "interface" | "interface-field" | "type-alias" | "type-alias-field" | "variable" | "function" | "function-parameter" | "method-parameter"; /** * Query variants supported by the semantic tsserver plugin. * * @public */ export declare type FormSpecSemanticQuery = { /** Protocol version carried with every request. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Query variant requesting health/manifest information. */ readonly kind: "health"; } | { /** Protocol version carried with every request. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Query variant requesting completion context. */ readonly kind: "completion"; /** Absolute path of the source file. */ readonly filePath: string; /** Zero-based cursor offset in the file. */ readonly offset: number; } | { /** Protocol version carried with every request. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Query variant requesting hover information. */ readonly kind: "hover"; /** Absolute path of the source file. */ readonly filePath: string; /** Zero-based cursor offset in the file. */ readonly offset: number; } | { /** Protocol version carried with every request. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Query variant requesting diagnostics only. */ readonly kind: "diagnostics"; /** Absolute path of the source file. */ readonly filePath: string; } | { /** Protocol version carried with every request. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Query variant requesting a full serialized file snapshot. */ readonly kind: "file-snapshot"; /** Absolute path of the source file. */ readonly filePath: string; }; /** * Response variants returned by the semantic tsserver plugin. * * @public */ export declare type FormSpecSemanticResponse = { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Response variant carrying health information. */ readonly kind: "health"; /** Manifest describing the active semantic service. */ readonly manifest: FormSpecAnalysisManifest; } | { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Response variant carrying completion context. */ readonly kind: "completion"; /** Source hash used to validate cursor data freshness. */ readonly sourceHash: string; /** Completion context for the requested cursor position. */ readonly context: FormSpecSerializedCompletionContext; } | { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Response variant carrying hover information. */ readonly kind: "hover"; /** Source hash used to validate hover freshness. */ readonly sourceHash: string; /** Hover payload, if one is available. */ readonly hover: FormSpecSerializedHoverInfo | null; } | { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Response variant carrying diagnostics. */ readonly kind: "diagnostics"; /** Source hash used to validate diagnostic freshness. */ readonly sourceHash: string; /** Diagnostics for the requested file. */ readonly diagnostics: readonly FormSpecAnalysisDiagnostic[]; } | { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Response variant carrying a serialized file snapshot. */ readonly kind: "file-snapshot"; /** Snapshot of the requested file, if available. */ readonly snapshot: FormSpecAnalysisFileSnapshot | null; } | { /** Protocol version carried with every response. */ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION; /** Error response variant. */ readonly kind: "error"; /** Human-readable error message. */ readonly error: string; }; /** * Serialized representation of a parsed target specifier with exact spans. * * @public */ export declare interface FormSpecSerializedCommentTargetSpecifier { /** Raw target text without the leading colon. */ readonly rawText: string; /** Whether the target parsed cleanly. */ readonly valid: boolean; /** Classified target kind used by completion and hover. */ readonly kind: "path" | "member" | "variant" | "ambiguous"; /** Full span covering the colon and target text. */ readonly fullSpan: CommentSpan; /** Span covering only the leading colon. */ readonly colonSpan: CommentSpan; /** Span covering the target text after the colon. */ readonly span: CommentSpan; } /** * Cursor-scoped completion context serialized for transport between the * semantic tsserver plugin and the lightweight LSP. * * @public */ export declare type FormSpecSerializedCompletionContext = { /** Completion mode indicating the cursor is on a tag name. */ readonly kind: "tag-name"; /** Current partially typed tag prefix. */ readonly prefix: string; /** Tags available at the current cursor location. */ readonly availableTags: readonly FormSpecSerializedTagDefinition[]; } | { /** Completion mode indicating the cursor is on a target specifier. */ readonly kind: "target"; /** Semantic context for the active tag. */ readonly semantic: FormSpecSerializedTagSemanticContext; } | { /** Completion mode indicating the cursor is in an argument position. */ readonly kind: "argument"; /** Semantic context for the active tag. */ readonly semantic: FormSpecSerializedTagSemanticContext; /** Suggested value labels for argument completion. */ readonly valueLabels: readonly string[]; } | { /** Sentinel indicating that no FormSpec completion is available. */ readonly kind: "none"; }; /** * Structured declaration-level fact derived from one or more comment tags. * * @public */ export declare type FormSpecSerializedDeclarationFact = { /** Summary text attached to the declaration body before the first tag. */ readonly kind: "description"; /** Summary text rendered from the declaration doc comment. */ readonly value: string; } | { /** Additional remarks text attached to the declaration. */ readonly kind: "remarks"; /** Remarks text as authored. */ readonly value: string; } | { /** Default JSON value carried by the declaration metadata. */ readonly kind: "default-value"; /** Parsed JSON-safe default value. */ readonly value: FormSpecSerializedJsonValue; } | { /** Example text attached to the declaration. */ readonly kind: "example"; /** Example text as authored. */ readonly value: string; } | { /** Deprecation status for the declaration. */ readonly kind: "deprecated"; /** Optional deprecation guidance authored alongside the tag. */ readonly message: string | null; } | { /** Combined numeric constraints for one declaration target. */ readonly kind: "numeric-constraints"; /** Target path receiving the constraints, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Inclusive lower bound, when present. */ readonly minimum?: number | undefined; /** Inclusive upper bound, when present. */ readonly maximum?: number | undefined; /** Exclusive lower bound, when present. */ readonly exclusiveMinimum?: number | undefined; /** Exclusive upper bound, when present. */ readonly exclusiveMaximum?: number | undefined; /** Divisibility constraint, when present. */ readonly multipleOf?: number | undefined; } | { /** Combined string constraints for one declaration target. */ readonly kind: "string-constraints"; /** Target path receiving the constraints, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Minimum string length, when present. */ readonly minLength?: number | undefined; /** Maximum string length, when present. */ readonly maxLength?: number | undefined; /** Regex patterns that must all be satisfied. */ readonly patterns: readonly string[]; } | { /** Combined array constraints for one declaration target. */ readonly kind: "array-constraints"; /** Target path receiving the constraints, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Minimum item count, when present. */ readonly minItems?: number | undefined; /** Maximum item count, when present. */ readonly maxItems?: number | undefined; /** Whether items must be unique. */ readonly uniqueItems?: boolean | undefined; } | { /** Enum/member whitelist constraint for one declaration target. */ readonly kind: "allowed-members"; /** Target path receiving the constraint, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Allowed member identifiers after normalization. */ readonly members: readonly (string | number)[]; } | { /** Constant-value constraint for one declaration target. */ readonly kind: "const"; /** Target path receiving the constraint, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Constant JSON-safe value. */ readonly value: FormSpecSerializedJsonValue; } | { /** Extension-defined constraint fact for one declaration target. */ readonly kind: "custom-constraint"; /** Target path receiving the constraint, or `null` for the declaration itself. */ readonly targetPath: string | null; /** Stable extension-qualified constraint identifier. */ readonly constraintId: string; /** Composition rule used when combining repeated applications. */ readonly compositionRule: "intersect" | "override"; /** JSON-safe payload parsed from the authored tag. */ readonly payload: FormSpecSerializedJsonValue; }; /** * Serializable source details for one explicit metadata value. * * @public */ export declare interface FormSpecSerializedExplicitMetadataSource { /** Tag name associated with the explicit value, without the `@` prefix. */ readonly tagName: string; /** Whether the explicit value used a bare or qualified tag form. */ readonly form: "bare" | "qualified"; /** Full range covering the explicit tag occurrence. */ readonly fullRange: CommentSpan; /** Range covering only the tag name token. */ readonly tagNameRange: CommentSpan; /** Range covering the qualifier text, when present. */ readonly qualifierRange?: CommentSpan | undefined; /** Range covering only the explicit value text. */ readonly valueRange: CommentSpan; /** Qualifier text without the leading colon, when present. */ readonly qualifier?: string | undefined; } /** * Hover payload for a single comment token under the cursor. * * @public */ export declare interface FormSpecSerializedHoverInfo { /** Token kind that produced this hover payload. */ readonly kind: "tag-name" | "target" | "argument" | "declaration"; /** Markdown content returned to the hover UI. */ readonly markdown: string; } /** * JSON-safe value carried by declaration summary facts. * * @public */ export declare type FormSpecSerializedJsonValue = string | number | boolean | null | readonly FormSpecSerializedJsonValue[] | { readonly [key: string]: FormSpecSerializedJsonValue; }; /** * Serializable metadata slot resolution for one declaration. * * @public */ export declare interface FormSpecSerializedMetadataEntry { /** Stable logical slot identifier. */ readonly slotId: string; /** Tag name associated with the slot, without the `@` prefix. */ readonly tagName: string; /** Optional qualifier text without the leading colon. */ readonly qualifier?: string | undefined; /** Effective value after explicit/inferred resolution. */ readonly value: string; /** Whether the value was authored directly or inferred. */ readonly source: "explicit" | "inferred"; /** Fixer-oriented source details when the winning value was explicit. */ readonly explicitSource?: FormSpecSerializedExplicitMetadataSource | undefined; } /** * Serializable built-in metadata projection for one declaration. * * @public */ export declare interface FormSpecSerializedResolvedMetadata { /** Effective JSON-facing singular name. */ readonly apiName?: FormSpecSerializedResolvedScalarMetadata | undefined; /** Effective human-facing singular label. */ readonly displayName?: FormSpecSerializedResolvedScalarMetadata | undefined; /** Effective JSON-facing plural name, where applicable. */ readonly apiNamePlural?: FormSpecSerializedResolvedScalarMetadata | undefined; /** Effective human-facing plural label, where applicable. */ readonly displayNamePlural?: FormSpecSerializedResolvedScalarMetadata | undefined; } /** * Serializable scalar metadata value plus its provenance. * * @public */ export declare interface FormSpecSerializedResolvedScalarMetadata { /** Effective metadata value after policy resolution. */ readonly value: string; /** Whether the value was authored directly or inferred. */ readonly source: "explicit" | "inferred"; } /** * Serializable subset of tag metadata needed by hover and completion UIs. * * @public */ export declare interface FormSpecSerializedTagDefinition { /** Canonical tag name, including the leading `@`. */ readonly canonicalName: string; /** Short completion detail shown in UI pickers. */ readonly completionDetail: string; /** Markdown hover text for the tag name. */ readonly hoverMarkdown: string; } /** * Semantic facts about one parsed tag, reduced to JSON-safe data for IPC. * * @public */ export declare interface FormSpecSerializedTagSemanticContext { /** Tag name in canonical `@tag` form. */ readonly tagName: string; /** Resolved tag definition, if the tag is recognized. */ readonly tagDefinition: FormSpecSerializedTagDefinition | null; /** Placement inferred for the tag in the current comment. */ readonly placement: FormSpecPlacement | null; /** Usage variants filtered to the active tag occurrence. */ readonly contextualSignatures: readonly FormSpecSerializedTagSignature[]; /** Target kinds supported by the tag. */ readonly supportedTargets: readonly FormSpecTargetKind[]; /** Completion candidates for tag targets. */ readonly targetCompletions: readonly string[]; /** Path targets compatible with the current cursor context. */ readonly compatiblePathTargets: readonly string[]; /** Display labels for known argument values. */ readonly valueLabels: readonly string[]; /** Completion candidates for the argument position. */ readonly argumentCompletions: readonly string[]; /** Markdown hover content for the tag in the active occurrence context. */ readonly contextualTagHoverMarkdown: string | null; /** Summaries of the tag's overloads or signatures. */ readonly signatures: readonly FormSpecSerializedTagSignature[]; /** Markdown hover content for the tag itself. */ readonly tagHoverMarkdown: string | null; /** Markdown hover content for the target, if applicable. */ readonly targetHoverMarkdown: string | null; /** Markdown hover content for the argument, if applicable. */ readonly argumentHoverMarkdown: string | null; } /** * Serializable overload/signature summary for one comment tag form. * * @public */ export declare interface FormSpecSerializedTagSignature { /** Human-readable label for the signature form. */ readonly label: string; /** Target kinds accepted by this signature. */ readonly placements: readonly FormSpecPlacement[]; } /** * Target syntaxes that a FormSpec tag can accept. * * @public */ export declare type FormSpecTargetKind = "none" | "path" | "member" | "variant"; /** * Validates an unknown manifest payload from disk before consumers trust it. * * @public */ export declare function isFormSpecAnalysisManifest(value: unknown): value is FormSpecAnalysisManifest; /** * Validates an unknown inbound IPC request before dispatching it. * * @public */ export declare function isFormSpecSemanticQuery(value: unknown): value is FormSpecSemanticQuery; /** * Validates an unknown IPC response before the language server consumes it. * * @public */ export declare function isFormSpecSemanticResponse(value: unknown): value is FormSpecSemanticResponse; export { }