aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/package.json24
-rw-r--r--editors/code/ra_syntax_tree.tmGrammar.json31
-rw-r--r--editors/code/src/commands/syntax_tree.ts11
3 files changed, 63 insertions, 3 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 146b696e9..1d90e4298 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -411,6 +411,21 @@
411 ] 411 ]
412 } 412 }
413 ], 413 ],
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 ],
414 "problemMatchers": [ 429 "problemMatchers": [
415 { 430 {
416 "name": "rustc", 431 "name": "rustc",
@@ -450,6 +465,15 @@
450 "light": "#747474", 465 "light": "#747474",
451 "highContrast": "#BEBEBE" 466 "highContrast": "#BEBEBE"
452 } 467 }
468 },
469 {
470 "id": "rust_analyzer.syntaxTreeBorder",
471 "description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)",
472 "defaults": {
473 "dark": "#ffffff",
474 "light": "#b700ff",
475 "highContrast": "#b700ff"
476 }
453 } 477 }
454 ], 478 ],
455 "semanticTokenTypes": [ 479 "semanticTokenTypes": [
diff --git a/editors/code/ra_syntax_tree.tmGrammar.json b/editors/code/ra_syntax_tree.tmGrammar.json
new file mode 100644
index 000000000..0d72a3e36
--- /dev/null
+++ b/editors/code/ra_syntax_tree.tmGrammar.json
@@ -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}
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts
index 996c7a716..8d71cb39e 100644
--- a/editors/code/src/commands/syntax_tree.ts
+++ b/editors/code/src/commands/syntax_tree.ts
@@ -15,6 +15,9 @@ export function syntaxTree(ctx: Ctx): Cmd {
15 void new AstInspector(ctx); 15 void new AstInspector(ctx);
16 16
17 ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp)); 17 ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider(AST_FILE_SCHEME, tdcp));
18 ctx.pushCleanup(vscode.languages.setLanguageConfiguration("ra_syntax_tree", {
19 brackets: [["[", ")"]],
20 }));
18 21
19 return async () => { 22 return async () => {
20 const editor = vscode.window.activeTextEditor; 23 const editor = vscode.window.activeTextEditor;
@@ -36,7 +39,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
36} 39}
37 40
38class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { 41class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
39 readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); 42 readonly uri = vscode.Uri.parse('rust-analyzer://syntaxtree/tree.rast');
40 readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 43 readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
41 44
42 45
@@ -81,8 +84,10 @@ class TextDocumentContentProvider implements vscode.TextDocumentContentProvider
81// https://code.visualstudio.com/api/extension-guides/tree-view 84// https://code.visualstudio.com/api/extension-guides/tree-view
82class AstInspector implements vscode.HoverProvider, Disposable { 85class AstInspector implements vscode.HoverProvider, Disposable {
83 private static readonly astDecorationType = vscode.window.createTextEditorDecorationType({ 86 private static readonly astDecorationType = vscode.window.createTextEditorDecorationType({
84 fontStyle: "normal", 87 borderColor: new vscode.ThemeColor('rust_analyzer.syntaxTreeBorder'),
85 border: "#ffffff 1px solid", 88 borderStyle: "solid",
89 borderWidth: "2px",
90
86 }); 91 });
87 private rustEditor: undefined | RustEditor; 92 private rustEditor: undefined | RustEditor;
88 93