Skip to content

Commit

Permalink
Find correct edgecase rule in list mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Sep 19, 2024
1 parent 182c428 commit 3620bf5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Providers/TreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,37 +714,41 @@ async function gotoGrammar(element: element) {
const line = element.line;
if (id == 0) {
ruleId = grammar.lines[line].lastRule;
// vscode.window.showInformationMessage(`LineTokens: ${JSON.stringify(grammar.lines[line])}`);
}

if (id == 1) {
// Find the last (scopeNamed) rule that intersects the token
const tokenLine = grammar.lines[line];
// vscode.window.showInformationMessage(JSON.stringify(tokenLine));
const token = tokenLine.tokens[element.tokenId];
const tokenStart = token.startIndex;
const tokenEnd = token.endIndex; // This is required otherwise 0 width end rules get in the way
const rulesLength = tokenLine.rulesLength;
const rulesLength = tokenLine.rulesLength; // Start at the first rule in the line
// vscode.window.showInformationMessage(JSON.stringify(rulesLength));
let foundRule = false;
let breakLoop = false;
for (let index = rulesLength; index < grammar.rules.length; index++) {
const rule = grammar.rules[index];
if (!rule) {
break;
}
let foundRule = false;
let captureIndex = -1;
for (const captureIndice of rule.captureIndices) {
captureIndex++;
if (captureIndice.start == tokenStart && captureIndice.end >= tokenEnd) {
ruleId = rule.matchedRuleId;
capturesIndex = captureIndex;
// vscode.window.showInformationMessage("Capture: " + captureIndex);
foundRule = true;
// Keep going if next token is identical. (((x))) => 3 not 1
}
else if (foundRule) {
breakLoop = true;
break;
}
captureIndex++;
}
if (foundRule) {
ruleId = rule.matchedRuleId;
capturesIndex = captureIndex;
// vscode.window.showInformationMessage("Capture: " + captureIndex);
if (breakLoop) {
break;
}
}
Expand Down Expand Up @@ -785,7 +789,7 @@ async function gotoGrammar(element: element) {
grammarDoc = await vscode.workspace.openTextDocument(uri);
}
}
vscode.window.showInformationMessage(JSON.stringify(path) + " Capture: " + capturesIndex);
vscode.window.showInformationMessage(`${JSON.stringify(path)} Capture: ${capturesIndex}`);

const trees = getTrees(grammarDoc);
const tree = trees.jsonTree;
Expand Down

1 comment on commit 3620bf5

@RedCMD
Copy link
Owner Author

@RedCMD RedCMD commented on 3620bf5 Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10

Please sign in to comment.