fresh_core/command.rs
1use serde::{Deserialize, Serialize};
2
3/// Source of a command (builtin or from a plugin)
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ts_rs::TS)]
5#[ts(export)]
6pub enum CommandSource {
7 /// Built-in editor command
8 Builtin,
9 /// Command registered by a plugin (contains plugin filename without extension)
10 Plugin(String),
11}
12
13/// A command registered by a plugin via the service bridge.
14/// This is a simplified version that the editor converts to its internal Command type.
15#[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
16#[ts(export)]
17pub struct Command {
18 /// Command name (e.g., "Open File")
19 pub name: String,
20 /// Command description
21 pub description: String,
22 /// The action name to trigger (for plugin commands, this is the function name)
23 pub action_name: String,
24 /// Plugin that registered this command
25 pub plugin_name: String,
26 /// Custom contexts required for this command (plugin-defined contexts like "vi-mode")
27 pub custom_contexts: Vec<String>,
28}
29
30/// A single suggestion item for autocomplete
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ts_rs::TS)]
32#[ts(export)]
33pub struct Suggestion {
34 /// The text to display
35 pub text: String,
36 /// Optional description
37 pub description: Option<String>,
38 /// The value to use when selected (defaults to text if None)
39 pub value: Option<String>,
40 /// Whether this suggestion is disabled (greyed out)
41 pub disabled: bool,
42 /// Optional keyboard shortcut
43 pub keybinding: Option<String>,
44 /// Source of the command (for command palette)
45 pub source: Option<CommandSource>,
46}
47
48impl Suggestion {
49 pub fn new(text: String) -> Self {
50 Self {
51 text,
52 description: None,
53 value: None,
54 disabled: false,
55 keybinding: None,
56 source: None,
57 }
58 }
59}