WIP
This commit is contained in:
parent
dc0a761c96
commit
a5a597611e
@ -15,7 +15,9 @@ pub trait LauncherListItem {
|
||||
}
|
||||
|
||||
pub trait LauncherPlugin {
|
||||
fn init(&self);
|
||||
fn init(&self) {
|
||||
// Default empty init - plugins can override this
|
||||
}
|
||||
fn name(&self) -> String;
|
||||
fn priority(&self) -> i32;
|
||||
fn description(&self) -> Option<String>;
|
||||
|
@ -142,7 +142,7 @@ impl PluginConfig {
|
||||
quote! { false }
|
||||
};
|
||||
|
||||
// Generate init method
|
||||
// Generate init method only if explicitly specified in config
|
||||
let init_method = if let Some(ref init_fn) = self.init_fn {
|
||||
quote! {
|
||||
fn init(&self) {
|
||||
@ -150,11 +150,8 @@ impl PluginConfig {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
fn init(&self) {
|
||||
// Default empty init
|
||||
}
|
||||
}
|
||||
// Don't generate init method - user should implement it themselves or it will use default
|
||||
quote! {}
|
||||
};
|
||||
|
||||
// Generate default_list method
|
||||
@ -217,7 +214,8 @@ impl PluginConfig {
|
||||
// Stub implementations to satisfy rust-analyzer
|
||||
// These are only compiled when rust-analyzer is checking the code
|
||||
#[cfg(rust_analyzer)]
|
||||
fn init(&self) { unimplemented!("Generated by plugin! macro") }
|
||||
#[allow(unused)]
|
||||
fn init(&self) { unimplemented!("Generated by plugin! macro or implement your own") }
|
||||
#[cfg(rust_analyzer)]
|
||||
fn name(&self) -> String { unimplemented!("Generated by plugin! macro") }
|
||||
#[cfg(rust_analyzer)]
|
||||
|
@ -193,10 +193,27 @@ impl LauncherPlugin for FileSearchPlugin {
|
||||
priority: 500,
|
||||
description: "Search and open files",
|
||||
prefix: "f",
|
||||
init: file_search_init,
|
||||
default_list: file_search_default_list,
|
||||
filter: file_search_filter
|
||||
}
|
||||
|
||||
fn init(&self) {
|
||||
// Start async file scanning with 2000ms timeout
|
||||
let self_clone = FileSearchPlugin {
|
||||
search_paths: self.search_paths.clone(),
|
||||
skip_dirs: self.skip_dirs.clone(),
|
||||
files: Arc::clone(&self.files),
|
||||
};
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
self_clone
|
||||
.init_with_timeout(Duration::from_millis(2000))
|
||||
.await;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn file_search_default_list(_plugin: &FileSearchPlugin) -> Vec<Box<dyn LauncherListItem>> {
|
||||
@ -225,23 +242,6 @@ fn file_search_filter(plugin: &FileSearchPlugin, query: &str) -> Vec<Box<dyn Lau
|
||||
entries
|
||||
}
|
||||
|
||||
fn file_search_init(plugin: &FileSearchPlugin) {
|
||||
// Start async file scanning with 500ms timeout
|
||||
let self_clone = FileSearchPlugin {
|
||||
search_paths: plugin.search_paths.clone(),
|
||||
skip_dirs: plugin.skip_dirs.clone(),
|
||||
files: Arc::clone(&plugin.files),
|
||||
};
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
self_clone
|
||||
.init_with_timeout(Duration::from_millis(2000))
|
||||
.await;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new() -> FileSearchPlugin {
|
||||
FileSearchPlugin::new()
|
||||
|
@ -82,10 +82,57 @@ impl LauncherPlugin for ProjectsPlugin {
|
||||
priority: 800,
|
||||
description: "Search and open code projects",
|
||||
prefix: "proj",
|
||||
init: projects_init,
|
||||
default_list: projects_default_list,
|
||||
filter: projects_filter
|
||||
}
|
||||
|
||||
fn init(&self) {
|
||||
let files_clone = Arc::clone(&self.files);
|
||||
let search_paths = self.search_paths.clone();
|
||||
let skip_dirs = self.skip_dirs.clone();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let mut project_entries = Vec::new();
|
||||
|
||||
for search_path in &search_paths {
|
||||
if let Ok(entries) = fs::read_dir(search_path) {
|
||||
for entry in entries.flatten() {
|
||||
if let Ok(file_type) = entry.file_type() {
|
||||
if file_type.is_dir() {
|
||||
let path = entry.path();
|
||||
|
||||
// Skip hidden directories (starting with .)
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if let Some(name_str) = file_name.to_str() {
|
||||
// Skip hidden directories
|
||||
if name_str.starts_with('.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip directories in skip list
|
||||
if should_skip_dir(name_str, &skip_dirs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
project_entries.push(ProjectEntry { path });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the shared files collection
|
||||
let mut files_guard = files_clone.lock().await;
|
||||
*files_guard = project_entries;
|
||||
|
||||
println!("Projects plugin: Found {} projects", files_guard.len());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn projects_default_list(_plugin: &ProjectsPlugin) -> Vec<Box<dyn LauncherListItem>> {
|
||||
@ -114,55 +161,6 @@ fn projects_filter(plugin: &ProjectsPlugin, query: &str) -> Vec<Box<dyn Launcher
|
||||
entries
|
||||
}
|
||||
|
||||
fn projects_init(plugin: &ProjectsPlugin) {
|
||||
let files_clone = Arc::clone(&plugin.files);
|
||||
let search_paths = plugin.search_paths.clone();
|
||||
let skip_dirs = plugin.skip_dirs.clone();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let mut project_entries = Vec::new();
|
||||
|
||||
for search_path in &search_paths {
|
||||
if let Ok(entries) = fs::read_dir(search_path) {
|
||||
for entry in entries.flatten() {
|
||||
if let Ok(file_type) = entry.file_type() {
|
||||
if file_type.is_dir() {
|
||||
let path = entry.path();
|
||||
|
||||
// Skip hidden directories (starting with .)
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if let Some(name_str) = file_name.to_str() {
|
||||
// Skip hidden directories
|
||||
if name_str.starts_with('.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip directories in skip list
|
||||
if should_skip_dir(name_str, &skip_dirs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("{}", path.display());
|
||||
|
||||
project_entries.push(ProjectEntry { path });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the shared files collection
|
||||
let mut files_guard = files_clone.lock().await;
|
||||
*files_guard = project_entries;
|
||||
|
||||
println!("Projects plugin: Found {} projects", files_guard.len());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new() -> ProjectsPlugin {
|
||||
ProjectsPlugin {
|
||||
|
Loading…
x
Reference in New Issue
Block a user