-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add *.md support for plugin's details #2204
Open
DmitryAstafyev
wants to merge
7
commits into
esrlabs:plugins_support
Choose a base branch
from
DmitryAstafyev:plugins_support
base: plugins_support
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ebe0dba
Add *.md support for plugin's details
DmitryAstafyev 633e612
Add PluginRunData entity
DmitryAstafyev e12330e
Update Plugin Manager (client)
DmitryAstafyev fcd4b25
Fetching plugin run data to client
DmitryAstafyev 7dcfb70
Show logs first for invalid plugins
DmitryAstafyev e0d674d
Correct styling
DmitryAstafyev 94c0c8b
Format a TS file
DmitryAstafyev 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 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 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 |
---|---|---|
|
@@ -9,13 +9,16 @@ mod tests; | |
use std::path::{Path, PathBuf}; | ||
|
||
pub use errors::InitError; | ||
use stypes::{InvalidPluginEntity, PluginEntity}; | ||
use stypes::{ | ||
ExtendedInvalidPluginEntity, ExtendedPluginEntity, InvalidPluginEntity, PluginEntity, | ||
PluginRunData, | ||
}; | ||
|
||
/// Plugins manager responsible of loading the plugins, providing their states, info and metadata. | ||
#[derive(Debug)] | ||
pub struct PluginsManager { | ||
installed_plugins: Vec<PluginEntity>, | ||
invalid_plugins: Vec<InvalidPluginEntity>, | ||
installed_plugins: Vec<ExtendedPluginEntity>, | ||
invalid_plugins: Vec<ExtendedInvalidPluginEntity>, | ||
} | ||
|
||
impl PluginsManager { | ||
|
@@ -30,41 +33,87 @@ impl PluginsManager { | |
} | ||
|
||
/// Provide full infos of all loaded and valid plugins. | ||
pub fn installed_plugins(&self) -> &[PluginEntity] { | ||
&self.installed_plugins | ||
pub fn installed_plugins(&self) -> Vec<&PluginEntity> { | ||
self.installed_plugins | ||
.iter() | ||
.map(|en| en.into()) | ||
.collect::<Vec<&PluginEntity>>() | ||
Comment on lines
-33
to
+40
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. We can return an iterator here without having to collect into vector inside the function /// Provide full infos of all loaded and valid plugins.
pub fn installed_plugins(&self) -> impl Iterator<Item = &PluginEntity> {
self.installed_plugins.iter().map(|en| en.into())
} |
||
} | ||
|
||
/// Provide directory paths (considered ID) of all loaded and valid plugins. | ||
pub fn installed_plugins_paths(&self) -> impl Iterator<Item = &PathBuf> { | ||
self.installed_plugins.iter().map(|p| &p.dir_path) | ||
self.installed_plugins.iter().map(|p| &p.entity.dir_path) | ||
} | ||
|
||
/// Provide the info of the plugin with the given [`plugin_dir`] if available. | ||
/// | ||
/// * `plugin_dir`: The directory path of the plugin. Considered as ID currently. | ||
pub fn get_installed_plugin(&self, plugin_dir: &Path) -> Option<&PluginEntity> { | ||
self.installed_plugins | ||
.iter() | ||
.find(|p| p.dir_path == plugin_dir) | ||
self.installed_plugins.iter().find_map(|p| { | ||
if p.entity.dir_path == plugin_dir { | ||
Some(p.into()) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
|
||
/// Provide all invalid plugins. | ||
pub fn invalid_plugins(&self) -> &[InvalidPluginEntity] { | ||
&self.invalid_plugins | ||
pub fn invalid_plugins(&self) -> Vec<&InvalidPluginEntity> { | ||
self.invalid_plugins | ||
.iter() | ||
.map(|en| en.into()) | ||
.collect::<Vec<&InvalidPluginEntity>>() | ||
Comment on lines
-52
to
+66
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. Returning an iterator is more flexible here as well pub fn invalid_plugins(&self) -> impl Iterator<Item = &InvalidPluginEntity> {
self.invalid_plugins.iter().map(|en| en.into())
} |
||
} | ||
|
||
/// Provide directory paths (considered ID) of all invalid plugins. | ||
pub fn invalid_plugins_paths(&self) -> impl Iterator<Item = &PathBuf> { | ||
self.invalid_plugins.iter().map(|p| &p.dir_path) | ||
self.invalid_plugins.iter().map(|p| &p.entity.dir_path) | ||
} | ||
|
||
/// Provide the info of the invalid plugin with the given [`plugin_dir`] if available. | ||
/// | ||
/// * `plugin_dir`: The directory path of the plugin. Considered as ID currently. | ||
pub fn get_invalid_plugin(&self, plugin_dir: &Path) -> Option<&InvalidPluginEntity> { | ||
self.invalid_plugins | ||
self.invalid_plugins.iter().find_map(|p| { | ||
if p.entity.dir_path == plugin_dir { | ||
Some(p.into()) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
|
||
/// Retrieves runtime data for a plugin located at the specified path. | ||
/// | ||
/// This method searches for the plugin's runtime data (`PluginRunData`) among both | ||
/// successfully loaded plugins and failed ones. | ||
/// | ||
/// # Parameters | ||
/// - `plugin_dir`: The directory path of the plugin. | ||
/// | ||
/// # Returns | ||
/// - `Some(&PluginRunData)`: If the plugin's runtime data is found. | ||
/// - `None`: If no matching plugin is found. | ||
pub fn get_plugin_run_data<P: AsRef<Path>>(&self, plugin_dir: P) -> Option<&PluginRunData> { | ||
self.installed_plugins | ||
.iter() | ||
.find(|p| p.dir_path == plugin_dir) | ||
.find_map(|p| { | ||
if p.entity.dir_path == plugin_dir.as_ref() { | ||
Some(&p.rd) | ||
} else { | ||
None | ||
} | ||
}) | ||
.or_else(|| { | ||
self.invalid_plugins.iter().find_map(|p| { | ||
if p.entity.dir_path == plugin_dir.as_ref() { | ||
Some(&p.rd) | ||
} else { | ||
None | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
/// Reload all the plugins from the plugins directory. | ||
|
This file contains 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
I really like the names to be more expressive. Can we change this to
run_data
orrdata