Skip to content

Commit

Permalink
Add syntax highlighting for diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Dec 9, 2024
1 parent 52c25a9 commit e386dd2
Show file tree
Hide file tree
Showing 37 changed files with 2,537 additions and 20 deletions.
643 changes: 639 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions crates/radicle-tauri/src/commands/diff.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use radicle_surf as surf;

use radicle::identity;
use radicle_types as types;
use radicle_types::error::Error;
use radicle_types::traits::repo::Repo;

Expand All @@ -11,6 +10,6 @@ pub async fn get_diff(
ctx: tauri::State<'_, AppState>,
rid: identity::RepoId,
options: radicle_types::cobs::diff::Options,
) -> Result<surf::diff::Diff, Error> {
) -> Result<types::diff::Diff, Error> {
ctx.get_diff(rid, options)
}
19 changes: 17 additions & 2 deletions crates/radicle-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ edition = "2021"
anyhow = { version = "1.0.90" }
axum = { version = "0.7.5", default-features = false, features = ["json"] }
base64 = { version = "0.22.1" }
localtime = { version = "1.3.1" }
radicle = { git = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" }
radicle-surf = { version = "0.22.1", features = ["serde"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = { version = "1.0.132" }
thiserror = { version = "1.0.65" }
ts-rs = { version = "10.0.0", features = [ "serde-json-impl", "no-serde-warnings" ] }
localtime = { version = "1.3.1" }
tree-sitter-bash = { version = "0.23.3" }
tree-sitter-c = { version = "0.23.2" }
tree-sitter-css = { version = "0.23.1" }
tree-sitter-go = { version = "0.23.4" }
tree-sitter-highlight = { version = "0.24.4" }
tree-sitter-html = { version = "0.23.2" }
tree-sitter-javascript = { version = "0.23.1" }
tree-sitter-json = { version = "0.24.8" }
tree-sitter-md = { version = "0.3.2" }
tree-sitter-python = { version = "0.23.4" }
tree-sitter-ruby = { version = "0.23.1" }
tree-sitter-rust = { version = "0.23.2" }
tree-sitter-svelte-ng = { version = "1.0.2" }
tree-sitter-toml-ng = { version = "0.7.0" }
tree-sitter-typescript = { version = "0.23.2" }
ts-rs = { version = "10.0.0", features = [ "format", "serde-json-impl", "no-serde-warnings" ] }
5 changes: 5 additions & 0 deletions crates/radicle-types/bindings/diff/Added.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DiffContent } from "./DiffContent";
import type { DiffFile } from "./DiffFile";

export type Added = { path: string; diff: DiffContent; new: DiffFile };
4 changes: 4 additions & 0 deletions crates/radicle-types/bindings/diff/Addition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Line } from "../syntax/Line";

export type Addition = { line: string; lineNo: number; highlight: Line | null };
11 changes: 11 additions & 0 deletions crates/radicle-types/bindings/diff/Copied.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DiffContent } from "./DiffContent";
import type { DiffFile } from "./DiffFile";

export type Copied = {
oldPath: string;
newPath: string;
old: DiffFile;
new: DiffFile;
diff: DiffContent;
};
5 changes: 5 additions & 0 deletions crates/radicle-types/bindings/diff/Deleted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DiffContent } from "./DiffContent";
import type { DiffFile } from "./DiffFile";

export type Deleted = { path: string; diff: DiffContent; old: DiffFile };
4 changes: 4 additions & 0 deletions crates/radicle-types/bindings/diff/Deletion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Line } from "../syntax/Line";

export type Deletion = { line: string; lineNo: number; highlight: Line | null };
5 changes: 5 additions & 0 deletions crates/radicle-types/bindings/diff/Diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { FileDiff } from "./FileDiff";
import type { Stats } from "./Stats";

export type Diff = { files: Array<FileDiff>; stats: Stats };
11 changes: 11 additions & 0 deletions crates/radicle-types/bindings/diff/DiffContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { EofNewLine } from "./EofNewLine";
import type { FileStats } from "./FileStats";
import type { Hunks } from "./Hunks";

