diff options
author | Galilée 'Bill' Enguehard <[email protected]> | 2020-05-21 22:27:38 +0100 |
---|---|---|
committer | Galilée 'Bill' Enguehard <[email protected]> | 2020-05-21 22:27:38 +0100 |
commit | 7fece3bdd2450c0807f7dd742239cae95f0cc65e (patch) | |
tree | 866c4db826c959e79c63a6727bdb9f2c61e6fc4f /xtask/src/codegen | |
parent | db926218b2082077750291f8426ddd28b284cd08 (diff) | |
parent | 59732df8d40dfadc6dcf5951265416576399712a (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into modname_spacing
Diffstat (limited to 'xtask/src/codegen')
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 4 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 26 |
2 files changed, 26 insertions, 4 deletions
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 31d606535..4bd6b5f0c 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -101,14 +101,14 @@ fn collect_assists() -> Result<Vec<Assist>> { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { | 103 | fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { |
104 | let mut buf = String::from("use super::check;\n"); | 104 | let mut buf = String::from("use super::check_doc_test;\n"); |
105 | 105 | ||
106 | for assist in assists.iter() { | 106 | for assist in assists.iter() { |
107 | let test = format!( | 107 | let test = format!( |
108 | r######" | 108 | r######" |
109 | #[test] | 109 | #[test] |
110 | fn doctest_{}() {{ | 110 | fn doctest_{}() {{ |
111 | check( | 111 | check_doc_test( |
112 | "{}", | 112 | "{}", |
113 | r#####" | 113 | r#####" |
114 | {}"#####, r#####" | 114 | {}"#####, r#####" |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index e9dc09552..19d5594f5 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype | 3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype |
4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. | 4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. |
5 | 5 | ||
6 | use std::collections::HashSet; | 6 | use std::{collections::HashSet, fmt::Write}; |
7 | 7 | ||
8 | use proc_macro2::{Punct, Spacing}; | 8 | use proc_macro2::{Punct, Spacing}; |
9 | use quote::{format_ident, quote}; | 9 | use quote::{format_ident, quote}; |
@@ -102,6 +102,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
102 | }); | 102 | }); |
103 | ( | 103 | ( |
104 | quote! { | 104 | quote! { |
105 | #[pretty_doc_comment_placeholder_workaround] | ||
105 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 106 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
106 | pub struct #name { | 107 | pub struct #name { |
107 | pub(crate) syntax: SyntaxNode, | 108 | pub(crate) syntax: SyntaxNode, |
@@ -145,6 +146,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
145 | 146 | ||
146 | ( | 147 | ( |
147 | quote! { | 148 | quote! { |
149 | #[pretty_doc_comment_placeholder_workaround] | ||
148 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 150 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
149 | pub enum #name { | 151 | pub enum #name { |
150 | #(#variants(#variants),)* | 152 | #(#variants(#variants),)* |
@@ -230,10 +232,29 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
230 | }; | 232 | }; |
231 | 233 | ||
232 | let ast = ast.to_string().replace("T ! [ ", "T![").replace(" ] )", "])"); | 234 | let ast = ast.to_string().replace("T ! [ ", "T![").replace(" ] )", "])"); |
233 | let pretty = crate::reformat(ast)?.replace("#[derive", "\n#[derive"); | 235 | |
236 | let mut res = String::with_capacity(ast.len() * 2); | ||
237 | |||
238 | let mut docs = | ||
239 | grammar.nodes.iter().map(|it| it.doc).chain(grammar.enums.iter().map(|it| it.doc)); | ||
240 | |||
241 | for chunk in ast.split("# [ pretty_doc_comment_placeholder_workaround ]") { | ||
242 | res.push_str(chunk); | ||
243 | if let Some(doc) = docs.next() { | ||
244 | write_doc_comment(doc, &mut res); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | let pretty = crate::reformat(res)?; | ||
234 | Ok(pretty) | 249 | Ok(pretty) |
235 | } | 250 | } |
236 | 251 | ||
252 | fn write_doc_comment(contents: &[&str], dest: &mut String) { | ||
253 | for line in contents { | ||
254 | writeln!(dest, "///{}", line).unwrap(); | ||
255 | } | ||
256 | } | ||
257 | |||
237 | fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> { | 258 | fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> { |
238 | let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar | 259 | let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar |
239 | .punct | 260 | .punct |
@@ -432,6 +453,7 @@ impl Field<'_> { | |||
432 | ":" => "colon", | 453 | ":" => "colon", |
433 | "::" => "coloncolon", | 454 | "::" => "coloncolon", |
434 | "#" => "pound", | 455 | "#" => "pound", |
456 | "?" => "question_mark", | ||
435 | _ => name, | 457 | _ => name, |
436 | }; | 458 | }; |
437 | format_ident!("{}_token", name) | 459 | format_ident!("{}_token", name) |