diff options
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 9 | ||||
-rw-r--r-- | editors/code/package.json | 24 | ||||
-rw-r--r-- | editors/code/ra_syntax_tree.tmGrammar.json | 31 | ||||
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 11 |
4 files changed, 68 insertions, 7 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index c1b6e1ddc..b50cda06f 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -75,7 +75,7 @@ pub type Target = Idx<TargetData>; | |||
75 | 75 | ||
76 | #[derive(Debug, Clone)] | 76 | #[derive(Debug, Clone)] |
77 | pub struct PackageData { | 77 | pub struct PackageData { |
78 | pub id: String, | 78 | pub version: String, |
79 | pub name: String, | 79 | pub name: String, |
80 | pub manifest: PathBuf, | 80 | pub manifest: PathBuf, |
81 | pub targets: Vec<Target>, | 81 | pub targets: Vec<Target>, |
@@ -174,14 +174,15 @@ impl CargoWorkspace { | |||
174 | let ws_members = &meta.workspace_members; | 174 | let ws_members = &meta.workspace_members; |
175 | 175 | ||
176 | for meta_pkg in meta.packages { | 176 | for meta_pkg in meta.packages { |
177 | let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg; | 177 | let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } = |
178 | meta_pkg; | ||
178 | let is_member = ws_members.contains(&id); | 179 | let is_member = ws_members.contains(&id); |
179 | let edition = edition | 180 | let edition = edition |
180 | .parse::<Edition>() | 181 | .parse::<Edition>() |
181 | .with_context(|| format!("Failed to parse edition {}", edition))?; | 182 | .with_context(|| format!("Failed to parse edition {}", edition))?; |
182 | let pkg = packages.alloc(PackageData { | 183 | let pkg = packages.alloc(PackageData { |
183 | name, | 184 | name, |
184 | id: id.to_string(), | 185 | version: version.to_string(), |
185 | manifest: manifest_path, | 186 | manifest: manifest_path, |
186 | targets: Vec::new(), | 187 | targets: Vec::new(), |
187 | is_member, | 188 | is_member, |
@@ -256,7 +257,7 @@ impl CargoWorkspace { | |||
256 | if self.is_unique(&*package.name) { | 257 | if self.is_unique(&*package.name) { |
257 | package.name.clone() | 258 | package.name.clone() |
258 | } else { | 259 | } else { |
259 | package.id.clone() | 260 | format!("{}:{}", package.name, package.version) |
260 | } | 261 | } |
261 | } | 262 | } |
262 | 263 | ||
diff --git a/editors/code/package.json b/editors/code/package.json index 9f98ab736..946145df8 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -401,6 +401,21 @@ | |||
401 | ] | 401 | ] |
402 | } | 402 | } |
403 | ], | 403 | ], |
404 | "languages": [ | ||
405 | { | ||
406 | "id": "ra_syntax_tree", | ||
407 | "extensions": [ | ||
408 | ".rast" | ||
409 | ] | ||
410 | } | ||
411 | ], | ||
412 | "grammars": [ | ||
413 | { | ||
414 | "language": "ra_syntax_tree", | ||
415 | "scopeName": "source.ra_syntax_tree", | ||
416 | "path": "ra_syntax_tree.tmGrammar.json" | ||
417 | } | ||
418 | ], | ||
404 | "problemMatchers": [ | 419 | "problemMatchers": [ |
405 | { | 420 | { |
406 | "name": "rustc", | 421 | "name": "rustc", |
@@ -440,6 +455,15 @@ | |||
440 | "light": "#747474", | 455 | "light": "#747474", |
441 | "highContrast": "#BEBEBE" | 456 | "highContrast": "#BEBEBE" |
442 | } | 457 | } |
458 | }, | ||
459 | { | ||
460 | "id": "rust_analyzer.syntaxTreeBorder", | ||
461 | "description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)", | ||
462 | "defaults": { | ||
463 | "dark": "#ffffff", | ||
464 | "light": "#b700ff", | ||
465 | "highContrast": "#b700ff" | ||
466 | } | ||
443 | } | 467 | } |
444 | ], | 468 | ], |
445 | "semanticTokenTypes": [ | 469 | "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 | ||
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 | ||
@@ -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 |
82 | class AstInspector implements vscode.HoverProvider, Disposable { | 85 | class 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 | ||