Skip to content

Commit 17acefd

Browse files
committed
remove serde from deps
Signed-off-by: Benjamin Coenen <[email protected]>
1 parent 6e7a97b commit 17acefd

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

Cargo.lock

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/src/completion/generated_lint_completions.rs

+1-1
Large diffs are not rendered by default.

xtask/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ ungrammar = "1.1.3"
1919
walkdir = "2.3.1"
2020
write-json = "0.1.0"
2121
fs-err = "2.3"
22-
serde = { version = "1.0", features = ["derive"] }
23-
serde_json = "1.0"
2422
# Avoid adding more dependencies to this crate

xtask/src/codegen/gen_lint_completions.rs

+33-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
use std::{
33
collections::HashMap,
44
fs::File,
5+
io::BufReader,
6+
io::Read,
57
path::{Path, PathBuf},
68
};
79

810
use quote::quote;
9-
use serde::Deserialize;
1011
use walkdir::WalkDir;
1112

1213
use crate::{
@@ -65,18 +66,43 @@ fn generate_descriptor(src_dir: PathBuf) -> Result<proc_macro2::TokenStream> {
6566
Ok(ts)
6667
}
6768

68-
#[derive(Deserialize)]
69+
#[derive(Default)]
6970
struct ClippyLint {
70-
docs: HashMap<String, String>,
71+
help: String,
7172
id: String,
7273
}
7374

7475
fn generate_descriptor_clippy(uri: &str) -> Result<proc_macro2::TokenStream> {
75-
let file = File::open(uri)?;
76-
let clippy_lints: Vec<ClippyLint> = serde_json::from_reader(file)?;
77-
let definitions = clippy_lints.into_iter().map(|mut clippy_lint| {
76+
let mut file = File::open(uri)?;
77+
let mut file_content = String::new();
78+
file.read_to_string(&mut file_content)?;
79+
let mut clippy_lints: Vec<ClippyLint> = vec![];
80+
81+
for line in file_content.lines().map(|line| line.trim()) {
82+
if line.starts_with(r#""id":"#) {
83+
let clippy_lint = ClippyLint {
84+
id: line
85+
.strip_prefix(r#""id": ""#)
86+
.expect("should be prefixed by id")
87+
.strip_suffix(r#"","#)
88+
.expect("should be suffixed by comma")
89+
.into(),
90+
help: String::new(),
91+
};
92+
clippy_lints.push(clippy_lint)
93+
} else if line.starts_with(r#""What it does":"#) {
94+
clippy_lints.last_mut().expect("clippy lint must already exist").help = line
95+
.strip_prefix(r#""What it does": ""#)
96+
.expect("should be prefixed by what it does")
97+
.strip_suffix(r#"","#)
98+
.expect("should be suffixed by comma")
99+
.into();
100+
}
101+
}
102+
103+
let definitions = clippy_lints.into_iter().map(|clippy_lint| {
78104
let lint_ident = format!("clippy::{}", clippy_lint.id);
79-
let doc = clippy_lint.docs.remove("What it does").unwrap_or_default();
105+
let doc = clippy_lint.help;
80106

81107
quote! { LintCompletion { label: #lint_ident, description: #doc } }
82108
});

0 commit comments

Comments
 (0)