Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/emmylua_check/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use emmylua_code_analysis::{
};
use fern::Dispatch;
use log::LevelFilter;
use std::{path::PathBuf, str::FromStr};
use std::{
path::{Path, PathBuf},
str::FromStr,
};

fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
fn root_from_configs(config_paths: &[PathBuf], fallback: &Path) -> PathBuf {
if config_paths.len() != 1 {
fallback.clone()
fallback.to_path_buf()
} else {
let config_path = &config_paths[0];
// Need to convert to canonical path to ensure parent() is not an empty
Expand All @@ -20,7 +23,7 @@ fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf
config_path,
err
);
fallback.clone()
fallback.to_path_buf()
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions crates/emmylua_code_style/src/bin/emmylua_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ fn main() {
}
}
} else if args.write {
if changed {
if let Err(e) = fs::write(path, formatted) {
eprintln!("Failed to write {}: {e}", path.to_string_lossy());
exit_code = 2;
}
if changed && let Err(e) = fs::write(path, formatted) {
eprintln!("Failed to write {}: {e}", path.to_string_lossy());
exit_code = 2;
}
} else if let Some(out) = &args.output {
if let Err(e) = fs::write(out, formatted) {
Expand Down
1 change: 1 addition & 0 deletions crates/emmylua_code_style/src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
#[cfg(test)]
mod test {
use crate::{reformat_lua_code, styles::LuaCodeStyle};
Expand Down
12 changes: 8 additions & 4 deletions crates/emmylua_doc_cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ use emmylua_code_analysis::{
};
use fern::Dispatch;
use log::LevelFilter;
use std::{path::PathBuf, str::FromStr, sync::Arc};
use std::{
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};

fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
fn root_from_configs(config_paths: &[PathBuf], fallback: &Path) -> PathBuf {
if config_paths.len() != 1 {
fallback.clone()
fallback.to_path_buf()
} else {
let config_path = &config_paths[0];
// Need to convert to canonical path to ensure parent() is not an empty
Expand All @@ -20,7 +24,7 @@ fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf
config_path,
err
);
fallback.clone()
fallback.to_path_buf()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use tera::Tera;

use crate::markdown_generator::markdown_types::MkdocsIndex;

pub fn generate_index(
tl: &Tera,
mkdocs: &mut MkdocsIndex,
output: &std::path::PathBuf,
) -> Option<()> {
pub fn generate_index(tl: &Tera, mkdocs: &mut MkdocsIndex, output: &std::path::Path) -> Option<()> {
let mut context = tera::Context::new();
mkdocs.types.sort_by(|a, b| a.name.cmp(&b.name));
mkdocs.modules.sort_by(|a, b| a.name.cmp(&b.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ pub fn generate_module_markdown(
check_filter(db, module.file_id)?;

let mut context = tera::Context::new();
let mut doc = Doc::default();
doc.name = module.full_module_name.clone();
let mut doc = Doc {
name: module.full_module_name.clone(),
..Default::default()
};
let property_owner_id = module.semantic_id.clone();
if let Some(property_id) = property_owner_id {
doc.property = collect_property(db, property_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ pub fn generate_type_markdown(
check_filter(db, typ)?;
let mut context = tera::Context::new();
let typ_name = typ.get_name();
let mut doc = Doc::default();
doc.name = typ_name.to_string();
let mut doc = Doc {
name: typ_name.to_string(),
..Default::default()
};

if typ.is_class() {
generate_class_type_markdown(db, tl, typ, &mut doc, &mut context, output, mkdocs_index);
Expand Down
14 changes: 3 additions & 11 deletions crates/emmylua_ls/src/context/client_id.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use lsp_types::ClientInfo;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ClientId {
VSCode,
Intellij,
Neovim,
#[default]
Other,
}

impl Default for ClientId {
fn default() -> Self {
ClientId::Other
}
}

#[allow(unused)]
impl ClientId {
pub fn is_vscode(&self) -> bool {
Expand Down Expand Up @@ -56,10 +51,7 @@ fn check_vscode(client_info: &ClientInfo) -> bool {
return true;
}

match name.as_str() {
"Cursor" | "Windsurf" | "Trae" | "Qoder" => true,
_ => false,
}
matches!(name.as_str(), "Cursor" | "Windsurf" | "Trae" | "Qoder")
}

fn check_lsp4ij(client_info: &ClientInfo) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions crates/emmylua_ls/src/context/file_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ impl FileDiagnostic {

// create new token
let cancel_token = CancellationToken::new();
tokens.insert(file_id.clone(), cancel_token.clone());
tokens.insert(file_id, cancel_token.clone());
drop(tokens); // free the lock

let analysis = self.analysis.clone();
let client = self.client.clone();
let diagnostic_tokens = self.diagnostic_tokens.clone();
let file_id_clone = file_id.clone();
let file_id_clone = file_id;

// Spawn a new task to perform diagnostic
tokio::spawn(async move {
Expand Down Expand Up @@ -177,7 +177,7 @@ async fn workspace_diagnostic(
let mut count = 0;
if valid_file_count != 0 {
if silent {
while let Some(_) = rx.recv().await {
while (rx.recv().await).is_some() {
count += 1;
if count == valid_file_count {
break;
Expand All @@ -187,7 +187,7 @@ async fn workspace_diagnostic(
let text = format!("diagnose {} files", valid_file_count);
let _p = Profile::new(text.as_str());
let mut last_percentage = 0;
while let Some(_) = rx.recv().await {
while (rx.recv().await).is_some() {
count += 1;
let percentage_done = ((count as f32 / valid_file_count as f32) * 100.0) as u32;
if last_percentage != percentage_done {
Expand Down
14 changes: 0 additions & 14 deletions crates/emmylua_ls/src/context/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use lsp_types::{
NumberOrString, ProgressParams, ProgressParamsValue, WorkDoneProgress, WorkDoneProgressBegin,
WorkDoneProgressCreateParams, WorkDoneProgressEnd, WorkDoneProgressReport,
};
use serde::{Deserialize, Serialize};

use crate::util::time_cancel_token;

Expand Down Expand Up @@ -104,16 +103,3 @@ impl StatusBar {
)
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmmyServerStatus {
health: String,
loading: bool,
message: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmmyProgress {
text: String,
percent: f64,
}
56 changes: 23 additions & 33 deletions crates/emmylua_ls/src/context/workspace_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{path::PathBuf, sync::Arc, time::Duration};

use super::{ClientProxy, FileDiagnostic, StatusBar};
use crate::handlers::{ClientConfig, init_analysis};
use dirs;
use emmylua_code_analysis::{EmmyLuaAnalysis, Emmyrc, load_configs};
use emmylua_code_analysis::{update_code_style, uri_to_file_path};
use log::{debug, info};
Expand Down Expand Up @@ -114,10 +113,7 @@ impl WorkspaceManager {
}

pub async fn reload_workspace(&self) -> Option<()> {
let config_root: Option<PathBuf> = match self.workspace_folders.first() {
Some(root) => Some(PathBuf::from(root)),
None => None,
};
let config_root: Option<PathBuf> = self.workspace_folders.first().map(PathBuf::from);

let emmyrc = load_emmy_config(config_root, self.client_config.clone());
let analysis = self.analysis.clone();
Expand Down Expand Up @@ -183,7 +179,7 @@ impl WorkspaceManager {
return true;
}

let Some(file_path) = uri_to_file_path(&uri) else {
let Some(file_path) = uri_to_file_path(uri) else {
return true;
};

Expand Down Expand Up @@ -217,38 +213,32 @@ pub fn load_emmy_config(config_root: Option<PathBuf>, client_config: ClientConfi
let mut config_files = Vec::new();

let home_dir = dirs::home_dir();
match home_dir {
Some(home_dir) => {
let global_luarc_path = home_dir.join(luarc_file);
if global_luarc_path.exists() {
info!("load config from: {:?}", global_luarc_path);
config_files.push(global_luarc_path);
}
let global_emmyrc_path = home_dir.join(emmyrc_file);
if global_emmyrc_path.exists() {
info!("load config from: {:?}", global_emmyrc_path);
config_files.push(global_emmyrc_path);
}
if let Some(home_dir) = home_dir {
let global_luarc_path = home_dir.join(luarc_file);
if global_luarc_path.exists() {
info!("load config from: {:?}", global_luarc_path);
config_files.push(global_luarc_path);
}
let global_emmyrc_path = home_dir.join(emmyrc_file);
if global_emmyrc_path.exists() {
info!("load config from: {:?}", global_emmyrc_path);
config_files.push(global_emmyrc_path);
}
None => {}
};

let emmylua_config_dir = "emmylua_ls";
let config_dir = dirs::config_dir().map(|path| path.join(emmylua_config_dir));
match config_dir {
Some(config_dir) => {
let global_luarc_path = config_dir.join(luarc_file);
if global_luarc_path.exists() {
info!("load config from: {:?}", global_luarc_path);
config_files.push(global_luarc_path);
}
let global_emmyrc_path = config_dir.join(emmyrc_file);
if global_emmyrc_path.exists() {
info!("load config from: {:?}", global_emmyrc_path);
config_files.push(global_emmyrc_path);
}
if let Some(config_dir) = config_dir {
let global_luarc_path = config_dir.join(luarc_file);
if global_luarc_path.exists() {
info!("load config from: {:?}", global_luarc_path);
config_files.push(global_luarc_path);
}
let global_emmyrc_path = config_dir.join(emmyrc_file);
if global_emmyrc_path.exists() {
info!("load config from: {:?}", global_emmyrc_path);
config_files.push(global_emmyrc_path);
}
None => {}
};

std::env::var("EMMYLUALS_CONFIG")
Expand Down Expand Up @@ -381,7 +371,7 @@ impl WorkspaceFileMatcher {
log::error!("Invalid include pattern");
}

return true;
true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ fn get_kind(db: &DbIndex, type_owner: LuaTypeOwner) -> SymbolKind {
match type_cache {
Some(typ) => {
if typ.is_function() {
return SymbolKind::FUNCTION;
SymbolKind::FUNCTION
} else if typ.is_ref() || typ.is_def() {
return SymbolKind::CLASS;
SymbolKind::CLASS
} else if typ.is_const() {
return SymbolKind::CONSTANT;
SymbolKind::CONSTANT
} else {
return SymbolKind::VARIABLE;
SymbolKind::VARIABLE
}
}
None => SymbolKind::VARIABLE,
Expand Down
Loading
Loading