lsp: Remove the PostLoadBehavior

We always update if we have a UI and we never update if not. So this
flag does not help.
This commit is contained in:
Tobias Hunger 2023-09-01 11:37:46 +02:00 committed by Olivier Goffart
parent df86bf67af
commit 55cc1ae31f
5 changed files with 23 additions and 40 deletions

View file

@ -15,7 +15,7 @@ pub type Result<T> = std::result::Result<T, Error>;
/// ServerNotifier /// ServerNotifier
pub trait PreviewApi { pub trait PreviewApi {
fn set_contents(&self, path: &Path, contents: &str); fn set_contents(&self, path: &Path, contents: &str);
fn load_preview(&self, component: PreviewComponent, behavior: PostLoadBehavior); fn load_preview(&self, component: PreviewComponent);
fn config_changed( fn config_changed(
&self, &self,
style: &str, style: &str,
@ -44,10 +44,3 @@ pub struct PreviewComponent {
/// The style name for the preview /// The style name for the preview
pub style: String, pub style: String,
} }
/// What to do after a preview is loaded
#[allow(unused)]
pub enum PostLoadBehavior {
ShowAfterLoad,
DoNothing,
}

View file

@ -394,16 +394,13 @@ pub fn show_preview_command(params: &[serde_json::Value], ctx: &Rc<Context>) ->
params.get(1).and_then(|v| v.as_str()).filter(|v| !v.is_empty()).map(|v| v.to_string()); params.get(1).and_then(|v| v.as_str()).filter(|v| !v.is_empty()).map(|v| v.to_string());
let path = uri_to_file(&url).unwrap_or_default(); let path = uri_to_file(&url).unwrap_or_default();
ctx.preview.load_preview( ctx.preview.load_preview(crate::common::PreviewComponent {
crate::common::PreviewComponent { path,
path, component,
component, include_paths: config.include_paths.clone(),
include_paths: config.include_paths.clone(), library_paths: config.library_paths.clone(),
library_paths: config.library_paths.clone(), style: config.style.clone().unwrap_or_default(),
style: config.style.clone().unwrap_or_default(), });
},
crate::common::PostLoadBehavior::ShowAfterLoad,
);
Ok(()) Ok(())
} }

View file

@ -41,15 +41,11 @@ impl PreviewApi for Previewer {
preview::set_contents(_path, _contents.to_string()); preview::set_contents(_path, _contents.to_string());
} }
fn load_preview( fn load_preview(&self, _component: common::PreviewComponent) {
&self,
_component: common::PreviewComponent,
_behavior: common::PostLoadBehavior,
) {
#[cfg(feature = "preview")] #[cfg(feature = "preview")]
{ {
preview::open_ui(&self.server_notifier); preview::open_ui(&self.server_notifier);
preview::load_preview(_component, _behavior); preview::load_preview(_component);
} }
} }

View file

@ -3,7 +3,7 @@
// cSpell: ignore condvar // cSpell: ignore condvar
use crate::common::{PostLoadBehavior, PreviewComponent}; use crate::common::PreviewComponent;
use crate::lsp_ext::{Health, ServerStatusNotification, ServerStatusParams}; use crate::lsp_ext::{Health, ServerStatusNotification, ServerStatusParams};
use crate::ServerNotifier; use crate::ServerNotifier;
@ -177,7 +177,7 @@ fn close_ui_impl(preview_state: &mut PreviewState) {
} }
} }
pub fn load_preview(component: PreviewComponent, post_load_behavior: PostLoadBehavior) { pub fn load_preview(component: PreviewComponent) {
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
static PENDING_EVENTS: AtomicU32 = AtomicU32::new(0); static PENDING_EVENTS: AtomicU32 = AtomicU32::new(0);
if PENDING_EVENTS.load(Ordering::SeqCst) > 0 { if PENDING_EVENTS.load(Ordering::SeqCst) > 0 {
@ -186,7 +186,7 @@ pub fn load_preview(component: PreviewComponent, post_load_behavior: PostLoadBeh
PENDING_EVENTS.fetch_add(1, Ordering::SeqCst); PENDING_EVENTS.fetch_add(1, Ordering::SeqCst);
run_in_ui_thread(move || async move { run_in_ui_thread(move || async move {
PENDING_EVENTS.fetch_sub(1, Ordering::SeqCst); PENDING_EVENTS.fetch_sub(1, Ordering::SeqCst);
reload_preview(component, post_load_behavior).await reload_preview(component).await
}); });
} }
@ -212,9 +212,11 @@ pub fn set_contents(path: &Path, content: String) {
drop(cache); drop(cache);
let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap(); let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap();
cache.sender = sender.clone(); cache.sender = sender;
load_preview(current, PostLoadBehavior::DoNothing); if cache.sender.is_some() {
load_preview(current);
}
} }
} }
@ -238,9 +240,11 @@ pub fn config_changed(
drop(cache); drop(cache);
let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap(); let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap();
cache.sender = sender.clone(); cache.sender = sender;
load_preview(current, PostLoadBehavior::DoNothing); if cache.sender.is_some() {
load_preview(current);
}
} }
}; };
} }
@ -339,10 +343,7 @@ fn configure_design_mode(enabled: bool, sender: &crate::ServerNotifier) {
}); });
} }
async fn reload_preview( async fn reload_preview(preview_component: PreviewComponent) {
preview_component: PreviewComponent,
_post_load_behavior: PostLoadBehavior,
) {
let (design_mode, sender) = { let (design_mode, sender) = {
let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap(); let mut cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap();
cache.dependency.clear(); cache.dependency.clear();

View file

@ -52,11 +52,7 @@ impl PreviewApi for Previewer {
// do nothing! // do nothing!
} }
fn load_preview( fn load_preview(&self, _component: common::PreviewComponent) {
&self,
_component: common::PreviewComponent,
_behavior: common::PostLoadBehavior,
) {
// do nothing! // do nothing!
} }