mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Try to gracefully terminate the LSP server when requested
This commit is contained in:
parent
121a098f74
commit
d9db07db2a
2 changed files with 38 additions and 26 deletions
|
@ -45,7 +45,15 @@ impl<'a> DocumentCache<'a> {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
start_lsp_thread();
|
||||
std::thread::spawn(|| {
|
||||
match run_lsp_server() {
|
||||
Ok(_) => {}
|
||||
Err(error) => {
|
||||
eprintln!("Error running LSP server: {}", error);
|
||||
}
|
||||
}
|
||||
preview::quit_ui_event_loop();
|
||||
});
|
||||
// TODO: Don't terminate the event loop when the window is closed with Qt
|
||||
// TODO: There's a race condition where theoretically the LSP could receive a preview
|
||||
// request before the gui event loop has started, which would cause post_event to panic.
|
||||
|
@ -54,8 +62,7 @@ fn main() {
|
|||
preview::start_ui_event_loop();
|
||||
}
|
||||
|
||||
fn start_lsp_thread() {
|
||||
std::thread::spawn(|| {
|
||||
fn run_lsp_server() -> Result<(), Error> {
|
||||
let (connection, io_threads) = Connection::stdio();
|
||||
let capabilities = ServerCapabilities {
|
||||
completion_provider: Some(CompletionOptions {
|
||||
|
@ -75,11 +82,10 @@ fn start_lsp_thread() {
|
|||
..ServerCapabilities::default()
|
||||
};
|
||||
let server_capabilities = serde_json::to_value(&capabilities).unwrap();
|
||||
let initialization_params = connection.initialize(server_capabilities).unwrap();
|
||||
main_loop(&connection, initialization_params).unwrap();
|
||||
io_threads.join().unwrap();
|
||||
// TODO: notify the gui thread to gracefully terminate the event loop
|
||||
});
|
||||
let initialization_params = connection.initialize(server_capabilities)?;
|
||||
main_loop(&connection, initialization_params)?;
|
||||
io_threads.join()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main_loop(connection: &Connection, params: serde_json::Value) -> Result<(), Error> {
|
||||
|
|
|
@ -49,6 +49,12 @@ pub fn start_ui_event_loop() {
|
|||
sixtyfps_interpreter::run_event_loop();
|
||||
}
|
||||
|
||||
pub fn quit_ui_event_loop() {
|
||||
sixtyfps_rendering_backend_default::backend().post_event(Box::new(|| {
|
||||
sixtyfps_rendering_backend_default::backend().quit_event_loop();
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn load_preview(path: std::path::PathBuf) {
|
||||
run_in_ui_thread(Box::pin(async move { reload_preview(&path).await }));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue