Skip to content

Commit e3a2015

Browse files
improve highlighter type
1 parent 9a197b2 commit e3a2015

6 files changed

Lines changed: 23 additions & 20 deletions

File tree

packages/core/src/diff-parse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable max-lines */
2-
// NODE: ALL of the Diff parse logic from desktop, SEE https://github.com/desktop/desktop
2+
3+
// !NOTE: ALL of the diff parse logic copy from desktop, SEE https://github.com/desktop/desktop
34

45
// https://en.wikipedia.org/wiki/Diff_utility
56
//

packages/core/src/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { highlighter } from "@git-diff-view/lowlight";
22

33
import { Cache } from "./cache";
44

5-
import type { AST } from "@git-diff-view/lowlight";
5+
import type { DiffAST } from "@git-diff-view/lowlight";
66

77
const map = new Cache<string, File>();
88

@@ -44,7 +44,7 @@ export type SyntaxLine = {
4444
};
4545

4646
export class File {
47-
ast?: AST;
47+
ast?: DiffAST;
4848

4949
rawFile: Record<number, string> = {};
5050

packages/lowlight/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ lowlight.register("vue", function hljsDefineVue(hljs) {
5050
};
5151
});
5252

53-
export type AST = ReturnType<typeof lowlight.highlight>;
53+
export type DiffAST = ReturnType<typeof lowlight.highlight>;
5454

55-
export type Highlighter = {
55+
export type DiffHighlighter = {
5656
name: string;
5757
maxLineToIgnoreSyntax: number;
5858
setMaxLineToIgnoreSyntax: (v: number) => void;
5959
ignoreSyntaxHighlightList: (string | RegExp)[];
6060
setIgnoreSyntaxHighlightList: (v: (string | RegExp)[]) => void;
61-
getAST: (raw: string, fileName?: string, lang?: string) => AST;
62-
processAST: (ast: AST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };
61+
getAST: (raw: string, fileName?: string, lang?: string) => DiffAST;
62+
processAST: (ast: DiffAST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };
6363
};
6464

6565
const instance = { name: "lowlight" };
@@ -120,11 +120,11 @@ Object.defineProperty(instance, "getAST", {
120120
});
121121

122122
Object.defineProperty(instance, "processAST", {
123-
value: (ast: AST) => {
123+
value: (ast: DiffAST) => {
124124
return processAST(ast);
125125
},
126126
});
127127

128128
export { processAST } from "./processAST";
129129

130-
export const highlighter: Highlighter = instance as Highlighter;
130+
export const highlighter: DiffHighlighter = instance as DiffHighlighter;

packages/lowlight/src/processAST.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AST } from ".";
1+
import type { DiffAST } from ".";
22

33
export type SyntaxNode = {
44
type: string;
@@ -17,7 +17,7 @@ export type SyntaxLine = {
1717
nodeList: { node: SyntaxNode; wrapper?: SyntaxNode }[];
1818
};
1919

20-
export const processAST = (ast: AST) => {
20+
export const processAST = (ast: DiffAST) => {
2121
let lineNumber = 1;
2222

2323
const syntaxObj: Record<number, SyntaxLine> = {};

packages/shiki/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { processAST, type SyntaxLine } from "./processAST";
44

55
import type { codeToHast } from "shiki";
66

7-
export type AST = DePromise<ReturnType<typeof codeToHast>>;
7+
export type DiffAST = DePromise<ReturnType<typeof codeToHast>>;
88

9-
export type Highlighter = {
9+
export type DiffHighlighter = {
1010
name: string;
1111
maxLineToIgnoreSyntax: number;
1212
setMaxLineToIgnoreSyntax: (v: number) => void;
1313
ignoreSyntaxHighlightList: (string | RegExp)[];
1414
setIgnoreSyntaxHighlightList: (v: (string | RegExp)[]) => void;
15-
getAST: (raw: string, fileName?: string, lang?: string) => AST;
16-
processAST: (ast: AST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };
15+
getAST: (raw: string, fileName?: string, lang?: string) => DiffAST;
16+
processAST: (ast: DiffAST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };
1717
};
1818

1919
let internal: DePromise<ReturnType<typeof getHighlighter>> | null = null;
@@ -106,14 +106,14 @@ Object.defineProperty(instance, "getAST", {
106106
});
107107

108108
Object.defineProperty(instance, "processAST", {
109-
value: (ast: AST) => {
109+
value: (ast: DiffAST) => {
110110
return processAST(ast);
111111
},
112112
});
113113

114-
const highlighter: Highlighter = instance as Highlighter;
114+
const highlighter: DiffHighlighter = instance as DiffHighlighter;
115115

116-
export const highlighterReady = new Promise<Highlighter>((r) => {
116+
export const highlighterReady = new Promise<DiffHighlighter>((r) => {
117117
if (internal) {
118118
r(highlighter);
119119
} else {
@@ -125,4 +125,6 @@ export const highlighterReady = new Promise<Highlighter>((r) => {
125125
}
126126
});
127127

128+
export { processAST } from "./processAST";
129+
128130
export * from "shiki";

packages/shiki/src/processAST.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AST } from ".";
1+
import type { DiffAST } from ".";
22

33
export type SyntaxNode = {
44
type: string;
@@ -17,7 +17,7 @@ export type SyntaxLine = {
1717
nodeList: { node: SyntaxNode; wrapper?: SyntaxNode }[];
1818
};
1919

20-
export const processAST = (ast: AST) => {
20+
export const processAST = (ast: DiffAST) => {
2121
let lineNumber = 1;
2222

2323
const syntaxObj: Record<number, SyntaxLine> = {};

0 commit comments

Comments
 (0)