mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-22 16:22:17 +00:00
lsp: No error when sending messages to the Preview fails
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
The live-preview can get killed at any moment, so do not fail if sending messages to it fails.
This commit is contained in:
parent
bdb323754e
commit
017e02e623
6 changed files with 55 additions and 74 deletions
|
@ -42,7 +42,7 @@ pub enum PreviewTarget {
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait LspToPreview {
|
pub trait LspToPreview {
|
||||||
fn send(&self, message: &LspToPreviewMessage) -> Result<()>;
|
fn send(&self, message: &LspToPreviewMessage);
|
||||||
fn set_preview_target(&self, target: PreviewTarget) -> Result<()>;
|
fn set_preview_target(&self, target: PreviewTarget) -> Result<()>;
|
||||||
fn preview_target(&self) -> PreviewTarget;
|
fn preview_target(&self) -> PreviewTarget;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,7 @@ pub trait LspToPreview {
|
||||||
pub struct DummyLspToPreview {}
|
pub struct DummyLspToPreview {}
|
||||||
|
|
||||||
impl LspToPreview for DummyLspToPreview {
|
impl LspToPreview for DummyLspToPreview {
|
||||||
fn send(&self, _message: &LspToPreviewMessage) -> Result<()> {
|
fn send(&self, _message: &LspToPreviewMessage) {}
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn preview_target(&self) -> PreviewTarget {
|
fn preview_target(&self) -> PreviewTarget {
|
||||||
PreviewTarget::Dummy
|
PreviewTarget::Dummy
|
||||||
|
|
|
@ -34,6 +34,7 @@ use lsp_types::{
|
||||||
SemanticTokensOptions, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextEdit,
|
SemanticTokensOptions, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextEdit,
|
||||||
Url, WorkDoneProgressOptions,
|
Url, WorkDoneProgressOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
@ -90,22 +91,18 @@ pub fn request_state(ctx: &std::rc::Rc<Context>) {
|
||||||
}
|
}
|
||||||
let version = document_cache.document_version(&url);
|
let version = document_cache.document_version(&url);
|
||||||
|
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::SetContents {
|
||||||
.send(&common::LspToPreviewMessage::SetContents {
|
|
||||||
url: common::VersionedUrl::new(url, version),
|
url: common::VersionedUrl::new(url, version),
|
||||||
contents: node.text().to_string(),
|
contents: node.text().to_string(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::SetConfiguration {
|
||||||
.send(&common::LspToPreviewMessage::SetConfiguration {
|
|
||||||
config: ctx.preview_config.borrow().clone(),
|
config: ctx.preview_config.borrow().clone(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Some(c) = ctx.to_show.borrow().clone() {
|
if let Some(c) = ctx.to_show.borrow().clone() {
|
||||||
ctx.to_preview.send(&common::LspToPreviewMessage::ShowPreview(c)).unwrap();
|
ctx.to_preview.send(&common::LspToPreviewMessage::ShowPreview(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,12 +428,10 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
{
|
{
|
||||||
let element = gp.as_ref().unwrap().child_node(SyntaxKind::Element).unwrap();
|
let element = gp.as_ref().unwrap().child_node(SyntaxKind::Element).unwrap();
|
||||||
|
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
||||||
.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
|
||||||
url: Some(uri),
|
url: Some(uri),
|
||||||
offset: element.text_range().start().into(),
|
offset: element.text_range().start().into(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let range = util::node_to_lsp_range(&p);
|
let range = util::node_to_lsp_range(&p);
|
||||||
return Ok(Some(vec![lsp_types::DocumentHighlight { range, kind: None }]));
|
return Ok(Some(vec![lsp_types::DocumentHighlight { range, kind: None }]));
|
||||||
|
@ -454,23 +449,19 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|n| n.kind() != SyntaxKind::Component)
|
.is_some_and(|n| n.kind() != SyntaxKind::Component)
|
||||||
{
|
{
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
||||||
.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
|
||||||
url: Some(uri),
|
url: Some(uri),
|
||||||
offset: gp.unwrap().text_range().start().into(),
|
offset: gp.unwrap().text_range().start().into(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
return Ok(Some(vec![lsp_types::DocumentHighlight { range, kind: None }]));
|
return Ok(Some(vec![lsp_types::DocumentHighlight { range, kind: None }]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value) = common::rename_element_id::find_element_ids(&tk, &p) {
|
if let Some(value) = common::rename_element_id::find_element_ids(&tk, &p) {
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
||||||
.send(&common::LspToPreviewMessage::HighlightFromEditor {
|
|
||||||
url: None,
|
url: None,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
return Ok(Some(
|
return Ok(Some(
|
||||||
value
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -483,8 +474,7 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.to_preview
|
ctx.to_preview
|
||||||
.send(&common::LspToPreviewMessage::HighlightFromEditor { url: None, offset: 0 })
|
.send(&common::LspToPreviewMessage::HighlightFromEditor { url: None, offset: 0 });
|
||||||
.unwrap();
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
});
|
});
|
||||||
rh.register::<Rename, _>(|params, ctx| async move {
|
rh.register::<Rename, _>(|params, ctx| async move {
|
||||||
|
@ -580,7 +570,7 @@ pub fn show_preview_command(
|
||||||
|
|
||||||
let c = common::PreviewComponent { url, component };
|
let c = common::PreviewComponent { url, component };
|
||||||
ctx.to_show.replace(Some(c.clone()));
|
ctx.to_show.replace(Some(c.clone()));
|
||||||
ctx.to_preview.send(&common::LspToPreviewMessage::ShowPreview(c)).unwrap();
|
ctx.to_preview.send(&common::LspToPreviewMessage::ShowPreview(c));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -742,12 +732,10 @@ pub(crate) async fn reload_document_impl(
|
||||||
let dependencies = match action {
|
let dependencies = match action {
|
||||||
FileAction::ProcessContent(content) => {
|
FileAction::ProcessContent(content) => {
|
||||||
if let Some(ctx) = ctx {
|
if let Some(ctx) = ctx {
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::SetContents {
|
||||||
.send(&common::LspToPreviewMessage::SetContents {
|
|
||||||
url: common::VersionedUrl::new(url.clone(), version),
|
url: common::VersionedUrl::new(url.clone(), version),
|
||||||
contents: content.clone(),
|
contents: content.clone(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
let dependencies = document_cache.invalidate_url(&url);
|
let dependencies = document_cache.invalidate_url(&url);
|
||||||
let _ = document_cache.load_url(&url, version, content, &mut diag).await;
|
let _ = document_cache.load_url(&url, version, content, &mut diag).await;
|
||||||
|
@ -756,9 +744,7 @@ pub(crate) async fn reload_document_impl(
|
||||||
FileAction::IgnoreFile => return Default::default(),
|
FileAction::IgnoreFile => return Default::default(),
|
||||||
FileAction::InvalidateFile => {
|
FileAction::InvalidateFile => {
|
||||||
if let Some(ctx) = ctx {
|
if let Some(ctx) = ctx {
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::ForgetFile { url: url.clone() });
|
||||||
.send(&common::LspToPreviewMessage::ForgetFile { url: url.clone() })
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
document_cache.invalidate_url(&url)
|
document_cache.invalidate_url(&url)
|
||||||
}
|
}
|
||||||
|
@ -854,16 +840,14 @@ fn send_diagnostics(
|
||||||
|
|
||||||
pub async fn invalidate_document(ctx: &Rc<Context>, url: lsp_types::Url) -> common::Result<()> {
|
pub async fn invalidate_document(ctx: &Rc<Context>, url: lsp_types::Url) -> common::Result<()> {
|
||||||
// The preview cares about resources and slint files, so forward everything
|
// The preview cares about resources and slint files, so forward everything
|
||||||
ctx.to_preview
|
ctx.to_preview.send(&common::LspToPreviewMessage::InvalidateContents { url: url.clone() });
|
||||||
.send(&common::LspToPreviewMessage::InvalidateContents { url: url.clone() })
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
ctx.document_cache.borrow_mut().drop_document(&url)
|
ctx.document_cache.borrow_mut().drop_document(&url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_document(ctx: &Rc<Context>, url: lsp_types::Url) -> common::Result<()> {
|
pub async fn delete_document(ctx: &Rc<Context>, url: lsp_types::Url) -> common::Result<()> {
|
||||||
// The preview cares about resources and slint files, so forward everything
|
// The preview cares about resources and slint files, so forward everything
|
||||||
ctx.to_preview.send(&common::LspToPreviewMessage::ForgetFile { url: url.clone() }).unwrap();
|
ctx.to_preview.send(&common::LspToPreviewMessage::ForgetFile { url: url.clone() });
|
||||||
|
|
||||||
ctx.document_cache.borrow_mut().drop_document(&url)
|
ctx.document_cache.borrow_mut().drop_document(&url)
|
||||||
}
|
}
|
||||||
|
@ -1456,7 +1440,7 @@ pub async fn load_configuration(ctx: &Context) -> common::Result<()> {
|
||||||
document_cache.reload_cached_file(url, &mut diag).await;
|
document_cache.reload_cached_file(url, &mut diag).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.to_preview.send(&common::LspToPreviewMessage::SetConfiguration { config }).unwrap();
|
ctx.to_preview.send(&common::LspToPreviewMessage::SetConfiguration { config });
|
||||||
|
|
||||||
send_diagnostics(
|
send_diagnostics(
|
||||||
&ctx.server_notifier,
|
&ctx.server_notifier,
|
||||||
|
|
|
@ -342,14 +342,12 @@ fn main_loop(connection: Connection, init_param: InitializeParams, cli_args: Cli
|
||||||
let contents = std::fs::read_to_string(&path);
|
let contents = std::fs::read_to_string(&path);
|
||||||
if let Ok(url) = Url::from_file_path(&path) {
|
if let Ok(url) = Url::from_file_path(&path) {
|
||||||
if let Ok(contents) = &contents {
|
if let Ok(contents) = &contents {
|
||||||
to_preview
|
to_preview.send(&common::LspToPreviewMessage::SetContents {
|
||||||
.send(&common::LspToPreviewMessage::SetContents {
|
|
||||||
url: common::VersionedUrl::new(url, None),
|
url: common::VersionedUrl::new(url, None),
|
||||||
contents: contents.clone(),
|
contents: contents.clone(),
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
} else {
|
} else {
|
||||||
to_preview.send(&common::LspToPreviewMessage::ForgetFile { url }).unwrap();
|
to_preview.send(&common::LspToPreviewMessage::ForgetFile { url });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(contents.map(|c| (None, c)))
|
Some(contents.map(|c| (None, c)))
|
||||||
|
|
|
@ -105,16 +105,17 @@ impl Drop for ChildProcessLspToPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl common::LspToPreview for ChildProcessLspToPreview {
|
impl common::LspToPreview for ChildProcessLspToPreview {
|
||||||
fn send(&self, message: &common::LspToPreviewMessage) -> common::Result<()> {
|
fn send(&self, message: &common::LspToPreviewMessage) {
|
||||||
if self.preview_is_running() {
|
if self.preview_is_running() {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
let inner = inner.as_mut().unwrap();
|
let inner = inner.as_mut().unwrap();
|
||||||
let message = serde_json::to_string(message).map_err(|e| e.to_string())?;
|
let Ok(message) = serde_json::to_string(message) else {
|
||||||
writeln!(inner.to_child, "{message}")?;
|
return;
|
||||||
|
};
|
||||||
|
let _ = writeln!(inner.to_child, "{message}");
|
||||||
} else if let common::LspToPreviewMessage::ShowPreview(_) = message {
|
} else if let common::LspToPreviewMessage::ShowPreview(_) = message {
|
||||||
self.start_preview().unwrap();
|
self.start_preview().unwrap();
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview_target(&self) -> common::PreviewTarget {
|
fn preview_target(&self) -> common::PreviewTarget {
|
||||||
|
@ -137,8 +138,9 @@ impl EmbeddedLspToPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl common::LspToPreview for EmbeddedLspToPreview {
|
impl common::LspToPreview for EmbeddedLspToPreview {
|
||||||
fn send(&self, message: &common::LspToPreviewMessage) -> common::Result<()> {
|
fn send(&self, message: &common::LspToPreviewMessage) {
|
||||||
self.server_notifier.send_notification::<common::LspToPreviewMessage>(message.clone())
|
let _ =
|
||||||
|
self.server_notifier.send_notification::<common::LspToPreviewMessage>(message.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview_target(&self) -> common::PreviewTarget {
|
fn preview_target(&self) -> common::PreviewTarget {
|
||||||
|
@ -169,8 +171,8 @@ impl SwitchableLspToPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl common::LspToPreview for SwitchableLspToPreview {
|
impl common::LspToPreview for SwitchableLspToPreview {
|
||||||
fn send(&self, message: &common::LspToPreviewMessage) -> common::Result<()> {
|
fn send(&self, message: &common::LspToPreviewMessage) {
|
||||||
self.lsp_to_previews.get(&self.current_target.borrow()).unwrap().send(message)
|
let _ = self.lsp_to_previews.get(&self.current_target.borrow()).unwrap().send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview_target(&self) -> common::PreviewTarget {
|
fn preview_target(&self) -> common::PreviewTarget {
|
||||||
|
|
|
@ -240,8 +240,9 @@ impl WasmLspToPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl common::LspToPreview for WasmLspToPreview {
|
impl common::LspToPreview for WasmLspToPreview {
|
||||||
fn send(&self, message: &common::LspToPreviewMessage) -> common::Result<()> {
|
fn send(&self, message: &common::LspToPreviewMessage) {
|
||||||
self.server_notifier.send_notification::<common::LspToPreviewMessage>(message.clone())
|
let _ =
|
||||||
|
self.server_notifier.send_notification::<common::LspToPreviewMessage>(message.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview_target(&self) -> common::PreviewTarget {
|
fn preview_target(&self) -> common::PreviewTarget {
|
||||||
|
|
|
@ -202,12 +202,10 @@ pub fn create(
|
||||||
return Some(contents.map(|c| (None, c)));
|
return Some(contents.map(|c| (None, c)));
|
||||||
};
|
};
|
||||||
if let Ok(contents) = &contents {
|
if let Ok(contents) = &contents {
|
||||||
to_preview
|
to_preview.send(&LspToPreviewMessage::SetContents {
|
||||||
.send(&LspToPreviewMessage::SetContents {
|
|
||||||
url: VersionedUrl::new(url, None),
|
url: VersionedUrl::new(url, None),
|
||||||
contents: contents.clone(),
|
contents: contents.clone(),
|
||||||
})
|
});
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
Some(contents.map(|c| (None, c)))
|
Some(contents.map(|c| (None, c)))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue