-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtraits.rs
More file actions
99 lines (82 loc) · 2.83 KB
/
Copy pathtraits.rs
File metadata and controls
99 lines (82 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use std::path::Path;
use kild_config::KildConfig;
use super::errors::EditorError;
/// Trait defining the interface for editor backends.
///
/// Each supported editor (Zed, VS Code, Vim/Neovim, etc.) implements this trait
/// to provide editor-specific spawning behavior.
pub trait EditorBackend: Send + Sync {
/// The canonical name of this editor (e.g., "zed", "code", "vim").
fn name(&self) -> &'static str;
/// The user-facing display name (e.g., "Zed", "VS Code", "Vim").
fn display_name(&self) -> &'static str;
/// Whether this editor is available on the system.
fn is_available(&self) -> bool;
/// Whether this editor runs inside a terminal (e.g., vim, nvim, helix).
///
/// INVARIANT: If this returns `true`, `open()` MUST delegate to
/// `terminal_ops::spawn_terminal()`. If `false`, `open()` MUST spawn
/// the editor process directly via `Command::new()`.
fn is_terminal_editor(&self) -> bool;
/// Open a path in this editor.
///
/// For GUI editors, spawns a new process directly.
/// For terminal editors, delegates to the terminal backend via `config`.
fn open(&self, path: &Path, flags: &[String], config: &KildConfig) -> Result<(), EditorError>;
/// Open with an override command name.
///
/// Used for editors where multiple command names map to the same backend
/// (e.g., vim/nvim/helix all use VimBackend). The default implementation
/// ignores the override and calls `open()`.
fn open_with_command(
&self,
_command_override: &str,
path: &Path,
flags: &[String],
config: &KildConfig,
) -> Result<(), EditorError> {
self.open(path, flags, config)
}
}
#[cfg(test)]
mod tests {
use super::*;
struct MockBackend;
impl EditorBackend for MockBackend {
fn name(&self) -> &'static str {
"mock"
}
fn display_name(&self) -> &'static str {
"Mock Editor"
}
fn is_available(&self) -> bool {
true
}
fn is_terminal_editor(&self) -> bool {
false
}
fn open(
&self,
_path: &Path,
_flags: &[String],
_config: &KildConfig,
) -> Result<(), EditorError> {
Ok(())
}
}
#[test]
fn mock_editor_backend_is_available_and_not_a_terminal_editor() {
let backend = MockBackend;
assert_eq!(backend.name(), "mock");
assert_eq!(backend.display_name(), "Mock Editor");
assert!(backend.is_available());
assert!(!backend.is_terminal_editor());
}
#[test]
fn mock_editor_backend_open_succeeds() {
let backend = MockBackend;
let config = KildConfig::default();
let result = backend.open(Path::new("/tmp"), &[], &config);
assert!(result.is_ok());
}
}