|
2 | 2 | use std::{
|
3 | 3 | collections::HashMap,
|
4 | 4 | fs::File,
|
| 5 | + io::BufReader, |
| 6 | + io::Read, |
5 | 7 | path::{Path, PathBuf},
|
6 | 8 | };
|
7 | 9 |
|
8 | 10 | use quote::quote;
|
9 |
| -use serde::Deserialize; |
10 | 11 | use walkdir::WalkDir;
|
11 | 12 |
|
12 | 13 | use crate::{
|
@@ -65,18 +66,43 @@ fn generate_descriptor(src_dir: PathBuf) -> Result<proc_macro2::TokenStream> {
|
65 | 66 | Ok(ts)
|
66 | 67 | }
|
67 | 68 |
|
68 |
| -#[derive(Deserialize)] |
| 69 | +#[derive(Default)] |
69 | 70 | struct ClippyLint {
|
70 |
| - docs: HashMap<String, String>, |
| 71 | + help: String, |
71 | 72 | id: String,
|
72 | 73 | }
|
73 | 74 |
|
74 | 75 | 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| { |
78 | 104 | 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; |
80 | 106 |
|
81 | 107 | quote! { LintCompletion { label: #lint_ident, description: #doc } }
|
82 | 108 | });
|
|
0 commit comments