Skip to main content

ass_editor/extensions/
info.rs

1//! Extension capability and metadata types.
2//!
3//! Defines the capabilities an extension can advertise and the descriptive
4//! metadata (`ExtensionInfo`) attached to each extension.
5
6#[cfg(not(feature = "std"))]
7use alloc::{string::String, vec::Vec};
8
9/// Extension capabilities that can be provided
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum ExtensionCapability {
12    /// Text processing and transformation
13    TextProcessing,
14    /// Syntax highlighting and theming
15    SyntaxHighlighting,
16    /// Code completion and suggestions
17    CodeCompletion,
18    /// Linting and validation
19    Linting,
20    /// Import/export format support
21    FormatSupport,
22    /// Custom commands and shortcuts
23    CustomCommands,
24    /// UI enhancements and widgets
25    UserInterface,
26    /// External tool integration
27    ToolIntegration,
28    /// Custom event handling
29    EventHandling,
30    /// Performance monitoring
31    Performance,
32}
33
34impl ExtensionCapability {
35    /// Get a human-readable description of the capability
36    pub fn description(&self) -> &'static str {
37        match self {
38            Self::TextProcessing => "Text processing and transformation",
39            Self::SyntaxHighlighting => "Syntax highlighting and theming",
40            Self::CodeCompletion => "Code completion and suggestions",
41            Self::Linting => "Linting and validation",
42            Self::FormatSupport => "Import/export format support",
43            Self::CustomCommands => "Custom commands and shortcuts",
44            Self::UserInterface => "UI enhancements and widgets",
45            Self::ToolIntegration => "External tool integration",
46            Self::EventHandling => "Custom event handling",
47            Self::Performance => "Performance monitoring",
48        }
49    }
50}
51
52/// Extension metadata and information
53#[derive(Debug, Clone, PartialEq, Eq)]
54pub struct ExtensionInfo {
55    /// Extension name
56    pub name: String,
57    /// Extension version
58    pub version: String,
59    /// Extension author
60    pub author: String,
61    /// Extension description
62    pub description: String,
63    /// Capabilities provided by this extension
64    pub capabilities: Vec<ExtensionCapability>,
65    /// Dependencies on other extensions
66    pub dependencies: Vec<String>,
67    /// Optional extension website/homepage
68    pub homepage: Option<String>,
69    /// License identifier
70    pub license: Option<String>,
71}
72
73impl ExtensionInfo {
74    /// Create a new extension info
75    pub fn new(name: String, version: String, author: String, description: String) -> Self {
76        Self {
77            name,
78            version,
79            author,
80            description,
81            capabilities: Vec::new(),
82            dependencies: Vec::new(),
83            homepage: None,
84            license: None,
85        }
86    }
87
88    /// Add a capability to this extension
89    pub fn with_capability(mut self, capability: ExtensionCapability) -> Self {
90        self.capabilities.push(capability);
91        self
92    }
93
94    /// Add multiple capabilities
95    pub fn with_capabilities(mut self, capabilities: Vec<ExtensionCapability>) -> Self {
96        self.capabilities.extend(capabilities);
97        self
98    }
99
100    /// Add a dependency on another extension
101    pub fn with_dependency(mut self, dependency: String) -> Self {
102        self.dependencies.push(dependency);
103        self
104    }
105
106    /// Set the homepage URL
107    pub fn with_homepage(mut self, homepage: String) -> Self {
108        self.homepage = Some(homepage);
109        self
110    }
111
112    /// Set the license
113    pub fn with_license(mut self, license: String) -> Self {
114        self.license = Some(license);
115        self
116    }
117
118    /// Check if this extension provides a specific capability
119    pub fn has_capability(&self, capability: &ExtensionCapability) -> bool {
120        self.capabilities.contains(capability)
121    }
122}