Skip to content

Commit 9436ac2

Browse files
authored
Merge pull request #784 from ribru17/clip_emmylua_ls
Address the rest of the clippy lints
2 parents 7f4830f + 120541b commit 9436ac2

File tree

110 files changed

+1172
-1398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1172
-1398
lines changed

crates/emmylua_check/src/init.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use emmylua_code_analysis::{
33
};
44
use fern::Dispatch;
55
use log::LevelFilter;
6-
use std::{path::PathBuf, str::FromStr};
6+
use std::{
7+
path::{Path, PathBuf},
8+
str::FromStr,
9+
};
710

8-
fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
11+
fn root_from_configs(config_paths: &[PathBuf], fallback: &Path) -> PathBuf {
912
if config_paths.len() != 1 {
10-
fallback.clone()
13+
fallback.to_path_buf()
1114
} else {
1215
let config_path = &config_paths[0];
1316
// Need to convert to canonical path to ensure parent() is not an empty
@@ -20,7 +23,7 @@ fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf
2023
config_path,
2124
err
2225
);
23-
fallback.clone()
26+
fallback.to_path_buf()
2427
}
2528
}
2629
}

crates/emmylua_code_style/src/bin/emmylua_format.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ fn main() {
134134
}
135135
}
136136
} else if args.write {
137-
if changed {
138-
if let Err(e) = fs::write(path, formatted) {
139-
eprintln!("Failed to write {}: {e}", path.to_string_lossy());
140-
exit_code = 2;
141-
}
137+
if changed && let Err(e) = fs::write(path, formatted) {
138+
eprintln!("Failed to write {}: {e}", path.to_string_lossy());
139+
exit_code = 2;
142140
}
143141
} else if let Some(out) = &args.output {
144142
if let Err(e) = fs::write(out, formatted) {

crates/emmylua_code_style/src/test/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(clippy::module_inception)]
12
#[cfg(test)]
23
mod test {
34
use crate::{reformat_lua_code, styles::LuaCodeStyle};

crates/emmylua_doc_cli/src/init.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ use emmylua_code_analysis::{
33
};
44
use fern::Dispatch;
55
use log::LevelFilter;
6-
use std::{path::PathBuf, str::FromStr, sync::Arc};
6+
use std::{
7+
path::{Path, PathBuf},
8+
str::FromStr,
9+
sync::Arc,
10+
};
711

8-
fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
12+
fn root_from_configs(config_paths: &[PathBuf], fallback: &Path) -> PathBuf {
913
if config_paths.len() != 1 {
10-
fallback.clone()
14+
fallback.to_path_buf()
1115
} else {
1216
let config_path = &config_paths[0];
1317
// Need to convert to canonical path to ensure parent() is not an empty
@@ -20,7 +24,7 @@ fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf
2024
config_path,
2125
err
2226
);
23-
fallback.clone()
27+
fallback.to_path_buf()
2428
}
2529
}
2630
}

crates/emmylua_doc_cli/src/markdown_generator/generator/index_gen.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ use tera::Tera;
22

33
use crate::markdown_generator::markdown_types::MkdocsIndex;
44

5-
pub fn generate_index(
6-
tl: &Tera,
7-
mkdocs: &mut MkdocsIndex,
8-
output: &std::path::PathBuf,
9-
) -> Option<()> {
5+
pub fn generate_index(tl: &Tera, mkdocs: &mut MkdocsIndex, output: &std::path::Path) -> Option<()> {
106
let mut context = tera::Context::new();
117
mkdocs.types.sort_by(|a, b| a.name.cmp(&b.name));
128
mkdocs.modules.sort_by(|a, b| a.name.cmp(&b.name));

crates/emmylua_doc_cli/src/markdown_generator/generator/mod_gen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ pub fn generate_module_markdown(
2525
check_filter(db, module.file_id)?;
2626

2727
let mut context = tera::Context::new();
28-
let mut doc = Doc::default();
29-
doc.name = module.full_module_name.clone();
28+
let mut doc = Doc {
29+
name: module.full_module_name.clone(),
30+
..Default::default()
31+
};
3032
let property_owner_id = module.semantic_id.clone();
3133
if let Some(property_id) = property_owner_id {
3234
doc.property = collect_property(db, property_id);

crates/emmylua_doc_cli/src/markdown_generator/generator/typ_gen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ pub fn generate_type_markdown(
2323
check_filter(db, typ)?;
2424
let mut context = tera::Context::new();
2525
let typ_name = typ.get_name();
26-
let mut doc = Doc::default();
27-
doc.name = typ_name.to_string();
26+
let mut doc = Doc {
27+
name: typ_name.to_string(),
28+
..Default::default()
29+
};
2830

2931
if typ.is_class() {
3032
generate_class_type_markdown(db, tl, typ, &mut doc, &mut context, output, mkdocs_index);

crates/emmylua_ls/src/context/client_id.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
use lsp_types::ClientInfo;
22

3-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
44
pub enum ClientId {
55
VSCode,
66
Intellij,
77
Neovim,
8+
#[default]
89
Other,
910
}
1011

11-
impl Default for ClientId {
12-
fn default() -> Self {
13-
ClientId::Other
14-
}
15-
}
16-
1712
#[allow(unused)]
1813
impl ClientId {
1914
pub fn is_vscode(&self) -> bool {
@@ -56,10 +51,7 @@ fn check_vscode(client_info: &ClientInfo) -> bool {
5651
return true;
5752
}
5853

59-
match name.as_str() {
60-
"Cursor" | "Windsurf" | "Trae" | "Qoder" => true,
61-
_ => false,
62-
}
54+
matches!(name.as_str(), "Cursor" | "Windsurf" | "Trae" | "Qoder")
6355
}
6456

6557
fn check_lsp4ij(client_info: &ClientInfo) -> bool {

crates/emmylua_ls/src/context/file_diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ impl FileDiagnostic {
4040

4141
// create new token
4242
let cancel_token = CancellationToken::new();
43-
tokens.insert(file_id.clone(), cancel_token.clone());
43+
tokens.insert(file_id, cancel_token.clone());
4444
drop(tokens); // free the lock
4545

4646
let analysis = self.analysis.clone();
4747
let client = self.client.clone();
4848
let diagnostic_tokens = self.diagnostic_tokens.clone();
49-
let file_id_clone = file_id.clone();
49+
let file_id_clone = file_id;
5050

5151
// Spawn a new task to perform diagnostic
5252
tokio::spawn(async move {
@@ -177,7 +177,7 @@ async fn workspace_diagnostic(
177177
let mut count = 0;
178178
if valid_file_count != 0 {
179179
if silent {
180-
while let Some(_) = rx.recv().await {
180+
while (rx.recv().await).is_some() {
181181
count += 1;
182182
if count == valid_file_count {
183183
break;
@@ -187,7 +187,7 @@ async fn workspace_diagnostic(
187187
let text = format!("diagnose {} files", valid_file_count);
188188
let _p = Profile::new(text.as_str());
189189
let mut last_percentage = 0;
190-
while let Some(_) = rx.recv().await {
190+
while (rx.recv().await).is_some() {
191191
count += 1;
192192
let percentage_done = ((count as f32 / valid_file_count as f32) * 100.0) as u32;
193193
if last_percentage != percentage_done {

crates/emmylua_ls/src/context/status_bar.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use lsp_types::{
44
NumberOrString, ProgressParams, ProgressParamsValue, WorkDoneProgress, WorkDoneProgressBegin,
55
WorkDoneProgressCreateParams, WorkDoneProgressEnd, WorkDoneProgressReport,
66
};
7-
use serde::{Deserialize, Serialize};
87

98
use crate::util::time_cancel_token;
109

@@ -104,16 +103,3 @@ impl StatusBar {
104103
)
105104
}
106105
}
107-
108-
#[derive(Debug, Clone, Serialize, Deserialize)]
109-
pub struct EmmyServerStatus {
110-
health: String,
111-
loading: bool,
112-
message: String,
113-
}
114-
115-
#[derive(Debug, Clone, Serialize, Deserialize)]
116-
pub struct EmmyProgress {
117-
text: String,
118-
percent: f64,
119-
}

0 commit comments

Comments
 (0)