From a409a12f1b3c7aa6c09405bf8e28f73b9761fd18 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Oct 2019 19:19:22 +0300 Subject: simplify --- xtask/src/codegen/gen_parser_tests.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index 0f550d948..e6eeb29a1 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -56,16 +56,16 @@ struct Tests { pub err: HashMap, } -fn collect_tests(s: &str) -> Vec<(usize, Test)> { +fn collect_tests(s: &str) -> Vec { let mut res = vec![]; let prefix = "// "; - let lines = s.lines().map(str::trim_start).enumerate(); + let lines = s.lines().map(str::trim_start); let mut block = vec![]; - for (line_idx, line) in lines { + for line in lines { let is_comment = line.starts_with(prefix); if is_comment { - block.push((line_idx, &line[prefix.len()..])); + block.push(&line[prefix.len()..]); } else { process_block(&mut res, &block); block.clear(); @@ -74,29 +74,28 @@ fn collect_tests(s: &str) -> Vec<(usize, Test)> { process_block(&mut res, &block); return res; - fn process_block(acc: &mut Vec<(usize, Test)>, block: &[(usize, &str)]) { + fn process_block(acc: &mut Vec, block: &[&str]) { if block.is_empty() { return; } let mut ok = true; let mut block = block.iter(); - let (start_line, name) = loop { + let name = loop { match block.next() { - Some(&(idx, line)) if line.starts_with("test ") => { - break (idx, line["test ".len()..].to_string()); + Some(line) if line.starts_with("test ") => { + break line["test ".len()..].to_string(); } - Some(&(idx, line)) if line.starts_with("test_err ") => { + Some(line) if line.starts_with("test_err ") => { ok = false; - break (idx, line["test_err ".len()..].to_string()); + break line["test_err ".len()..].to_string(); } Some(_) => (), None => return, } }; - let text: String = - block.map(|(_, line)| *line).chain(std::iter::once("")).collect::>().join("\n"); + let text: String = block.copied().chain(std::iter::once("")).collect::>().join("\n"); assert!(!text.trim().is_empty() && text.ends_with('\n')); - acc.push((start_line, Test { name, text, ok })) + acc.push(Test { name, text, ok }) } } @@ -118,7 +117,7 @@ fn tests_from_dir(dir: &Path) -> Result { fn process_file(res: &mut Tests, path: &Path) -> Result<()> { let text = fs::read_to_string(path)?; - for (_, test) in collect_tests(&text) { + for test in collect_tests(&text) { if test.ok { if let Some(old_test) = res.ok.insert(test.name.clone(), test) { Err(format!("Duplicate test: {}", old_test.name))? -- cgit v1.2.3 From a40d02c9eb1c7226bc7db87b014dc827e77f2a08 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Oct 2019 19:29:38 +0300 Subject: refactor comment extraction from tasks --- xtask/src/codegen.rs | 25 ++++++++++++++- xtask/src/codegen/gen_parser_tests.rs | 58 ++++++++++++----------------------- 2 files changed, 44 insertions(+), 39 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 948b86719..bf3a90119 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -8,7 +8,7 @@ mod gen_syntax; mod gen_parser_tests; -use std::{fs, path::Path}; +use std::{fs, mem, path::Path}; use crate::Result; @@ -44,3 +44,26 @@ pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { fs::write(path, contents)?; Ok(()) } + +fn extract_comment_blocks(text: &str) -> Vec> { + let mut res = Vec::new(); + + let prefix = "// "; + let lines = text.lines().map(str::trim_start); + + let mut block = vec![]; + for line in lines { + let is_comment = line.starts_with(prefix); + if is_comment { + block.push(line[prefix.len()..].to_string()); + } else { + if !block.is_empty() { + res.push(mem::replace(&mut block, Vec::new())) + } + } + } + if !block.is_empty() { + res.push(mem::replace(&mut block, Vec::new())) + } + res +} diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index e6eeb29a1..db1e59dac 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -3,12 +3,12 @@ use std::{ collections::HashMap, - fs, + fs, iter, path::{Path, PathBuf}, }; use crate::{ - codegen::{self, update, Mode}, + codegen::{self, extract_comment_blocks, update, Mode}, project_root, Result, }; @@ -57,46 +57,28 @@ struct Tests { } fn collect_tests(s: &str) -> Vec { - let mut res = vec![]; - let prefix = "// "; - let lines = s.lines().map(str::trim_start); - - let mut block = vec![]; - for line in lines { - let is_comment = line.starts_with(prefix); - if is_comment { - block.push(&line[prefix.len()..]); + let mut res = Vec::new(); + for comment_block in extract_comment_blocks(s) { + let first_line = &comment_block[0]; + let (name, ok) = if first_line.starts_with("test ") { + let name = first_line["test ".len()..].to_string(); + (name, true) + } else if first_line.starts_with("test_err ") { + let name = first_line["test_err ".len()..].to_string(); + (name, false) } else { - process_block(&mut res, &block); - block.clear(); - } - } - process_block(&mut res, &block); - return res; - - fn process_block(acc: &mut Vec, block: &[&str]) { - if block.is_empty() { - return; - } - let mut ok = true; - let mut block = block.iter(); - let name = loop { - match block.next() { - Some(line) if line.starts_with("test ") => { - break line["test ".len()..].to_string(); - } - Some(line) if line.starts_with("test_err ") => { - ok = false; - break line["test_err ".len()..].to_string(); - } - Some(_) => (), - None => return, - } + continue; }; - let text: String = block.copied().chain(std::iter::once("")).collect::>().join("\n"); + let text: String = comment_block[1..] + .iter() + .cloned() + .chain(iter::once(String::new())) + .collect::>() + .join("\n"); assert!(!text.trim().is_empty() && text.ends_with('\n')); - acc.push(Test { name, text, ok }) + res.push(Test { name, text, ok }) } + res } fn tests_from_dir(dir: &Path) -> Result { -- cgit v1.2.3 From 0dd35ff2b2ceffdb926953fdacc7d30e1968047d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 14:16:46 +0300 Subject: auto-generate assists docs and tests --- xtask/src/codegen.rs | 36 ++++++++-- xtask/src/codegen/gen_assists_docs.rs | 123 ++++++++++++++++++++++++++++++++++ xtask/src/codegen/gen_syntax.rs | 25 +------ xtask/src/main.rs | 1 + 4 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 xtask/src/codegen/gen_assists_docs.rs (limited to 'xtask/src') diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index bf3a90119..44729cd57 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -7,12 +7,22 @@ mod gen_syntax; mod gen_parser_tests; +mod gen_assists_docs; -use std::{fs, mem, path::Path}; +use std::{ + fs, + io::Write, + mem, + path::Path, + process::{Command, Stdio}, +}; -use crate::Result; +use crate::{project_root, Result}; -pub use self::{gen_parser_tests::generate_parser_tests, gen_syntax::generate_syntax}; +pub use self::{ + gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests, + gen_syntax::generate_syntax, +}; pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; @@ -22,6 +32,10 @@ const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs"; pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; +const ASSISTS_DIR: &str = "crates/ra_assists/src/assists"; +const ASSISTS_TESTS: &str = "crates/ra_assists/src/doc_tests/generated.rs"; +const ASSISTS_DOCS: &str = "docs/user/assists.md"; + #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum Mode { Overwrite, @@ -30,7 +44,7 @@ pub enum Mode { /// A helper to update file on disk if it has changed. /// With verify = false, -pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { +fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { match fs::read_to_string(path) { Ok(ref old_contents) if old_contents == contents => { return Ok(()); @@ -45,6 +59,20 @@ pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { Ok(()) } +fn reformat(text: impl std::fmt::Display) -> Result { + let mut rustfmt = Command::new("rustfmt") + .arg("--config-path") + .arg(project_root().join("rustfmt.toml")) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + write!(rustfmt.stdin.take().unwrap(), "{}", text)?; + let output = rustfmt.wait_with_output()?; + let stdout = String::from_utf8(output.stdout)?; + let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`"; + Ok(format!("//! {}\n\n{}", preamble, stdout)) +} + fn extract_comment_blocks(text: &str) -> Vec> { let mut res = Vec::new(); diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs new file mode 100644 index 000000000..654ae09d6 --- /dev/null +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -0,0 +1,123 @@ +use std::{fs, path::Path}; + +use crate::{ + codegen::{self, extract_comment_blocks, Mode}, + project_root, Result, +}; + +pub fn generate_assists_docs(mode: Mode) -> Result<()> { + let assists = collect_assists()?; + generate_tests(&assists, mode)?; + generate_docs(&assists, mode)?; + Ok(()) +} + +#[derive(Debug)] +struct Assist { + id: String, + doc: String, + before: String, + after: String, +} + +fn collect_assists() -> Result> { + let mut res = Vec::new(); + for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? { + let entry = entry?; + let path = entry.path(); + if path.is_file() { + collect_file(&mut res, path.as_path())?; + } + } + res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); + return Ok(res); + + fn collect_file(acc: &mut Vec, path: &Path) -> Result<()> { + let text = fs::read_to_string(path)?; + let comment_blocks = extract_comment_blocks(&text); + + for block in comment_blocks { + // FIXME: doesn't support blank lines yet, need to tweak + // `extract_comment_blocks` for that. + let mut lines = block.iter(); + let first_line = lines.next().unwrap(); + if !first_line.starts_with("Assist: ") { + continue; + } + let id = first_line["Assist: ".len()..].to_string(); + assert!(id.chars().all(|it| it.is_ascii_lowercase() || it == '_')); + + let doc = take_until(lines.by_ref(), "```"); + let before = take_until(lines.by_ref(), "```"); + + assert_eq!(lines.next().unwrap().as_str(), "->"); + assert_eq!(lines.next().unwrap().as_str(), "```"); + let after = take_until(lines.by_ref(), "```"); + acc.push(Assist { id, doc, before, after }) + } + + fn take_until<'a>(lines: impl Iterator, marker: &str) -> String { + let mut buf = Vec::new(); + for line in lines { + if line == marker { + break; + } + buf.push(line.clone()); + } + buf.join("\n") + } + Ok(()) + } +} + +fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { + let mut buf = String::from("use super::check;\n"); + + for assist in assists.iter() { + let test = format!( + r######" +#[test] +fn doctest_{}() {{ + check( + "{}", +r#####" +{} +"#####, r#####" +{} +"#####) +}} +"######, + assist.id, assist.id, assist.before, assist.after + ); + + buf.push_str(&test) + } + let buf = codegen::reformat(buf)?; + codegen::update(&project_root().join(codegen::ASSISTS_TESTS), &buf, mode) +} + +fn generate_docs(assists: &[Assist], mode: Mode) -> Result<()> { + let mut buf = String::from("# Assists\n"); + + for assist in assists { + let docs = format!( + " +## `{}` + +{} + +```rust +// BEFORE +{} + +// AFTER +{} +``` +", + assist.id, assist.doc, assist.before, assist.after + ); + buf.push_str(&docs); + } + + codegen::update(&project_root().join(codegen::ASSISTS_DOCS), &buf, mode) +} diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 6a81c0e4d..88f2ac0e3 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -3,12 +3,7 @@ //! Specifically, it generates the `SyntaxKind` enum and a number of newtype //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. -use std::{ - collections::BTreeMap, - fs, - io::Write, - process::{Command, Stdio}, -}; +use std::{collections::BTreeMap, fs}; use proc_macro2::{Punct, Spacing}; use quote::{format_ident, quote}; @@ -163,7 +158,7 @@ fn generate_ast(grammar: &Grammar) -> Result { #(#nodes)* }; - let pretty = reformat(ast)?; + let pretty = codegen::reformat(ast)?; Ok(pretty) } @@ -276,21 +271,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result { } }; - reformat(ast) -} - -fn reformat(text: impl std::fmt::Display) -> Result { - let mut rustfmt = Command::new("rustfmt") - .arg("--config-path") - .arg(project_root().join("rustfmt.toml")) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - write!(rustfmt.stdin.take().unwrap(), "{}", text)?; - let output = rustfmt.wait_with_output()?; - let stdout = String::from_utf8(output.stdout)?; - let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`"; - Ok(format!("//! {}\n\n{}", preamble, stdout)) + codegen::reformat(ast) } #[derive(Deserialize, Debug)] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index db901ced2..06aa3c8ec 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -64,6 +64,7 @@ fn main() -> Result<()> { } codegen::generate_syntax(Mode::Overwrite)?; codegen::generate_parser_tests(Mode::Overwrite)?; + codegen::generate_assists_docs(Mode::Overwrite)?; } "format" => { if matches.contains(["-h", "--help"]) { -- cgit v1.2.3 From d385438bcc8d302fbcb91114e19ac0cc30528822 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 23:38:15 +0300 Subject: generate more assists docs --- xtask/src/codegen.rs | 13 +++++++++++++ xtask/src/codegen/gen_assists_docs.rs | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 44729cd57..4ec8ab75a 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -74,6 +74,14 @@ fn reformat(text: impl std::fmt::Display) -> Result { } fn extract_comment_blocks(text: &str) -> Vec> { + do_extract_comment_blocks(text, false) +} + +fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec> { + do_extract_comment_blocks(text, true) +} + +fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> Vec> { let mut res = Vec::new(); let prefix = "// "; @@ -81,6 +89,11 @@ fn extract_comment_blocks(text: &str) -> Vec> { let mut block = vec![]; for line in lines { + if line == "//" && allow_blocks_with_empty_lins { + block.push(String::new()); + continue; + } + let is_comment = line.starts_with(prefix); if is_comment { block.push(line[prefix.len()..].to_string()); diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 654ae09d6..e313820d1 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -1,7 +1,7 @@ use std::{fs, path::Path}; use crate::{ - codegen::{self, extract_comment_blocks, Mode}, + codegen::{self, extract_comment_blocks_with_empty_lines, Mode}, project_root, Result, }; @@ -34,7 +34,7 @@ fn collect_assists() -> Result> { fn collect_file(acc: &mut Vec, path: &Path) -> Result<()> { let text = fs::read_to_string(path)?; - let comment_blocks = extract_comment_blocks(&text); + let comment_blocks = extract_comment_blocks_with_empty_lines(&text); for block in comment_blocks { // FIXME: doesn't support blank lines yet, need to tweak @@ -45,7 +45,11 @@ fn collect_assists() -> Result> { continue; } let id = first_line["Assist: ".len()..].to_string(); - assert!(id.chars().all(|it| it.is_ascii_lowercase() || it == '_')); + assert!( + id.chars().all(|it| it.is_ascii_lowercase() || it == '_'), + "invalid assist id: {:?}", + id + ); let doc = take_until(lines.by_ref(), "```"); let before = take_until(lines.by_ref(), "```"); -- cgit v1.2.3 From 8e8b6e7f628824d8bf5a50f6b8d445447c000830 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:12:56 +0300 Subject: warn if npm is not found --- xtask/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'xtask/src') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 06aa3c8ec..eb39bf715 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -159,6 +159,17 @@ fn fix_path_for_mac() -> Result<()> { } fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { + let npm_version = Cmd { + unix: r"npm --version", + windows: r"cmd.exe /c npm.cmd --version", + work_dir: "./editors/code", + } + .run(); + + if npm_version.is_err() { + eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin") + } + Cmd { unix: r"npm ci", windows: r"cmd.exe /c npm.cmd ci", work_dir: "./editors/code" }.run()?; Cmd { unix: r"npm run package", -- cgit v1.2.3 From e3a253d80f124f12b5ec3707216590eb5c0dccff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:20:44 +0300 Subject: document tasks module --- xtask/src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 06aa3c8ec..34eb63eb3 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,5 +1,12 @@ -//! FIXME: write short doc here - +//! See https://github.com/matklad/cargo-xtask/. +//! +//! This binary defines various auxiliary build commands, which are not +//! expressible with just `cargo`. Notably, it provides `cargo xtask codegen` +//! for code genetaiont and `cargo xtask install` for installation of +//! rust-analyzer server and client. +//! +//! This binary is integrated into the `cargo` command line by using an alias in +//! `.cargo/config`. mod help; use core::fmt::Write; -- cgit v1.2.3 From 394e4744792f8e36ca1690cb23c2d3dd55556272 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:27:47 +0300 Subject: add blank lines for readability --- xtask/src/codegen/gen_assists_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index e313820d1..2ca7cda63 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -51,7 +51,7 @@ fn collect_assists() -> Result> { id ); - let doc = take_until(lines.by_ref(), "```"); + let doc = take_until(lines.by_ref(), "```").trim().to_string(); let before = take_until(lines.by_ref(), "```"); assert_eq!(lines.next().unwrap().as_str(), "->"); -- cgit v1.2.3 From a5cbd8d5e8aca0d0d8dde175ba13bfa995a753c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 19:08:13 +0300 Subject: check style for assist docs --- xtask/src/codegen/gen_assists_docs.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 2ca7cda63..8dca2ed06 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -52,6 +52,12 @@ fn collect_assists() -> Result> { ); let doc = take_until(lines.by_ref(), "```").trim().to_string(); + assert!( + doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."), + "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", + id, doc, + ); + let before = take_until(lines.by_ref(), "```"); assert_eq!(lines.next().unwrap().as_str(), "->"); -- cgit v1.2.3 From cf4720ffd5524f1ddda411e4810da8d97a0c593f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 21:17:39 +0300 Subject: use unicode bar for drawing the cursor --- xtask/src/codegen/gen_assists_docs.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 8dca2ed06..0c4cf2152 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -107,9 +107,13 @@ r#####" } fn generate_docs(assists: &[Assist], mode: Mode) -> Result<()> { - let mut buf = String::from("# Assists\n"); + let mut buf = String::from( + "# Assists\n\nCursor position or selection is signified by `┃` character.\n\n", + ); for assist in assists { + let before = assist.before.replace("<|>", "┃"); // Unicode pseudo-graphics bar + let after = assist.after.replace("<|>", "┃"); let docs = format!( " ## `{}` @@ -124,7 +128,7 @@ fn generate_docs(assists: &[Assist], mode: Mode) -> Result<()> { {} ``` ", - assist.id, assist.doc, assist.before, assist.after + assist.id, assist.doc, before, after ); buf.push_str(&docs); } -- cgit v1.2.3 From b441b4e8effeaf4532fd2e45c4d864480857c49e Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 13:36:37 -0400 Subject: Some clippy fixes --- xtask/src/codegen/gen_assists_docs.rs | 2 +- xtask/src/codegen/gen_parser_tests.rs | 8 +++----- xtask/src/main.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 0c4cf2152..05afda8f1 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -53,7 +53,7 @@ fn collect_assists() -> Result> { let doc = take_until(lines.by_ref(), "```").trim().to_string(); assert!( - doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."), + doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'), "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", id, doc, ); diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index db1e59dac..d0f0f683b 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -102,12 +102,10 @@ fn tests_from_dir(dir: &Path) -> Result { for test in collect_tests(&text) { if test.ok { if let Some(old_test) = res.ok.insert(test.name.clone(), test) { - Err(format!("Duplicate test: {}", old_test.name))? - } - } else { - if let Some(old_test) = res.err.insert(test.name.clone(), test) { - Err(format!("Duplicate test: {}", old_test.name))? + return Err(format!("Duplicate test: {}", old_test.name).into()); } + } else if let Some(old_test) = res.err.insert(test.name.clone(), test) { + return Err(format!("Duplicate test: {}", old_test.name).into()); } } Ok(()) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 04dca402c..4d20232ff 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -60,7 +60,7 @@ fn main() -> Result<()> { matches.finish().or_else(handle_extra_flags)?; let opts = InstallOpt { client: if server { None } else { Some(ClientOpt::VsCode) }, - server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) }, + server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, }; install(opts)? } -- cgit v1.2.3 From e529c8e3e287b4f70fac0b078fe7ce45394f914c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 20:49:04 +0300 Subject: echo cargo version during install --- xtask/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'xtask/src') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 04dca402c..d88b7ef37 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -229,6 +229,7 @@ fn install_server(opts: ServerOpt) -> Result<()> { let mut old_rust = false; if let Ok(output) = run_with_output("cargo --version", ".") { if let Ok(stdout) = String::from_utf8(output.stdout) { + println!("{}", stdout); if !check_version(&stdout, REQUIRED_RUST_VERSION) { old_rust = true; } -- cgit v1.2.3 From 462c1b49c652b1fb271e6243f3feee13e4ea8880 Mon Sep 17 00:00:00 2001 From: krk Date: Wed, 30 Oct 2019 21:17:27 +0100 Subject: Fix typo in xtask/src/main.rs. --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index abcbf7129..e04e45f15 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -2,7 +2,7 @@ //! //! This binary defines various auxiliary build commands, which are not //! expressible with just `cargo`. Notably, it provides `cargo xtask codegen` -//! for code genetaiont and `cargo xtask install` for installation of +//! for code generation and `cargo xtask install` for installation of //! rust-analyzer server and client. //! //! This binary is integrated into the `cargo` command line by using an alias in -- cgit v1.2.3