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
4 changes: 3 additions & 1 deletion crates/emmylua_doc_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ Arguments:

Options:
-c, --config <CONFIG> Configuration file paths. If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace directory
--ignore <IGNORE> Comma separated list of ignore patterns. Patterns must follow glob syntax
--include <INCLUDE> Comma separated list of include patterns. Patterns must follow glob syntax. It will override the default include patterns.
--ignore <EXCLUDE> Comma separated list of exclude patterns. Patterns must follow glob syntax(deprecated, use --exclude instead)
--exclude <EXCLUDE> Comma separated list of exclude patterns. Patterns must follow glob syntax. Exclude patterns take precedence over include patterns
-f, --output-format <OUTPUT_FORMAT> Specify output format [default: markdown] [possible values: json, markdown]
-o, --output <OUTPUT> Specify output destination (can be stdout when output_format is json) [default: ./output]
--override-template <OVERRIDE_TEMPLATE> The path of the override template
Expand Down
12 changes: 9 additions & 3 deletions crates/emmylua_doc_cli/src/cmd_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ pub struct CmdArgs {
#[arg(num_args = 1..)]
pub workspace: Vec<PathBuf>,

/// Comma separated list of ignore patterns.
/// Comma separated list of exclude patterns
/// Patterns must follow glob syntax
#[arg(long, value_delimiter = ',')]
pub ignore: Option<Vec<String>>,
/// Exclude patterns take precedence over include patterns
#[arg(long = "exclude", alias = "ignore", value_delimiter = ',')]
pub exclude_pattern: Option<Vec<String>>,

/// Comma separated list of include patterns
/// Patterns must follow glob syntax
#[arg(long = "include", value_delimiter = ',')]
pub include_pattern: Option<Vec<String>>,

/// Specify output format
#[arg(
Expand Down
57 changes: 38 additions & 19 deletions crates/emmylua_doc_cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub fn load_workspace(
main_path: PathBuf,
mut workspace_folders: Vec<PathBuf>,
config_paths: Option<Vec<PathBuf>>,
ignore: Option<Vec<String>>,
exclude_pattern: Option<Vec<String>>,
include_pattern: Option<Vec<String>>,
) -> Option<EmmyLuaAnalysis> {
let (config_files, config_root): (Vec<PathBuf>, PathBuf) =
if let Some(config_paths) = config_paths {
Expand Down Expand Up @@ -111,7 +112,12 @@ pub fn load_workspace(
analysis.update_config(Arc::new(emmyrc));
analysis.init_std_lib(None);

let file_infos = collect_files(&workspace_folders, &analysis.emmyrc, ignore);
let file_infos = collect_files(
&workspace_folders,
&analysis.emmyrc,
exclude_pattern,
include_pattern,
);
let files = file_infos
.into_iter()
.filter_map(|file| {
Expand Down Expand Up @@ -140,10 +146,12 @@ pub fn load_workspace(
pub fn collect_files(
workspaces: &Vec<PathBuf>,
emmyrc: &Emmyrc,
ignore: Option<Vec<String>>,
exclude_pattern: Option<Vec<String>>,
include_pattern: Option<Vec<String>>,
) -> Vec<LuaFileInfo> {
let mut files = Vec::new();
let (match_pattern, exclude, exclude_dir) = calculate_include_and_exclude(emmyrc, ignore);
let (match_pattern, exclude, exclude_dir) =
calculate_include_and_exclude(emmyrc, exclude_pattern, include_pattern);

let encoding = &emmyrc.workspace.encoding;

Expand All @@ -167,21 +175,32 @@ pub fn collect_files(
/// File patterns for workspace scanning: (include_patterns, exclude_patterns, exclude_dirs)
type FilePatterns = (Vec<String>, Vec<String>, Vec<PathBuf>);

pub fn calculate_include_and_exclude(emmyrc: &Emmyrc, ignore: Option<Vec<String>>) -> FilePatterns {
let mut include = vec!["**/*.lua".to_string(), "**/.editorconfig".to_string()];
pub fn calculate_include_and_exclude(
emmyrc: &Emmyrc,
exclude_pattern: Option<Vec<String>>,
include_pattern: Option<Vec<String>>,
) -> FilePatterns {
let mut include = Vec::new();
let mut exclude = Vec::new();
let mut exclude_dirs = Vec::new();

for extension in &emmyrc.runtime.extensions {
if extension.starts_with(".") {
log::info!("Adding extension: **/*{}", extension);
include.push(format!("**/*{}", extension));
} else if extension.starts_with("*.") {
log::info!("Adding extension: **/{}", extension);
include.push(format!("**/{}", extension));
} else {
log::info!("Adding extension: {}", extension);
include.push(extension.clone());
if let Some(p) = include_pattern {
include.extend(p);
} else {
Comment on lines +187 to +189

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability, consider using a more descriptive variable name than p. For example, patterns or include_patterns would make it clearer what the variable contains.

Suggested change
if let Some(p) = include_pattern {
include.extend(p);
} else {
if let Some(patterns) = include_pattern {
include.extend(patterns);
} else {

include.push("**/*.lua".to_string());
include.push("**/.editorconfig".to_string());

for extension in &emmyrc.runtime.extensions {
if extension.starts_with(".") {
log::info!("Adding extension: **/*{}", extension);
include.push(format!("**/*{}", extension));
} else if extension.starts_with("*.") {
log::info!("Adding extension: **/{}", extension);
include.push(format!("**/{}", extension));
} else {
log::info!("Adding extension: {}", extension);
include.push(extension.clone());
}
}
}

Expand All @@ -190,9 +209,9 @@ pub fn calculate_include_and_exclude(emmyrc: &Emmyrc, ignore: Option<Vec<String>
exclude.push(ignore_glob.clone());
}

if let Some(ignore) = ignore {
log::info!("Adding ignores from \"--ignore\": {:?}", ignore);
exclude.extend(ignore);
if let Some(p) = exclude_pattern {
log::info!("Adding excludes from \"--exclude(or --ignore)\": {:?}", p);
exclude.extend(p);
}
Comment on lines +212 to 215

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and consistency, consider using a more descriptive variable name than p. For example, patterns or exclude_patterns would make the code's intent clearer.

Suggested change
if let Some(p) = exclude_pattern {
log::info!("Adding excludes from \"--exclude(or --ignore)\": {:?}", p);
exclude.extend(p);
}
if let Some(patterns) = exclude_pattern {
log::info!("Adding excludes from \"--exclude(or --ignore)\": {:?}", patterns);
exclude.extend(patterns);
}


for dir in &emmyrc.workspace.ignore_dir {
Expand Down
3 changes: 2 additions & 1 deletion crates/emmylua_doc_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub fn run_doc_cli(mut cmd_args: CmdArgs) -> Result<(), Box<dyn std::error::Erro
main_path.clone(),
workspaces.clone(),
cmd_args.config,
cmd_args.ignore,
cmd_args.exclude_pattern,
cmd_args.include_pattern,
) {
Some(analysis) => analysis,
None => {
Expand Down