Skip to content

Commit 37cdee0

Browse files
committed
feat: CallStack: add reload grammars from disk #10
1 parent 54dd8ab commit 37cdee0

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@
500500
"group": "navigation@0",
501501
"when": "view == TextMate"
502502
},
503+
{
504+
"command": "textmate.reload.grammars",
505+
"group": "navigation@1",
506+
"when": "view == TextMate"
507+
},
503508
{
504509
"command": "textmate.tree-view",
505510
"group": "navigation@2",
@@ -588,6 +593,12 @@
588593
"category": "TextMate",
589594
"icon": "$(refresh)"
590595
},
596+
{
597+
"command": "textmate.reload.grammars",
598+
"title": "Reload Grammars from Disk",
599+
"category": "TextMate",
600+
"icon": "$(sync)"
601+
},
591602
{
592603
"command": "textmate.follow.cursor",
593604
"title": "Follow Cursor",

src/Providers/TreeDataProvider.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import * as vscodeOniguruma from 'vscode-oniguruma';
33
// import * as vscodeTextmate from 'vscode-textmate';
44
import { stringify } from "../extension";
5-
import { getScopeName, grammarLanguages, tokenizeFile } from "../TextMate";
5+
import { getScopeName, grammarLanguages, initTextMate, tokenizeFile } from "../TextMate";
66
import { getTrees, queryNode, toRange } from "../TreeSitter";
77
import { IGrammar, IMatchResult, IToken, RegExpSource, RuleId, endRuleId, whileRuleId } from "../ITextMate";
88
import { IRawGrammar } from "../textmate/main";
@@ -854,6 +854,7 @@ export function initCallStackView(context: vscode.ExtensionContext): void {
854854
context.subscriptions.push(
855855
vscode.commands.registerTextEditorCommand("textmate.callstack", CallStackView),
856856
vscode.commands.registerCommand("textmate.refresh", refresh),
857+
vscode.commands.registerCommand("textmate.reload.grammars", reloadGrammars),
857858
vscode.commands.registerCommand("textmate.find", find),
858859
vscode.commands.registerCommand("textmate.copytoclipboard.grammar", copyGrammarToClipBoard),
859860
vscode.commands.registerCommand("textmate.call.details", callDetails),
@@ -1033,6 +1034,14 @@ async function refresh(element?: element) {
10331034
onDidChangeTreeDataCall.fire(undefined);
10341035
}
10351036

1037+
async function reloadGrammars(element?: element) {
1038+
// vscode.window.showInformationMessage(`reloadGrammars\n${JSON.stringify(element)}`);
1039+
1040+
initTextMate();
1041+
1042+
onDidChangeTreeData.fire(undefined);
1043+
}
1044+
10361045
async function find(element?: element) {
10371046
// vscode.window.showInformationMessage(`find\n${JSON.stringify(element)}`);
10381047
await treeView.reveal(undefined, { focus: true });

src/TextMate.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const grammarLanguages: {
3636
};
3737

3838
function parseExtensions() {
39+
grammarLanguages.languageId = {};
40+
grammarLanguages.scopeName = {};
41+
3942
for (const extension of vscode.extensions.all as IRelaxedExtension[]) {
4043
// if (extension?.isActive === false) {
4144
// continue;
@@ -181,10 +184,10 @@ async function onigLibInterface(): vscodeTextmate.RegistryOptions['onigLib'] {
181184
}
182185

183186
let registry: vscodeTextmate.Registry;
184-
export function initTextMate(context: vscode.ExtensionContext) {
187+
export function initTextMate(context?: vscode.ExtensionContext) {
185188
parseExtensions();
186189

187-
context.subscriptions.push(vscode.extensions.onDidChange(parseExtensions));
190+
context?.subscriptions.push(vscode.extensions.onDidChange(parseExtensions));
188191

189192
// https://vscode.dev/github/microsoft/vscode/blob/main/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts#L27
190193
const options: vscodeTextmate.RegistryOptions = {

0 commit comments

Comments
 (0)