Skip to content

Commit

Permalink
Improve scope views in list mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Mar 15, 2024
1 parent 121aa7c commit 00cf3ea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
39 changes: 32 additions & 7 deletions out/TreeDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ exports.TreeDataProvider = {
// vscode.window.showInformationMessage(JSON.stringify("element done"));
return elements;
}
if (element.id == 1) {
const token = element.tokenId;
for (let index = 0; index < grammar.lines[element.line].tokens[token].scopes.length; index++) {
const tokenElement = {
id: 2,
tokenId: element.tokenId,
scopeId: index,
line: element.line,
document: document,
type: 'list',
};
elements.push(tokenElement);
}
return elements;
}
}
},
getTreeItem(element) {
Expand All @@ -157,13 +172,13 @@ exports.TreeDataProvider = {
const label = /* timeFixed + ': ' + */ grammar._rootScopeName;
const treeLabel = {
label: label,
highlights: time >= 500 ? [[0, label.length]] : null,
// highlights: time >= 500 ? [[0, label.length]] : null,
// highlights: time >= 500 ? [[0, timeFixed.length]] : null,
};
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.Collapsed);
item.iconPath = new vscode.ThemeIcon('symbol-variable');
item.tooltip = `Time: ${time}`;
item.description = `${timeFixed}ms`;
item.description = timeFixed + "ms" + (time > 500 ? ' ⚠️' : '');
return item;
}
const document = element.document;
Expand Down Expand Up @@ -192,7 +207,7 @@ exports.TreeDataProvider = {
// const label = cachedRule.id + ": " + ruleChached[rule.matchedRuleId] + ": " + id;
const label = cachedRule._name || cachedRule._contentName || cachedRule.id.toString();
const treeLabel = {
label: label /* + (time >= 1 ? '' : '') */,
label: (time >= 1 ? '⚠️' : '') + label,
// highlights: ruleChached[rule.matchedRuleId] == id ? [[0, label.length]] : null,
// highlights: time >= 1 ? [[0, label.length]] : null,
};
Expand Down Expand Up @@ -262,14 +277,13 @@ exports.TreeDataProvider = {
const line = element.line;
const token = grammar.lines[line].tokens[element.tokenId];
// const scope = token.scopes[token.scopes.length - 1];
const scopes = token.scopes.join(' ');
const label = scopes;
const scope = token.scopes.at(-1);
const label = scope;
const treeLabel = {
label: label,
// highlights: time >= 10 ? [[0, timeFixed.length]] : null,
};
// const item = new vscode.TreeItem(line.toString(), vscode.TreeItemCollapsibleState.None);
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.None);
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.Collapsed);
// Account for newlines in uncaptured tokens
const newLineAdjust = token.scopes.length == 1 && (grammar.lines[line].tokens.length - 1 == element.tokenId) ? 1 : 0;
item.description = token.startIndex + " - " + (token.endIndex - newLineAdjust);
Expand All @@ -292,6 +306,17 @@ exports.TreeDataProvider = {
// item.command = command;
return item;
}
if (id == 2) {
const line = element.line;
const token = grammar.lines[line].tokens[element.tokenId];
const scope = token.scopes[element.scopeId];
const label = scope;
const treeLabel = {
label: label,
};
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.None);
return item;
}
}
},
getParent(element) {
Expand Down
43 changes: 36 additions & 7 deletions src/TreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getTrees, queryNode, toRange } from './TreeSitter';
type element = {
line?: number,
tokenId?: number,
scopeId?: number,
document: vscode.TextDocument,
token?: vscodeTextmate.IToken,
id?: number,
Expand Down Expand Up @@ -189,6 +190,22 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
// vscode.window.showInformationMessage(JSON.stringify("element done"));
return elements;
}

if (element.id == 1) {
const token = element.tokenId;
for (let index = 0; index < grammar.lines[element.line].tokens[token].scopes.length; index++) {
const tokenElement: element = {
id: 2,
tokenId: element.tokenId,
scopeId: index,
line: element.line,
document: document,
type: 'list',
};
elements.push(tokenElement);
}
return elements;
}
}
},
getTreeItem(element: element): vscode.TreeItem {
Expand All @@ -203,13 +220,13 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
const label = /* timeFixed + ': ' + */ grammar._rootScopeName;
const treeLabel: vscode.TreeItemLabel = {
label: label,
highlights: time >= 500 ? [[0, label.length]] : null,
// highlights: time >= 500 ? [[0, label.length]] : null,
// highlights: time >= 500 ? [[0, timeFixed.length]] : null,
};
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.Collapsed);
item.iconPath = new vscode.ThemeIcon('symbol-variable');
item.tooltip = `Time: ${time}`;
item.description = `${timeFixed}ms`;
item.description = timeFixed + "ms" + (time > 500 ? ' ⚠️' : '');
return item;
}

Expand Down Expand Up @@ -242,7 +259,7 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
// const label = cachedRule.id + ": " + ruleChached[rule.matchedRuleId] + ": " + id;
const label = cachedRule._name || cachedRule._contentName || cachedRule.id.toString();
const treeLabel: vscode.TreeItemLabel = {
label: label /* + (time >= 1 ? '' : '') */,
label: (time >= 1 ? '⚠️' : '') + label,
// highlights: ruleChached[rule.matchedRuleId] == id ? [[0, label.length]] : null,
// highlights: time >= 1 ? [[0, label.length]] : null,
};
Expand Down Expand Up @@ -322,15 +339,14 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
const line = element.line;
const token = grammar.lines[line].tokens[element.tokenId];
// const scope = token.scopes[token.scopes.length - 1];
const scopes = token.scopes.join(' ');
const scope = token.scopes.at(-1);

const label = scopes;
const label = scope;
const treeLabel: vscode.TreeItemLabel = {
label: label,
// highlights: time >= 10 ? [[0, timeFixed.length]] : null,
};
// const item = new vscode.TreeItem(line.toString(), vscode.TreeItemCollapsibleState.None);
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.None);
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.Collapsed);
// Account for newlines in uncaptured tokens
const newLineAdjust = token.scopes.length == 1 && (grammar.lines[line].tokens.length - 1 == element.tokenId) ? 1 : 0;
item.description = token.startIndex + " - " + (token.endIndex - newLineAdjust);
Expand All @@ -353,6 +369,19 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
// };
// item.command = command;

return item;
}
if (id == 2) {
const line = element.line;
const token = grammar.lines[line].tokens[element.tokenId];
const scope = token.scopes[element.scopeId];

const label = scope;
const treeLabel: vscode.TreeItemLabel = {
label: label,
};
const item = new vscode.TreeItem(treeLabel, vscode.TreeItemCollapsibleState.None);

return item;
}
}
Expand Down

1 comment on commit 00cf3ea

@RedCMD
Copy link
Owner Author

@RedCMD RedCMD commented on 00cf3ea Mar 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.