From 288f55da7667d0678d4c1abc248da2cff54891e4 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Sep 2023 12:32:50 +0200 Subject: [PATCH] Add syntax highlighting to patch and commit changesets - This commit doesn't change the way syntax highlighting is done. - But due to changes in `radicle-httpd` we can highlight the entire files of a changeset, and then replace the plain text lines with highlighted ones. - Also highlights only the files currently visible of a changeset. Signed-off-by: Sebastian Martinez --- httpd-client/index.ts | 4 +- httpd-client/lib/project.ts | 11 +- httpd-client/lib/project/commit.ts | 50 ++++++-- src/components/Observer.svelte | 41 ++++++ src/views/projects/Changeset.svelte | 125 +++++++++++-------- src/views/projects/Changeset/FileDiff.svelte | 46 ++++++- src/views/projects/Commit.svelte | 5 +- src/views/projects/Patch.svelte | 6 +- src/views/projects/router.ts | 12 +- tests/support/heartwood-version | 2 +- 10 files changed, 218 insertions(+), 84 deletions(-) create mode 100644 src/components/Observer.svelte diff --git a/httpd-client/index.ts b/httpd-client/index.ts index 2590179e2..82dadc087 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -1,7 +1,6 @@ import type { BaseUrl } from "./lib/fetcher.js"; import type { Blob, - CommitBlob, Project, Remote, Tree, @@ -10,8 +9,10 @@ import type { import type { Comment } from "./lib/project/comment.js"; import type { Commit, + CommitBlob, CommitHeader, Diff, + DiffBlob, DiffContent, DiffFile, HunkLine, @@ -46,6 +47,7 @@ export type { CommitBlob, CommitHeader, Diff, + DiffBlob, DiffContent, DiffFile, DiffResponse, diff --git a/httpd-client/lib/project.ts b/httpd-client/lib/project.ts index 6ef6c88c6..5b9d04f1a 100644 --- a/httpd-client/lib/project.ts +++ b/httpd-client/lib/project.ts @@ -29,6 +29,7 @@ import { } from "zod"; import { + diffBlobSchema, commitHeaderSchema, commitSchema, commitsSchema, @@ -86,14 +87,6 @@ const blobSchema = object({ export type Blob = z.infer; -const commitBlobSchema = object({ - binary: boolean(), - content: optional(string()), - lastCommit: commitHeaderSchema, -}); - -export type CommitBlob = z.infer; - const treeEntrySchema = object({ path: string(), name: string(), @@ -138,7 +131,7 @@ export type DiffResponse = z.infer; const diffResponseSchema = object({ commits: array(commitHeaderSchema), diff: diffSchema, - files: record(string(), commitBlobSchema), + files: record(string(), diffBlobSchema), }); export class Client { diff --git a/httpd-client/lib/project/commit.ts b/httpd-client/lib/project/commit.ts index ed0043c09..9a8f60464 100644 --- a/httpd-client/lib/project/commit.ts +++ b/httpd-client/lib/project/commit.ts @@ -1,17 +1,34 @@ import type { z } from "zod"; export type { + Commit, + CommitHeader, Commits, + Diff, + DiffContent, + DiffFile, HunkLine, Hunks, - Commit, - Diff, - CommitHeader, - DiffFile, - DiffContent, }; -import { array, literal, number, object, optional, string, union } from "zod"; -export { commitHeaderSchema, diffSchema, commitSchema, commitsSchema }; +import { + array, + boolean, + literal, + number, + object, + optional, + record, + string, + union, +} from "zod"; +export { + commitBlobSchema, + commitHeaderSchema, + commitSchema, + commitsSchema, + diffBlobSchema, + diffSchema, +}; const gitPersonSchema = object({ name: string(), @@ -29,6 +46,22 @@ const commitHeaderSchema = object({ committer: gitPersonSchema.merge(object({ time: number() })), }); +const diffBlobSchema = object({ + binary: boolean(), + content: string(), + id: string(), + lastCommit: commitHeaderSchema, +}); + +export type DiffBlob = z.infer; + +const commitBlobSchema = object({ + binary: boolean(), + content: string(), +}); + +export type CommitBlob = z.infer; + type AdditionHunkLine = z.infer; const additionHunkLineSchema = object({ @@ -146,12 +179,13 @@ const commitSchema = object({ commit: commitHeaderSchema, diff: diffSchema, branches: array(string()), + files: record(string(), commitBlobSchema), }); type Commits = z.infer; const commitsSchema = object({ - commits: array(commitSchema), + commits: array(commitSchema.omit({ files: true })), stats: object({ commits: number(), branches: number(), diff --git a/src/components/Observer.svelte b/src/components/Observer.svelte new file mode 100644 index 000000000..081411080 --- /dev/null +++ b/src/components/Observer.svelte @@ -0,0 +1,41 @@ + + + + + diff --git a/src/views/projects/Changeset.svelte b/src/views/projects/Changeset.svelte index 3e29ae8c0..146181d3b 100644 --- a/src/views/projects/Changeset.svelte +++ b/src/views/projects/Changeset.svelte @@ -1,8 +1,8 @@