Skip to content

Commit

Permalink
Add proper icons. Add goto function in list view. Improve performan…
Browse files Browse the repository at this point in the history
…ce timings. Add `find` #10
  • Loading branch information
RedCMD committed Mar 12, 2024
1 parent 282a4a3 commit 6e3ce56
Show file tree
Hide file tree
Showing 7 changed files with 606 additions and 225 deletions.
27 changes: 18 additions & 9 deletions out/TextMate.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,42 +108,51 @@ async function tokenizeLine(document, lineNumber) {
return tokenLineResult;
}
exports.tokenizeLine = tokenizeLine;
async function tokenizeFile(document) {
async function tokenizeFile(document, runTwice) {
const lang = document.languageId;
const scopeName = getScopeName(lang);
// const grammar = await registry.loadGrammar(scopeName);
const grammar = await registry.loadGrammar(scopeName);
// Very hacky, assigns array so `_tokenizeString()` can add rules to it
grammar.rules = [];
grammar.lines = [];
// cache rules for more accurate debug timing
let ruleStack = vscodeTextmate.INITIAL;
for (let i = 0; i < document.lineCount; i++) {
ruleStack = grammar.tokenizeLine(document.lineAt(i).text, ruleStack, 15000).ruleStack;
// cache rules for more accurate debug timing
if (runTwice) {
for (let i = 0; i < document.lineCount; i++) {
ruleStack = grammar.tokenizeLine(document.lineAt(i).text, ruleStack, 15000).ruleStack;
}
grammar.rules = [];
// vscode.window.showInformationMessage(JSON.stringify(grammar, stringify));
}
grammar.rules = [];
// vscode.window.showInformationMessage(JSON.stringify(grammar, stringify));
let rulesLength = 0;
ruleStack = vscodeTextmate.INITIAL;
const startTime = performance.now();
grammar.startTime = startTime;
for (let i = 0; i < document.lineCount; i++) {
// vscode.window.showInformationMessage(JSON.stringify(grammar, stringify));
const line = document.lineAt(i).text;
const lineTokens = grammar.tokenizeLine(line, ruleStack, 15000);
// grammar.rules.pop();
grammar.rules.push(undefined);
ruleStack = lineTokens.ruleStack;
grammar.lines.push({
tokens: lineTokens.tokens,
stoppedEarly: lineTokens.stoppedEarly,
time: performance.now() - startTime,
// @ts-ignore
lastRule: ruleStack.ruleId || 1,
rulesLength: rulesLength,
});
rulesLength = grammar.rules.length;
// tokenLineResults.push(
// {
// tokens: lineTokens.tokens,
// ruleStack: structuredClone(lineTokens.ruleStack),
// stoppedEarly: lineTokens.stoppedEarly,
// }
// );
// grammar.rules.pop();
grammar.rules.push(undefined);
ruleStack = lineTokens.ruleStack;
// vscode.window.showInformationMessage(JSON.stringify(ruleStack, stringify));
}
// vscode.window.showInformationMessage(JSON.stringify(registry, stringify));
vscode.window.showInformationMessage(JSON.stringify(grammar, extension_1.stringify));
Expand Down
Loading

0 comments on commit 6e3ce56

Please sign in to comment.