export type DiffContent = { "type": "binary" } | {
"type": "plain";
hunks: Hunks;
stats: FileStats;
eof: EofNewLine;
} | { "type": "empty" };
4 changes: 4 additions & 0 deletions crates/radicle-types/bindings/diff/DiffFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { FileMode } from "./FileMode";

export type DiffFile = { oid: string; mode: FileMode };
7 changes: 7 additions & 0 deletions crates/radicle-types/bindings/diff/EofNewLine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type EofNewLine =
| "oldMissing"
| "newMissing"
| "bothMissing"
| "noneMissing";
13 changes: 13 additions & 0 deletions crates/radicle-types/bindings/diff/FileDiff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Added } from "./Added";
import type { Copied } from "./Copied";
import type { Deleted } from "./Deleted";
import type { Modified } from "./Modified";
import type { Moved } from "./Moved";

export type FileDiff =
| { "status": "added" } & Added
| { "status": "deleted" } & Deleted
| { "status": "modified" } & Modified
| { "status": "moved" } & Moved
| { "status": "copied" } & Copied;
3 changes: 3 additions & 0 deletions crates/radicle-types/bindings/diff/FileMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type FileMode = "blob" | "blobExecutable" | "tree" | "link" | "commit";
3 changes: 3 additions & 0 deletions crates/radicle-types/bindings/diff/FileStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type FileStats = { additions: number; deletions: number };
9 changes: 9 additions & 0 deletions crates/radicle-types/bindings/diff/Hunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Modification } from "./Modification";

export type Hunk = {
header: string;
lines: Array<Modification>;
old: { start: number; end: number };
new: { start: number; end: number };
};
4 changes: 4 additions & 0 deletions crates/radicle-types/bindings/diff/Hunks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Hunk } from "./Hunk";

export type Hunks = Array<Hunk>;
3 changes: 3 additions & 0 deletions crates/radicle-types/bindings/diff/Line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type Line = Array<number>;
15 changes: 15 additions & 0 deletions crates/radicle-types/bindings/diff/Modification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Addition } from "./Addition";
import type { Deletion } from "./Deletion";
import type { Line } from "../syntax/Line";

export type Modification =
| { "type": "addition" } & Addition
| { "type": "deletion" } & Deletion
| {
"type": "context";
line: string;
lineNoOld: number;
lineNoNew: number;
highlight: Line | null;
};
10 changes: 10 additions & 0 deletions crates/radicle-types/bindings/diff/Modified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DiffContent } from "./DiffContent";
import type { DiffFile } from "./DiffFile";

export type Modified = {
path: string;
diff: DiffContent;
old: DiffFile;
new: DiffFile;
};
11 changes: 11 additions & 0 deletions crates/radicle-types/bindings/diff/Moved.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DiffContent } from "./DiffContent";
import type { DiffFile } from "./DiffFile";

export type Moved = {
oldPath: string;
old: DiffFile;
newPath: string;
new: DiffFile;
diff: DiffContent;
};
7 changes: 7 additions & 0 deletions crates/radicle-types/bindings/diff/Stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type Stats = {
filesChanged: number;
insertions: number;
deletions: number;
};
7 changes: 7 additions & 0 deletions crates/radicle-types/bindings/syntax/Label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Paint } from "./Paint";

/**
* A styled string that does not contain any `'\n'`.
*/
export type Label = Paint;
7 changes: 7 additions & 0 deletions crates/radicle-types/bindings/syntax/Line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Label } from "./Label";

/**
* A line of text that has styling and can be displayed.
*/
export type Line = { items: Array<Label> };
6 changes: 6 additions & 0 deletions crates/radicle-types/bindings/syntax/Paint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* A structure encapsulating an item and styling.
*/
export type Paint = { item: string; style: string | null };
3 changes: 2 additions & 1 deletion crates/radicle-types/src/cobs/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ use serde::{Deserialize, Serialize};
pub struct Options {
pub base: git::Oid,
pub head: git::Oid,
pub unified: u32,
pub unified: Option<u32>,
pub highlight: Option<bool>,
}
Loading

0 comments on commit e386dd2

Please sign in to comment.