@formspec/ts-plugin 0.1.0-alpha.21 → 0.1.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,470 @@
1
+ import * as ts from 'typescript';
2
+ import type * as tsServer from 'typescript/lib/tsserverlibrary.js';
3
+
4
+ /** @public */
5
+ export declare type CommentSourceSpan = CommentSpan;
6
+
7
+ /** @public */
8
+ export declare interface CommentSpan {
9
+ readonly start: number;
10
+ readonly end: number;
11
+ }
12
+
13
+ /**
14
+ * Reference proxy wrapper that keeps FormSpec semantic snapshots fresh while
15
+ * delegating actual TypeScript editor features to the original service.
16
+ *
17
+ * @public
18
+ */
19
+ export declare function createLanguageServiceProxy(languageService: ts.LanguageService, semanticService: FormSpecSemanticService): ts.LanguageService;
20
+
21
+ /** @public */
22
+ export declare const FORMSPEC_ANALYSIS_PROTOCOL_VERSION = 2;
23
+
24
+ /** @public */
25
+ export declare const FORMSPEC_ANALYSIS_SCHEMA_VERSION = 1;
26
+
27
+ /**
28
+ * Serializable view of one declaration-attached doc comment in a source file.
29
+ *
30
+ * @public
31
+ */
32
+ export declare interface FormSpecAnalysisCommentSnapshot {
33
+ readonly commentSpan: CommentSpan;
34
+ readonly declarationSpan: CommentSpan;
35
+ readonly placement: FormSpecPlacement | null;
36
+ readonly subjectType: string | null;
37
+ readonly hostType: string | null;
38
+ readonly tags: readonly FormSpecAnalysisTagSnapshot[];
39
+ }
40
+
41
+ /**
42
+ * File-local diagnostic derived from comment parsing or semantic analysis.
43
+ *
44
+ * @public
45
+ */
46
+ export declare interface FormSpecAnalysisDiagnostic {
47
+ readonly code: string;
48
+ readonly category: FormSpecAnalysisDiagnosticCategory;
49
+ readonly message: string;
50
+ readonly range: CommentSpan;
51
+ readonly severity: "error" | "warning" | "info";
52
+ readonly relatedLocations: readonly FormSpecAnalysisDiagnosticLocation[];
53
+ readonly data: Record<string, FormSpecAnalysisDiagnosticDataValue>;
54
+ }
55
+
56
+ /**
57
+ * Machine-readable diagnostic category used by FormSpec tooling surfaces.
58
+ *
59
+ * @public
60
+ */
61
+ export declare type FormSpecAnalysisDiagnosticCategory = "tag-recognition" | "value-parsing" | "type-compatibility" | "target-resolution" | "constraint-validation" | "infrastructure";
62
+
63
+ /**
64
+ * Primitive structured values carried in diagnostic facts for white-label
65
+ * downstream rendering.
66
+ *
67
+ * @public
68
+ */
69
+ export declare type FormSpecAnalysisDiagnosticDataValue = string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
70
+
71
+ /**
72
+ * Additional source location associated with a diagnostic.
73
+ *
74
+ * @public
75
+ */
76
+ export declare interface FormSpecAnalysisDiagnosticLocation {
77
+ readonly filePath: string;
78
+ readonly range: CommentSpan;
79
+ readonly message?: string;
80
+ }
81
+
82
+ /**
83
+ * Serializable analysis artifact for a single source file.
84
+ *
85
+ * @public
86
+ */
87
+ export declare interface FormSpecAnalysisFileSnapshot {
88
+ readonly filePath: string;
89
+ readonly sourceHash: string;
90
+ readonly generatedAt: string;
91
+ readonly comments: readonly FormSpecAnalysisCommentSnapshot[];
92
+ readonly diagnostics: readonly FormSpecAnalysisDiagnostic[];
93
+ }
94
+
95
+ /**
96
+ * Discovery record written by the tsserver plugin so other FormSpec tooling
97
+ * can locate and validate the matching semantic service for a workspace.
98
+ *
99
+ * @public
100
+ */
101
+ export declare interface FormSpecAnalysisManifest {
102
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
103
+ readonly analysisSchemaVersion: typeof FORMSPEC_ANALYSIS_SCHEMA_VERSION;
104
+ readonly workspaceRoot: string;
105
+ readonly workspaceId: string;
106
+ readonly endpoint: FormSpecIpcEndpoint;
107
+ readonly typescriptVersion: string;
108
+ readonly extensionFingerprint: string;
109
+ readonly generation: number;
110
+ readonly updatedAt: string;
111
+ }
112
+
113
+ /**
114
+ * Serializable view of a single parsed FormSpec tag within a doc comment.
115
+ *
116
+ * @public
117
+ */
118
+ export declare interface FormSpecAnalysisTagSnapshot {
119
+ readonly rawTagName: string;
120
+ readonly normalizedTagName: string;
121
+ readonly recognized: boolean;
122
+ readonly fullSpan: CommentSpan;
123
+ readonly tagNameSpan: CommentSpan;
124
+ readonly payloadSpan: CommentSpan | null;
125
+ readonly target: FormSpecSerializedCommentTargetSpecifier | null;
126
+ readonly argumentSpan: CommentSpan | null;
127
+ readonly argumentText: string;
128
+ readonly semantic: FormSpecSerializedTagSemanticContext;
129
+ }
130
+
131
+ /**
132
+ * Cross-process endpoint used by the language server to reach the semantic
133
+ * tsserver plugin on the current workspace host.
134
+ *
135
+ * @public
136
+ */
137
+ export declare interface FormSpecIpcEndpoint {
138
+ readonly kind: "unix-socket" | "windows-pipe";
139
+ readonly address: string;
140
+ }
141
+
142
+ /** @public */
143
+ export declare type FormSpecPlacement = "class" | "class-field" | "class-method" | "interface" | "interface-field" | "type-alias" | "type-alias-field" | "variable" | "function" | "function-parameter" | "method-parameter";
144
+
145
+ /**
146
+ * Reference manifest/socket wrapper around `FormSpecSemanticService`.
147
+ *
148
+ * Downstream TypeScript hosts that already control their own plugin/runtime
149
+ * lifecycle can use `FormSpecSemanticService` directly and skip this wrapper.
150
+ *
151
+ * @public
152
+ */
153
+ export declare class FormSpecPluginService {
154
+ private readonly options;
155
+ private readonly manifest;
156
+ private readonly runtimePaths;
157
+ private readonly semanticService;
158
+ private server;
159
+ constructor(options: FormSpecPluginServiceOptions);
160
+ getManifest(): FormSpecAnalysisManifest;
161
+ /**
162
+ * Returns the underlying semantic service used by this reference wrapper.
163
+ *
164
+ * @public
165
+ */
166
+ getSemanticService(): FormSpecSemanticService;
167
+ start(): Promise<void>;
168
+ stop(): Promise<void>;
169
+ scheduleSnapshotRefresh(filePath: string): void;
170
+ handleQuery(query: FormSpecSemanticQuery): FormSpecSemanticResponse;
171
+ private executeQuery;
172
+ private respondToSocket;
173
+ private writeManifest;
174
+ private cleanupRuntimeArtifacts;
175
+ private logQueryDuration;
176
+ }
177
+
178
+ /**
179
+ * Public configuration for the reference plugin wrapper that exposes
180
+ * `FormSpecSemanticService` over the local manifest + IPC transport.
181
+ *
182
+ * Supports the same semantic-service options, including
183
+ * `enablePerformanceLogging`, `performanceLogThresholdMs`, and
184
+ * `snapshotDebounceMs`. The packaged tsserver plugin wires these from
185
+ * `FORMSPEC_PLUGIN_PROFILE=1` and `FORMSPEC_PLUGIN_PROFILE_THRESHOLD_MS`.
186
+ *
187
+ * @public
188
+ */
189
+ export declare type FormSpecPluginServiceOptions = FormSpecSemanticServiceOptions;
190
+
191
+ /** @public */
192
+ export declare interface FormSpecSemanticCompletionResult {
193
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
194
+ readonly sourceHash: string;
195
+ readonly context: FormSpecSerializedCompletionContext;
196
+ }
197
+
198
+ /** @public */
199
+ export declare interface FormSpecSemanticDiagnosticsResult {
200
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
201
+ readonly sourceHash: string;
202
+ readonly diagnostics: readonly FormSpecAnalysisDiagnostic[];
203
+ }
204
+
205
+ /** @public */
206
+ export declare interface FormSpecSemanticHoverResult {
207
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
208
+ readonly sourceHash: string;
209
+ readonly hover: FormSpecSerializedHoverInfo | null;
210
+ }
211
+
212
+ /**
213
+ * Query variants supported by the semantic tsserver plugin.
214
+ *
215
+ * @public
216
+ */
217
+ export declare type FormSpecSemanticQuery = {
218
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
219
+ readonly kind: "health";
220
+ } | {
221
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
222
+ readonly kind: "completion";
223
+ readonly filePath: string;
224
+ readonly offset: number;
225
+ } | {
226
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
227
+ readonly kind: "hover";
228
+ readonly filePath: string;
229
+ readonly offset: number;
230
+ } | {
231
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
232
+ readonly kind: "diagnostics";
233
+ readonly filePath: string;
234
+ } | {
235
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
236
+ readonly kind: "file-snapshot";
237
+ readonly filePath: string;
238
+ };
239
+
240
+ /**
241
+ * Response variants returned by the semantic tsserver plugin.
242
+ *
243
+ * @public
244
+ */
245
+ export declare type FormSpecSemanticResponse = {
246
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
247
+ readonly kind: "health";
248
+ readonly manifest: FormSpecAnalysisManifest;
249
+ } | {
250
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
251
+ readonly kind: "completion";
252
+ readonly sourceHash: string;
253
+ readonly context: FormSpecSerializedCompletionContext;
254
+ } | {
255
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
256
+ readonly kind: "hover";
257
+ readonly sourceHash: string;
258
+ readonly hover: FormSpecSerializedHoverInfo | null;
259
+ } | {
260
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
261
+ readonly kind: "diagnostics";
262
+ readonly sourceHash: string;
263
+ readonly diagnostics: readonly FormSpecAnalysisDiagnostic[];
264
+ } | {
265
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
266
+ readonly kind: "file-snapshot";
267
+ readonly snapshot: FormSpecAnalysisFileSnapshot | null;
268
+ } | {
269
+ readonly protocolVersion: typeof FORMSPEC_ANALYSIS_PROTOCOL_VERSION;
270
+ readonly kind: "error";
271
+ readonly error: string;
272
+ };
273
+
274
+ /**
275
+ * Reusable in-process semantic service for FormSpec authoring features.
276
+ *
277
+ * Downstream TypeScript hosts can construct this directly against their own
278
+ * `Program` and own the final presentation of completions, hover, and
279
+ * diagnostics. The shipped tsserver plugin is a reference wrapper over this
280
+ * public service.
281
+ *
282
+ * @public
283
+ */
284
+ export declare class FormSpecSemanticService {
285
+ private readonly options;
286
+ private readonly snapshotCache;
287
+ private readonly refreshTimers;
288
+ private readonly stats;
289
+ constructor(options: FormSpecSemanticServiceOptions);
290
+ /** Resolves semantic completion context for a comment cursor position. */
291
+ getCompletionContext(filePath: string, offset: number): FormSpecSemanticCompletionResult | null;
292
+ /** Resolves semantic hover payload for a comment cursor position. */
293
+ getHover(filePath: string, offset: number): FormSpecSemanticHoverResult | null;
294
+ /** Returns canonical FormSpec diagnostics for a file in the current host program. */
295
+ getDiagnostics(filePath: string): FormSpecSemanticDiagnosticsResult;
296
+ /** Returns the full serialized semantic snapshot for a file. */
297
+ getFileSnapshot(filePath: string): FormSpecAnalysisFileSnapshot;
298
+ /** Schedules a debounced background refresh for the file snapshot cache. */
299
+ scheduleSnapshotRefresh(filePath: string): void;
300
+ /** Clears pending timers and cached semantic snapshots. */
301
+ dispose(): void;
302
+ /** Returns a copy of the current performance and cache counters. */
303
+ getStats(): FormSpecSemanticServiceStats;
304
+ private runMeasured;
305
+ private withCommentQueryContext;
306
+ private getFileSnapshotWithCacheState;
307
+ private getNow;
308
+ private getSourceEnvironment;
309
+ private recordQueryPath;
310
+ private updateStatsFromPerformanceEvents;
311
+ private logPerformanceEvents;
312
+ }
313
+
314
+ /** @public */
315
+ export declare interface FormSpecSemanticServiceOptions {
316
+ /** Workspace root used for runtime paths and contextual logging. */
317
+ readonly workspaceRoot: string;
318
+ /** TypeScript version string reported by the host runtime. */
319
+ readonly typescriptVersion: string;
320
+ /** Supplies the current host program. Returns `undefined` until ready. */
321
+ readonly getProgram: () => ts.Program | undefined;
322
+ /** Optional logger used for profiling and refresh-failure messages. */
323
+ readonly logger?: LoggerLike;
324
+ /** Enables structured hotspot logging for semantic queries. */
325
+ readonly enablePerformanceLogging?: boolean;
326
+ /** Minimum query duration, in milliseconds, required before logging. */
327
+ readonly performanceLogThresholdMs?: number;
328
+ /** Debounce window, in milliseconds, for background snapshot refresh. */
329
+ readonly snapshotDebounceMs?: number;
330
+ /** Injectable clock used by tests and runtime snapshot timestamps. */
331
+ readonly now?: () => Date;
332
+ }
333
+
334
+ /** @public */
335
+ export declare interface FormSpecSemanticServiceStats {
336
+ /** Total number of calls by semantic query kind. */
337
+ readonly queryTotals: {
338
+ readonly completion: number;
339
+ readonly hover: number;
340
+ readonly diagnostics: number;
341
+ readonly fileSnapshot: number;
342
+ };
343
+ /** Cold vs warm query path counts for snapshot-backed operations. */
344
+ readonly queryPathTotals: {
345
+ readonly diagnostics: {
346
+ readonly cold: number;
347
+ readonly warm: number;
348
+ };
349
+ readonly fileSnapshot: {
350
+ readonly cold: number;
351
+ readonly warm: number;
352
+ };
353
+ };
354
+ /** Number of file snapshot cache hits. */
355
+ readonly fileSnapshotCacheHits: number;
356
+ /** Number of file snapshot cache misses. */
357
+ readonly fileSnapshotCacheMisses: number;
358
+ /** Number of synthetic batch cache hits. */
359
+ readonly syntheticBatchCacheHits: number;
360
+ /** Number of synthetic batch cache misses. */
361
+ readonly syntheticBatchCacheMisses: number;
362
+ /** Number of synthetic compiler program creations. */
363
+ readonly syntheticCompileCount: number;
364
+ /** Total synthetic application count compiled across misses. */
365
+ readonly syntheticCompileApplications: number;
366
+ }
367
+
368
+ /**
369
+ * Serialized representation of a parsed target specifier with exact spans.
370
+ *
371
+ * @public
372
+ */
373
+ export declare interface FormSpecSerializedCommentTargetSpecifier {
374
+ readonly rawText: string;
375
+ readonly valid: boolean;
376
+ readonly kind: "path" | "member" | "variant" | "ambiguous";
377
+ readonly fullSpan: CommentSpan;
378
+ readonly colonSpan: CommentSpan;
379
+ readonly span: CommentSpan;
380
+ }
381
+
382
+ /**
383
+ * Cursor-scoped completion context serialized for transport between the
384
+ * semantic tsserver plugin and the lightweight LSP.
385
+ *
386
+ * @public
387
+ */
388
+ export declare type FormSpecSerializedCompletionContext = {
389
+ readonly kind: "tag-name";
390
+ readonly prefix: string;
391
+ readonly availableTags: readonly FormSpecSerializedTagDefinition[];
392
+ } | {
393
+ readonly kind: "target";
394
+ readonly semantic: FormSpecSerializedTagSemanticContext;
395
+ } | {
396
+ readonly kind: "argument";
397
+ readonly semantic: FormSpecSerializedTagSemanticContext;
398
+ readonly valueLabels: readonly string[];
399
+ } | {
400
+ readonly kind: "none";
401
+ };
402
+
403
+ /**
404
+ * Hover payload for a single comment token under the cursor.
405
+ *
406
+ * @public
407
+ */
408
+ export declare interface FormSpecSerializedHoverInfo {
409
+ readonly kind: "tag-name" | "target" | "argument";
410
+ readonly markdown: string;
411
+ }
412
+
413
+ /**
414
+ * Serializable subset of tag metadata needed by hover and completion UIs.
415
+ *
416
+ * @public
417
+ */
418
+ export declare interface FormSpecSerializedTagDefinition {
419
+ readonly canonicalName: string;
420
+ readonly completionDetail: string;
421
+ readonly hoverMarkdown: string;
422
+ }
423
+
424
+ /**
425
+ * Semantic facts about one parsed tag, reduced to JSON-safe data for IPC.
426
+ *
427
+ * @public
428
+ */
429
+ export declare interface FormSpecSerializedTagSemanticContext {
430
+ readonly tagName: string;
431
+ readonly tagDefinition: FormSpecSerializedTagDefinition | null;
432
+ readonly placement: FormSpecPlacement | null;
433
+ readonly supportedTargets: readonly FormSpecTargetKind[];
434
+ readonly targetCompletions: readonly string[];
435
+ readonly compatiblePathTargets: readonly string[];
436
+ readonly valueLabels: readonly string[];
437
+ readonly signatures: readonly FormSpecSerializedTagSignature[];
438
+ readonly tagHoverMarkdown: string | null;
439
+ readonly targetHoverMarkdown: string | null;
440
+ readonly argumentHoverMarkdown: string | null;
441
+ }
442
+
443
+ /**
444
+ * Serializable overload/signature summary for one comment tag form.
445
+ *
446
+ * @public
447
+ */
448
+ export declare interface FormSpecSerializedTagSignature {
449
+ readonly label: string;
450
+ readonly placements: readonly FormSpecPlacement[];
451
+ }
452
+
453
+ /** @public */
454
+ export declare type FormSpecTargetKind = "none" | "path" | "member" | "variant";
455
+
456
+ /**
457
+ * Initializes the FormSpec TypeScript language service plugin.
458
+ *
459
+ * @public
460
+ */
461
+ export declare function init(modules: {
462
+ readonly typescript: typeof tsServer;
463
+ }): tsServer.server.PluginModule;
464
+
465
+ /** @public */
466
+ export declare interface LoggerLike {
467
+ info(message: string): void;
468
+ }
469
+
470
+ export { }