diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-02 08:32:14 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-02 08:32:14 +0100 |
commit | f0ba01cd43489f0029e90fa7857c88b4e31f9996 (patch) | |
tree | 67cfd74fa8cadca05c5ddfe436aa2640f80fef86 | |
parent | 93f21ac624815dc58ea367eb4127526564206e84 (diff) | |
parent | 62ed01a1078f499c93c70025342dd869bd277d39 (diff) |
Merge #3817
3817: vscode: highlight syntax tree ro editor r=matklad a=Veetaha
Small textmate grammar declaration to make rust-analyzer syntax tree more easily inspectable:
Btw, if we change the file extension of our `ra_syntax/test_data/**` files to `.rast` they should be highlighted in vscode too.
The colors of the tokens are actually going to be color-theme dependent, or you can customize them via:
```jsonc
{
"editor.tokenColorCustomizations": {
"textMateRules": [ { "scope": "name", "settings": { /* */ } } ]
}
}
```
![image](https://user-images.githubusercontent.com/36276403/78204947-99f9d600-74a3-11ea-8315-cb1c87810c7c.png)
Related: #3682
Co-authored-by: veetaha <[email protected]>
-rw-r--r-- | editors/code/package.json | 15 | ||||
-rw-r--r-- | editors/code/ra_syntax_tree.tmGrammar.json | 31 | ||||
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 5 |
3 files changed, 50 insertions, 1 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index cf74c6775..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", |
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 ad9878617..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 | ||
38 | class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { | 41 | 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'); |
40 | readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); | 43 | readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); |
41 | 44 | ||
42 | 45 | ||