@vscode/diff 0.0.2-0 → 0.0.2-2

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.
Binary file
package/dist/index.d.ts CHANGED
@@ -219,5 +219,233 @@ interface CreateDiffComputerOptions {
219
219
  }
220
220
  declare function createDiffComputer(options?: CreateDiffComputerOptions): Promise<IDiffComputer>;
221
221
 
222
- export { AnnotatedStringEdit, AnnotatedStringReplacement, DiffAnnotation, DiffResult, Move, OffsetRange, OffsetRangeMapping, StringEdit, StringReplacement, createDiffComputer };
223
- export type { CreateDiffComputerOptions, DiffOptions, IDiffComputer, IEditData };
222
+ /**
223
+ * Main-thread client for the diff worker. Exposes an async `IAsyncDiffComputer`.
224
+ *
225
+ * Inputs travel as `string[]` via structured-clone postMessage. The response
226
+ * is a small JSON-friendly `WireLinesDiff`; the main thread reconstructs the
227
+ * full `LinesDiff` and runs `_adaptLinesDiff` locally (it already has the
228
+ * input strings).
229
+ */
230
+
231
+ interface IAsyncDiffComputer {
232
+ computeDiff(original: string, modified: string, options?: DiffOptions): Promise<DiffResult>;
233
+ dispose(): void;
234
+ }
235
+ interface CreateWorkerDiffComputerOptions {
236
+ /** Use the WASM backend inside the worker. Default: false (TS). */
237
+ useWasm?: boolean;
238
+ /**
239
+ * Override worker construction. Defaults to
240
+ * `new Worker(new URL('./worker.ts?esm', import.meta.url), { type: 'module' })`.
241
+ *
242
+ * The `?esm` marker is recognized by `@vscode/rollup-plugin-esm-url`,
243
+ * `@vscode/esbuild-plugin-esm-url`, and `@vscode/esm-url-webpack-plugin`,
244
+ * which auto-discover sibling worker entries when bundling consumer apps.
245
+ * After bundling, the URL resolves to a sibling `worker.js`. Override this
246
+ * only when your toolchain needs a non-default discovery mechanism.
247
+ */
248
+ workerFactory?: () => Worker;
249
+ }
250
+ declare function createWorkerDiffComputer(opts?: CreateWorkerDiffComputerOptions): Promise<IAsyncDiffComputer>;
251
+
252
+ /**
253
+ * Represents a range in terms of lines and columns.
254
+ */
255
+ interface IRange {
256
+ readonly startLineNumber: number;
257
+ readonly startColumn: number;
258
+ readonly endLineNumber: number;
259
+ readonly endColumn: number;
260
+ }
261
+ declare class Range implements IRange {
262
+ readonly startLineNumber: number;
263
+ readonly startColumn: number;
264
+ readonly endLineNumber: number;
265
+ readonly endColumn: number;
266
+ constructor(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number);
267
+ static fromPositions(start: Position, end: Position): Range;
268
+ }
269
+ declare class Position {
270
+ readonly lineNumber: number;
271
+ readonly column: number;
272
+ constructor(lineNumber: number, column: number);
273
+ isBefore(other: Position): boolean;
274
+ }
275
+
276
+ /**
277
+ * A range of lines (1-based, end is exclusive).
278
+ */
279
+ declare class LineRange {
280
+ readonly startLineNumber: number;
281
+ readonly endLineNumberExclusive: number;
282
+ constructor(startLineNumber: number, endLineNumberExclusive: number);
283
+ get isEmpty(): boolean;
284
+ get length(): number;
285
+ join(other: LineRange): LineRange;
286
+ intersectsOrTouches(other: LineRange): boolean;
287
+ toOffsetRange(): OffsetRange;
288
+ toString(): string;
289
+ }
290
+ /**
291
+ * A mapping between two ranges.
292
+ */
293
+ declare class RangeMapping {
294
+ readonly originalRange: Range;
295
+ readonly modifiedRange: Range;
296
+ constructor(originalRange: Range, modifiedRange: Range);
297
+ toString(): string;
298
+ static assertSorted(rangeMappings: RangeMapping[]): void;
299
+ }
300
+ /**
301
+ * A mapping between two line ranges.
302
+ */
303
+ declare class LineRangeMapping {
304
+ readonly original: LineRange;
305
+ readonly modified: LineRange;
306
+ constructor(original: LineRange, modified: LineRange);
307
+ toString(): string;
308
+ /**
309
+ * This method assumes that the LineRangeMapping describes a valid diff!
310
+ * I.e. if one range is empty, the other range cannot be the entire document.
311
+ * It avoids various problems when the line range points to non-existing line-numbers.
312
+ */
313
+ toRangeMapping2(originalLines: string[], modifiedLines: string[]): RangeMapping;
314
+ }
315
+ /**
316
+ * A detailed mapping between two line ranges, including inner changes.
317
+ */
318
+ declare class DetailedLineRangeMapping extends LineRangeMapping {
319
+ readonly innerChanges: RangeMapping[] | undefined;
320
+ constructor(original: LineRange, modified: LineRange, innerChanges: RangeMapping[] | undefined);
321
+ }
322
+ /**
323
+ * Result of a lines diff computation.
324
+ */
325
+ declare class LinesDiff {
326
+ readonly changes: DetailedLineRangeMapping[];
327
+ readonly moves: MovedText[];
328
+ readonly hitTimeout: boolean;
329
+ constructor(changes: DetailedLineRangeMapping[], moves: MovedText[], hitTimeout: boolean);
330
+ }
331
+ /**
332
+ * Represents text that was moved from one location to another.
333
+ */
334
+ declare class MovedText {
335
+ readonly lineRangeMapping: LineRangeMapping;
336
+ readonly changes: DetailedLineRangeMapping[];
337
+ constructor(lineRangeMapping: LineRangeMapping, changes: DetailedLineRangeMapping[]);
338
+ }
339
+
340
+ /**
341
+ * Options for the lines diff computer.
342
+ */
343
+ interface ILinesDiffComputerOptions {
344
+ /**
345
+ * Maximum computation time in milliseconds. 0 means no timeout.
346
+ */
347
+ maxComputationTimeMs: number;
348
+ /**
349
+ * Whether to ignore leading and trailing whitespace.
350
+ */
351
+ ignoreTrimWhitespace: boolean;
352
+ /**
353
+ * Whether to compute moved text detection.
354
+ */
355
+ computeMoves: boolean;
356
+ /**
357
+ * Whether to extend diffs to subword boundaries.
358
+ */
359
+ extendToSubwords: boolean;
360
+ }
361
+ /**
362
+ * The main diff computer that computes detailed line diffs.
363
+ */
364
+ declare class DefaultLinesDiffComputer {
365
+ private readonly _dynamicProgrammingDiffing;
366
+ private readonly _myersDiffingAlgorithm;
367
+ computeDiff(originalLines: string[], modifiedLines: string[], options: ILinesDiffComputerOptions): LinesDiff;
368
+ private _refineDiff;
369
+ }
370
+
371
+ /**
372
+ * Types for WASM interop, matching the Rust WasmLinesDiff structure.
373
+ */
374
+ /**
375
+ * A line range in the diff result.
376
+ */
377
+ interface WasmLineRange {
378
+ startLineNumber: number;
379
+ endLineNumberExclusive: number;
380
+ }
381
+ /**
382
+ * A character-level range mapping between original and modified.
383
+ */
384
+ interface WasmRangeMapping {
385
+ originalStartLine: number;
386
+ originalStartColumn: number;
387
+ originalEndLine: number;
388
+ originalEndColumn: number;
389
+ modifiedStartLine: number;
390
+ modifiedStartColumn: number;
391
+ modifiedEndLine: number;
392
+ modifiedEndColumn: number;
393
+ }
394
+ /**
395
+ * A detailed mapping between line ranges with optional inner character changes.
396
+ */
397
+ interface WasmDetailedLineRangeMapping {
398
+ original: WasmLineRange;
399
+ modified: WasmLineRange;
400
+ innerChanges: WasmRangeMapping[] | null;
401
+ }
402
+ /**
403
+ * Result of a WASM diff computation.
404
+ */
405
+ interface WasmLinesDiff {
406
+ changes: WasmDetailedLineRangeMapping[];
407
+ hitTimeout: boolean;
408
+ }
409
+ /**
410
+ * Options for the WASM diff computation.
411
+ */
412
+ interface WasmDiffOptions {
413
+ maxComputationTimeMs?: number;
414
+ ignoreTrimWhitespace?: boolean;
415
+ computeMoves?: boolean;
416
+ extendToSubwords?: boolean;
417
+ }
418
+ /**
419
+ * WASM module exports interface.
420
+ */
421
+ interface WasmModule {
422
+ computeDiff(original: string, modified: string, options: WasmDiffOptions | undefined): WasmLinesDiff;
423
+ computeDiffLines(originalLines: string[], modifiedLines: string[], options: WasmDiffOptions | undefined): WasmLinesDiff;
424
+ init(): void;
425
+ }
426
+
427
+ /**
428
+ * WASM module loader.
429
+ *
430
+ * Handles async initialization of the WASM module.
431
+ */
432
+
433
+ /**
434
+ * Initialize the WASM module.
435
+ *
436
+ * This must be called before using any WASM-based diff functions.
437
+ * It's safe to call multiple times — subsequent calls are no-ops.
438
+ *
439
+ * @returns Promise that resolves when WASM is ready
440
+ */
441
+ declare function initWasm(): Promise<WasmModule>;
442
+ /**
443
+ * Get the WASM module synchronously.
444
+ *
445
+ * @throws Error if WASM hasn't been initialized yet
446
+ * @returns The WASM module
447
+ */
448
+ declare function getWasm(): WasmModule;
449
+
450
+ export { AnnotatedStringEdit, AnnotatedStringReplacement, DiffAnnotation, DiffResult, Move, OffsetRange, OffsetRangeMapping, StringEdit, StringReplacement, DefaultLinesDiffComputer as _DefaultLinesDiffComputer, DetailedLineRangeMapping as _DetailedLineRangeMapping, LineRange as _LineRange, LineRangeMapping as _LineRangeMapping, LinesDiff as _LinesDiff, RangeMapping as _RangeMapping, getWasm as _getWasm, initWasm as _initWasm, createDiffComputer, createWorkerDiffComputer };
451
+ export type { CreateDiffComputerOptions, CreateWorkerDiffComputerOptions, DiffOptions, IAsyncDiffComputer, IDiffComputer, IEditData };