Skip to content

Commit

Permalink
more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Apr 13, 2024
1 parent 88385af commit 3f72e35
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/components/DocumentView/CodeBlock/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,19 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
return a.start - b.start;
});

const lineCountBefore = lineCount;
const highlighter = await loadHighlighter();
await loadHighlighterLanguage(highlighter, langName);
lineCount += block.nodes.length;

const start = Date.now();
const lines = highlighter.codeToTokensBase(code, {
lang: langName,
tokenizeMaxLineLength: 120,
});
const end = Date.now() - start;
const duration = Date.now() - start;

let currentIndex = 0;

console.log(
`${block.key} ${end - start}ms code len: ${code.length} lineCountBefore: ${lineCountBefore} tokenCount: ${tokenCount}`,
);
return lines.map((tokens, index) => {
const result = lines.map((tokens, index) => {
tokenCount += tokens.length;
const lineBlock = block.nodes[index];
const result: HighlightToken[] = [];
Expand All @@ -98,6 +94,7 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
};

while (tokens.length > 0) {
console.log(`tokens.length: ${tokens.length}`)
result.push(...matchTokenAndInlines(eatToken, inlines));
}

Expand All @@ -108,6 +105,12 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
tokens: result,
};
});

console.log(
`${block.key} ${duration}ms code len: ${code.length} lineCountBefore: ${lineCount} tokenCount: ${tokenCount} created lines: ${result.length}`,
);

return result;
});
}

Expand Down

0 comments on commit 3f72e35

Please sign in to comment.