-
Notifications
You must be signed in to change notification settings - Fork 53
emmylua_doc_cli: support include patterns #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 { | ||||||||||||||||||
|
|
@@ -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| { | ||||||||||||||||||
|
|
@@ -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; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -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 { | ||||||||||||||||||
| 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()); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better readability and consistency, consider using a more descriptive variable name than
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| for dir in &emmyrc.workspace.ignore_dir { | ||||||||||||||||||
|
|
||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability, consider using a more descriptive variable name than
p. For example,patternsorinclude_patternswould make it clearer what the variable contains.