Skip to content

Commit

Permalink
live-preview: Do not fail to render when top level sources are not lo…
Browse files Browse the repository at this point in the history
…aded

Ths can open one file in VSCode and show the preview. Then you click
on another file in the file tree, which will replace the current file.

This replacement invalidates the data stored in the live-previews caches, so
it used to render an empty file. Read the data from disc instead -- if
that is an option.
  • Loading branch information
hunger committed Oct 16, 2024
1 parent 1112880 commit 9449f23
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools/lsp/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,13 @@ async fn reload_preview_impl(
start_parsing();

let path = component.url.to_file_path().unwrap_or(PathBuf::from(&component.url.to_string()));
let (version, source) = get_url_from_cache(&component.url).unwrap_or_default();
let (version, source) = get_url_from_cache(&component.url).unwrap_or_else(|| {
if cfg!(not(target_arch = "wasm32")) {
(None, std::fs::read_to_string(&path).unwrap_or_default())
} else {
(None, String::new())
}
});

let (diagnostics, compiled, open_import_fallback, source_file_versions) = parse_source(
config.include_paths,
Expand Down

0 comments on commit 9449f23

Please sign in to comment.