Skip to content

Commit

Permalink
Add support for Delta documents
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaspit committed Jan 8, 2025
1 parent 920740b commit 78a1e92
Show file tree
Hide file tree
Showing 56 changed files with 2,746 additions and 563 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-deers-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sillsdev/lynx': minor
---

Update core APIs to be more generic (specify the document, change/edit, and content types)
5 changes: 5 additions & 0 deletions .changeset/two-chairs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sillsdev/lynx-usfm': minor
---

Add USFM edit factory
5 changes: 5 additions & 0 deletions .changeset/wicked-windows-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sillsdev/lynx-delta': minor
---

Initial release
100 changes: 98 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/src/diagnostic/diagnostic-fix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TextEdit } from '../common/text-edit';
import { Diagnostic } from './diagnostic';

export interface DiagnosticFix {
export interface DiagnosticFix<T = TextEdit> {
title: string;
diagnostic: Diagnostic;
isPreferred?: boolean;
edits: TextEdit[];
edits: T[];
}
5 changes: 3 additions & 2 deletions packages/core/src/diagnostic/diagnostic-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Observable } from 'rxjs';

import { TextEdit } from '../common/text-edit';
import { Diagnostic } from './diagnostic';
import { DiagnosticFix } from './diagnostic-fix';

Expand All @@ -9,10 +10,10 @@ export interface DiagnosticsChanged {
diagnostics: Diagnostic[];
}

export interface DiagnosticProvider {
export interface DiagnosticProvider<T = TextEdit> {
readonly id: string;
readonly diagnosticsChanged$: Observable<DiagnosticsChanged>;
init(): Promise<void>;
getDiagnostics(uri: string): Promise<Diagnostic[]>;
getDiagnosticFixes(uri: string, diagnostic: Diagnostic): Promise<DiagnosticFix[]>;
getDiagnosticFixes(uri: string, diagnostic: Diagnostic): Promise<DiagnosticFix<T>[]>;
}
35 changes: 35 additions & 0 deletions packages/core/src/document/document-accessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Observable } from 'rxjs';

import { Document } from './document';

export interface DocumentCreated<T extends Document> {
document: T;
}

export interface DocumentClosed {
uri: string;
}

export interface DocumentOpened<T extends Document> {
document: T;
}

export interface DocumentDeleted {
uri: string;
}

export interface DocumentChanged<T extends Document> {
document: T;
}

export interface DocumentAccessor<T extends Document = Document> {
readonly created$: Observable<DocumentCreated<T>>;
readonly closed$: Observable<DocumentClosed>;
readonly opened$: Observable<DocumentOpened<T>>;
readonly deleted$: Observable<DocumentDeleted>;
readonly changed$: Observable<DocumentChanged<T>>;

get(uri: string): Promise<T | undefined>;
all(): Promise<T[]>;
active(): Promise<T[]>;
}
13 changes: 4 additions & 9 deletions packages/core/src/document/document-factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Range } from '../common/range';
import { Document } from './document';
import { TextDocumentChange } from './text-document-change';

export interface DocumentChange {
range?: Range;
text: string;
}

export interface DocumentFactory<T extends Document> {
create(uri: string, format: string, version: number, content: string): T;
update(document: T, changes: readonly DocumentChange[], version: number): T;
export interface DocumentFactory<TDoc extends Document = Document, TChange = TextDocumentChange, TContent = string> {
create(uri: string, format: string, version: number, content: TContent): TDoc;
update(document: TDoc, changes: readonly TChange[], version: number): TDoc;
}
Loading

0 comments on commit 78a1e92

Please sign in to comment.