Skip to content

Commit e9ddb51

Browse files
committed
Add copyGrammarToClipBoard button #10
1 parent 6229c78 commit e9ddb51

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

package.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,24 +396,34 @@
396396
"group": "inline@1",
397397
"when": "view == TextMate && viewItem == document"
398398
},
399+
{
400+
"command": "textmate.copytoclipboard.grammar",
401+
"group": "inline@3",
402+
"when": "view == TextMate && viewItem == root"
403+
},
399404
{
400405
"command": "textmate.goto.file",
401-
"group": "inline@2",
406+
"group": "inline@5",
402407
"when": "view == TextMate || view == TextMate-Call"
403408
},
404409
{
405410
"command": "textmate.goto.grammar",
406-
"group": "inline@3",
411+
"group": "inline@7",
407412
"when": "view == TextMate || view == TextMate-Call"
408413
},
414+
{
415+
"command": "textmate.copytoclipboard.grammar",
416+
"group": "0_navigation@3",
417+
"when": "view == TextMate && viewItem == root"
418+
},
409419
{
410420
"command": "textmate.goto.file",
411-
"group": "0_navigation@1",
421+
"group": "0_navigation@5",
412422
"when": "view == TextMate || view == TextMate-Call"
413423
},
414424
{
415425
"command": "textmate.goto.grammar",
416-
"group": "0_navigation@2",
426+
"group": "0_navigation@7",
417427
"when": "view == TextMate || view == TextMate-Call"
418428
}
419429
]
@@ -438,6 +448,12 @@
438448
"category": "TextMate",
439449
"icon": "assets/TextMate-file-icon.svg"
440450
},
451+
{
452+
"command": "textmate.copytoclipboard.grammar",
453+
"title": "Copy <grammar state> to clipboard (JSON)",
454+
"category": "TextMate",
455+
"icon": "$(copy)"
456+
},
441457
{
442458
"command": "textmate.call.details",
443459
"title": "Show Call Details",

src/Providers/TreeDataProvider.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ const TreeDataProvider: vscode.TreeDataProvider<element> = {
318318
item.tooltip = `Time: ${time}\nRuleCount: ${grammar.rules.length - grammar.lines.length}\nRegexCount: ${regexCount}`;
319319
item.description = `${timeFixed}ms${time > 500 ? ' ⚠️' : ''}`;
320320
item.id = grammar._rootScopeName;
321+
item.contextValue = 'root';
321322
return item;
322323
}
323324

@@ -853,14 +854,16 @@ export function initCallStackView(context: vscode.ExtensionContext): void {
853854
vscode.commands.registerTextEditorCommand("textmate.callstack", CallStackView),
854855
vscode.commands.registerCommand("textmate.refresh", refresh),
855856
vscode.commands.registerCommand("textmate.find", find),
857+
vscode.commands.registerCommand("textmate.copytoclipboard.grammar", copyToClipBoardGrammar),
856858
vscode.commands.registerCommand("textmate.call.details", callDetails),
857859
vscode.commands.registerCommand("textmate.goto.file", gotoFile),
858860
vscode.commands.registerCommand("textmate.goto.grammar", gotoGrammar),
859-
vscode.commands.registerCommand("textmate.tree-view", (element: element) => changeView('tree', element)),
860-
vscode.commands.registerCommand("textmate.list-view", (element: element) => changeView('list', element)),
861+
vscode.commands.registerCommand("textmate.tree-view", (element?: element) => changeView('tree', element)),
862+
vscode.commands.registerCommand("textmate.list-view", (element?: element) => changeView('list', element)),
861863
// vscode.window.onDidChangeActiveColorTheme(updateWorkbench_colorCustomizations),
862864
);
863865

866+
// vscode.window.showInformationMessage(`vscode.commands.getCommands()\n${JSON.stringify(await vscode.commands.getCommands())}`);
864867
// await updateWorkbench_colorCustomizations();
865868

866869
changeView(callView);
@@ -1036,6 +1039,15 @@ async function find(element?: element) {
10361039
// vscode.commands.executeCommand('list.toggleFindMatchType');
10371040
}
10381041

1042+
async function copyToClipBoardGrammar(element?: element) {
1043+
try {
1044+
const grammarJSON = JSON.stringify(grammar, stringify);
1045+
await vscode.env.clipboard.writeText(grammarJSON);
1046+
} catch (error) {
1047+
console.warn("JSON TextMate: CallStack CopyToClipBoard: Error:\n", error);
1048+
}
1049+
}
1050+
10391051
async function callDetails(element: element) {
10401052
// vscode.window.showInformationMessage(`callDetails\n${JSON.stringify(element)}`);
10411053
selectedElement = element;

src/TextMate.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,8 @@ export async function tokenizeFile(document: vscode.TextDocument, runTwice?: boo
302302
// vscode.window.showInformationMessage(JSON.stringify(ruleStack, stringify));
303303
}
304304

305-
try {
306-
// vscode.window.showInformationMessage(JSON.stringify(registry, stringify));
307-
vscode.window.showInformationMessage(JSON.stringify(grammar, stringify));
308-
// vscode.window.showInformationMessage(JSON.stringify(tokenLineResults, stringify));
309-
} catch (error) {
310-
vscode.window.showInformationMessage(JSON.stringify(error));
311-
}
312-
305+
// vscode.window.showInformationMessage(JSON.stringify(registry, stringify));
306+
// vscode.window.showInformationMessage(JSON.stringify(tokenLineResults, stringify));
313307
// return tokenLineResults;
314308
return grammar;
315309
}

0 commit comments

Comments
 (0)