Skip to content

Commit 62ed01a

Browse files
committed
vscode: add highlighting of syntax tree
1 parent f696df3 commit 62ed01a

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

editors/code/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@
411411
]
412412
}
413413
],
414+
"languages": [
415+
{
416+
"id": "ra_syntax_tree",
417+
"extensions": [
418+
".rast"
419+
]
420+
}
421+
],
422+
"grammars": [
423+
{
424+
"language": "ra_syntax_tree",
425+
"scopeName": "source.ra_syntax_tree",
426+
"path": "ra_syntax_tree.tmGrammar.json"
427+
}
428+
],
414429
"problemMatchers": [
415430
{
416431
"name": "rustc",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
4+
"scopeName": "source.ra_syntax_tree",
5+
"patterns": [
6+
{ "include": "#node_type" },
7+
{ "include": "#node_range_index" },
8+
{ "include": "#token_text" }
9+
],
10+
"repository": {
11+
"node_type": {
12+
"match": "^\\s*([A-Z_]+?)@",
13+
"captures": {
14+
"1": {
15+
"name": "entity.name.class"
16+
}
17+
}
18+
},
19+
"node_range_index": {
20+
"match": "\\d+",
21+
"name": "constant.numeric"
22+
},
23+
"token_text": {
24+
"match": "\".+\"",
25+
"name": "string"
26+
}
27+
},
28+
"fileTypes": [
29+
"rast"
30+
]
31+
}

editors/code/src/commands/syntax_tree.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export function syntaxTree(ctx: Ctx): Cmd {
1515
void new AstInspector(ctx);
1616

1717
ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp));
18+
ctx.pushCleanup(vscode.languages.setLanguageConfiguration("ra_syntax_tree", {
19+
brackets: [["[", ")"]],
20+
}));
1821

1922
return async () => {
2023
const editor = vscode.window.activeTextEditor;
@@ -36,7 +39,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
3639
}
3740

3841
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
39-
readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
42+
readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree/tree.rast');
4043
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
4144

4245

0 commit comments

Comments
 (0)