Skip to content

Commit c6f3637

Browse files
committed
Add EOL token #10
1 parent 01546db commit c6f3637

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

src/Providers/TreeDataProvider.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ const TreeDataProvider: vscode.TreeDataProvider<element> = {
216216
}
217217
const rule = grammar._ruleId2desc[ruleId];
218218
if (!rule) {
219-
vscode.window.showInformationMessage(JSON.stringify(matchResult, stringify));
219+
// vscode.window.showInformationMessage(`noRule: ${ruleId}\n${JSON.stringify(matchResult, stringify)}`);
220+
continue;
220221
}
221222
if (rule._begin && !rule._while) {
222223
depth++;
@@ -389,15 +390,17 @@ const TreeDataProvider: vscode.TreeDataProvider<element> = {
389390
const timeFixed = time.toFixed(3);
390391

391392
// const label = cachedRule.id + ": " + ruleCached[rule.matchedRuleId] + ": " + id;
392-
const label = cachedRule._name || cachedRule._contentName || Math.abs(ruleId).toString();
393+
// vscode.window.showInformationMessage(`cachedRule\n${JSON.stringify(cachedRule)}`);
394+
const label = cachedRule?._name || cachedRule?._contentName || (ruleId ? Math.abs(ruleId).toString() : '<EOL>');
395+
// vscode.window.showInformationMessage(`label\n${JSON.stringify(label)}`);
393396
const treeLabel: vscode.TreeItemLabel = {
394397
label: `${label}${time >= 1 ? '⚠️' : ''}`,
395398
// highlights: ruleCached[rule.matchedRuleId] == id ? [[0, label.length]] : null,
396399
// highlights: time >= 1 ? [[0, label.length]] : null,
397400
};
398401
const item = new vscode.TreeItem(
399402
treeLabel,
400-
cachedRule._begin && ruleId >= 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, // TODO: toggle option
403+
cachedRule?._begin && ruleId >= 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, // TODO: toggle option
401404
);
402405
item.id = `_${id}`;
403406
if (!grammar.lines[line]) {
@@ -407,14 +410,14 @@ const TreeDataProvider: vscode.TreeDataProvider<element> = {
407410
}
408411
item.description = timeFixed + "ms" + (grammar.lines[line]?.stoppedEarly ? '❌' : time >= 1 ? ' ⚠️' : '');
409412
// item.description = timeFixed + "ms" + (ruleCached[rule.matchedRuleId] == id /* && !cachedRule._match */ ? ' ⚠️' : '');
410-
if (cachedRule._match) {
413+
if (cachedRule?._match) {
411414
item.iconPath = new vscode.ThemeIcon('regex');
412415
// item.iconPath = new vscode.ThemeIcon('symbol-event');
413416
}
414-
else if (cachedRule._begin && ruleId < 0) {
417+
else if (cachedRule?._begin && ruleId < 0) {
415418
item.iconPath = new vscode.ThemeIcon('chevron-up');
416419
}
417-
item.tooltip = `${cachedRule._match ? `match: ${cachedRule._match.source}` : ''}${ruleId >= 0 ? (cachedRule._begin ? `begin: ${cachedRule._begin.source}` : '') : (cachedRule._end ? `end: ${cachedRule._end.source}` : '')}${cachedRule._while ? `while: ${cachedRule._while.source}` : ''}\nRuleId: ${ruleId}`;
420+
item.tooltip = `${cachedRule?._match ? `match: ${cachedRule._match.source}` : ''}${ruleId >= 0 ? (cachedRule?._begin ? `begin: ${cachedRule._begin.source}` : '') : (cachedRule?._end ? `end: ${cachedRule._end.source}` : '')}${cachedRule?._while ? `while: ${cachedRule._while.source}` : ''}${ruleId ? '' : '<EndOfLine>'}\nRuleId: ${ruleId}`;
418421
item.command = {
419422
title: `Show Call Details`,
420423
command: 'textmate.call.details',
@@ -647,6 +650,7 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
647650
const cachedRule = grammar._ruleId2desc[Math.abs(ruleId)];
648651
// vscode.window.showInformationMessage(`cachedRule ${JSON.stringify(ruleId, stringify)}\n${JSON.stringify(cachedRule, stringify)}`);
649652
const regexes: string[] = [];
653+
// vscode.window.showInformationMessage(`_cachedCompiledPatterns\n${JSON.stringify(cachedRule._cachedCompiledPatterns!._items, stringify)}`);
650654
for (const regexSource of cachedRule._cachedCompiledPatterns!._items) {
651655
regexes.push(regexSource.source);
652656
}
@@ -665,12 +669,13 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
665669
const onigMatch = scanner.findNextMatchSync(onigLineText, start, options);
666670
const time = performance.now() - startTime;
667671
const timeFixed = time.toFixed(3);
672+
// vscode.window.showInformationMessage(`onigMatch ${start} ${options}\n${JSON.stringify(onigMatch, stringify)}\n${JSON.stringify(onigLineText, stringify)}`);
668673
scanner.dispose();
669674

670675
// const regex = cachedRule._match?.source ?? (ruleId < 0 ? cachedRule._while?.source ?? cachedRule._end?.source : cachedRule._begin?.source);
671676
const item = new vscode.TreeItem(
672677
// regex.substring(0, 50),
673-
cachedRule._cachedCompiledPatterns!._items[onigMatch!.index].source.substring(0, 50),
678+
onigMatch ? cachedRule._cachedCompiledPatterns!._items[onigMatch.index].source.substring(0, 50) : '<EOL>',
674679
vscode.TreeItemCollapsibleState.Expanded,
675680
);
676681

@@ -749,15 +754,17 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
749754

750755
export function initCallStackView(context: vscode.ExtensionContext): void {
751756
// vscode.window.showInformationMessage(`initCallStackView\n${JSON.stringify(context)}`);
752-
context.subscriptions.push(vscode.commands.registerTextEditorCommand("textmate.callstack", CallStackView));
753-
context.subscriptions.push(vscode.commands.registerCommand("textmate.refresh", refresh));
754-
context.subscriptions.push(vscode.commands.registerCommand("textmate.find", find));
755-
context.subscriptions.push(vscode.commands.registerCommand("textmate.call.details", callDetails));
756-
context.subscriptions.push(vscode.commands.registerCommand("textmate.goto.file", gotoFile));
757-
context.subscriptions.push(vscode.commands.registerCommand("textmate.goto.grammar", gotoGrammar));
758-
context.subscriptions.push(vscode.commands.registerCommand("textmate.tree-view", (element: element) => changeView('tree', element)));
759-
context.subscriptions.push(vscode.commands.registerCommand("textmate.list-view", (element: element) => changeView('list', element)));
760-
// context.subscriptions.push(vscode.window.onDidChangeActiveColorTheme(updateWorkbench_colorCustomizations));
757+
context.subscriptions.push(
758+
vscode.commands.registerTextEditorCommand("textmate.callstack", CallStackView),
759+
vscode.commands.registerCommand("textmate.refresh", refresh),
760+
vscode.commands.registerCommand("textmate.find", find),
761+
vscode.commands.registerCommand("textmate.call.details", callDetails),
762+
vscode.commands.registerCommand("textmate.goto.file", gotoFile),
763+
vscode.commands.registerCommand("textmate.goto.grammar", gotoGrammar),
764+
vscode.commands.registerCommand("textmate.tree-view", (element: element) => changeView('tree', element)),
765+
vscode.commands.registerCommand("textmate.list-view", (element: element) => changeView('list', element)),
766+
// vscode.window.onDidChangeActiveColorTheme(updateWorkbench_colorCustomizations),
767+
);
761768

762769
// await updateWorkbench_colorCustomizations();
763770

src/textmate/grammar/tokenizeString.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ export function _tokenizeString(
9797
// No match
9898
lineTokens.produce(stack, lineLength);
9999
STOP = true;
100+
const captureIndices = [
101+
{
102+
start: linePos,
103+
end: lineLength,
104+
length: lineLength - linePos,
105+
}
106+
];
107+
// @ts-ignore
108+
grammar.rules.push(
109+
{
110+
captureIndices: captureIndices,
111+
// captureIndices: captureIndices,
112+
// matchedRuleId: matchedRuleId == endRuleId ? -poppedRule!.id : matchedRuleId,
113+
// lineText: lineText,
114+
// isFirstLine: isFirstLine,
115+
linePos: prevLinePos,
116+
// stack: stack,
117+
anchorPosition: anchorPosition,
118+
time: performance.now(),
119+
// @ts-ignore
120+
// length: grammar._ruleId2desc.length - 1,
121+
// lastRuleId: grammar._lastRuleId,
122+
}
123+
);
100124
return;
101125
}
102126

0 commit comments

Comments
 (0)