mirror of https://github.com/lapce/lapce.git
config folder watcher improvement
This commit is contained in:
parent
f4a93b61f0
commit
7dbcfc0a6c
|
@ -11,7 +11,7 @@
|
||||||
};
|
};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use lapce_proxy::{directory::Directory, plugin::wasi::find_all_volts};
|
use lapce_proxy::{directory::Directory, plugin::wasi::find_all_volts};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::{Mutex, RwLock};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use structdesc::FieldNames;
|
use structdesc::FieldNames;
|
||||||
|
@ -606,11 +606,15 @@ pub struct Config {
|
||||||
|
|
||||||
pub struct ConfigWatcher {
|
pub struct ConfigWatcher {
|
||||||
event_sink: ExtEventSink,
|
event_sink: ExtEventSink,
|
||||||
|
delay_handler: Arc<Mutex<Option<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigWatcher {
|
impl ConfigWatcher {
|
||||||
pub fn new(event_sink: ExtEventSink) -> Self {
|
pub fn new(event_sink: ExtEventSink) -> Self {
|
||||||
Self { event_sink }
|
Self {
|
||||||
|
event_sink,
|
||||||
|
delay_handler: Arc::new(Mutex::new(None)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,11 +625,19 @@ fn handle_event(&mut self, event: notify::Result<notify::Event>) {
|
||||||
notify::EventKind::Create(_)
|
notify::EventKind::Create(_)
|
||||||
| notify::EventKind::Modify(_)
|
| notify::EventKind::Modify(_)
|
||||||
| notify::EventKind::Remove(_) => {
|
| notify::EventKind::Remove(_) => {
|
||||||
let _ = self.event_sink.submit_command(
|
*self.delay_handler.lock() = Some(());
|
||||||
LAPCE_UI_COMMAND,
|
let delay_handler = self.delay_handler.clone();
|
||||||
LapceUICommand::ReloadConfig,
|
let event_sink = self.event_sink.clone();
|
||||||
Target::Auto,
|
std::thread::spawn(move || {
|
||||||
);
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
|
if delay_handler.lock().take().is_some() {
|
||||||
|
let _ = event_sink.submit_command(
|
||||||
|
LAPCE_UI_COMMAND,
|
||||||
|
LapceUICommand::ReloadConfig,
|
||||||
|
Target::Auto,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,6 @@ fn count(&self) -> usize {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::command::CommandExecuted::No;
|
|
||||||
use crate::selection_range::SyntaxSelectionRanges;
|
use crate::selection_range::SyntaxSelectionRanges;
|
||||||
use lapce_rpc::buffer::BufferId;
|
use lapce_rpc::buffer::BufferId;
|
||||||
use lsp_types::{Position, Range, SelectionRange};
|
use lsp_types::{Position, Range, SelectionRange};
|
||||||
|
@ -136,11 +135,11 @@ fn should_get_next_selection_range() {
|
||||||
rev: 0,
|
rev: 0,
|
||||||
last_known_selection: None,
|
last_known_selection: None,
|
||||||
ranges: SelectionRange {
|
ranges: SelectionRange {
|
||||||
range: range_zero.clone(),
|
range: range_zero,
|
||||||
parent: Some(Box::new(SelectionRange {
|
parent: Some(Box::new(SelectionRange {
|
||||||
range: range_one.clone(),
|
range: range_one,
|
||||||
parent: Some(Box::new(SelectionRange {
|
parent: Some(Box::new(SelectionRange {
|
||||||
range: range_two.clone(),
|
range: range_two,
|
||||||
parent: None,
|
parent: None,
|
||||||
})),
|
})),
|
||||||
})),
|
})),
|
||||||
|
|
Loading…
Reference in New Issue