mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
reduce panics
This commit is contained in:
parent
db97e3ed22
commit
712d648cf0
2 changed files with 19 additions and 8 deletions
|
@ -74,7 +74,8 @@ impl Registry {
|
|||
if &document.doc_info.url == updating_url {
|
||||
//Write the newly analysed document into the oncelock that any request requiring the latest document will be waiting on
|
||||
if let Some(a) = documents.get_mut(updating_url) {
|
||||
a.latest_document.set(document.clone()).unwrap()
|
||||
//We don't care if this fails becasue we expect the document to sometimes alreday be there
|
||||
a.latest_document.set(document.clone()).unwrap_or(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use analysis::HIGHLIGHT_TOKENS_LEGEND;
|
|||
use log::{debug, trace};
|
||||
use registry::{Registry, RegistryConfig};
|
||||
use std::future::Future;
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
use std::time::Duration;
|
||||
|
||||
use tower_lsp::jsonrpc::{self, Result};
|
||||
|
@ -173,10 +173,17 @@ impl RocServerState {
|
|||
return Err("Not latest version skipping analysis".to_string());
|
||||
}
|
||||
|
||||
let results = match tokio::task::spawn_blocking(|| global_analysis(doc_info)).await {
|
||||
Err(e) => return Err(format!("Document analysis failed. reason:{:?}", e)),
|
||||
Ok(a) => a,
|
||||
};
|
||||
let results =
|
||||
match tokio::task::spawn_blocking(|| catch_unwind(|| global_analysis(doc_info)))
|
||||
.await
|
||||
{
|
||||
Err(e) => {
|
||||
return Err(format!("Document analysis thread failed. reason:{:?}", e))
|
||||
}
|
||||
Ok(res) => {
|
||||
res.map_err(|err| format!("Document analysis panicked with: {:?}", err))?
|
||||
}
|
||||
};
|
||||
let latest_version = inner_ref.registry.get_latest_version(fi).await;
|
||||
|
||||
//if this version is not the latest another change must have come in and this analysis is useless
|
||||
|
@ -230,8 +237,11 @@ impl LanguageServer for RocServer {
|
|||
|
||||
// NOTE: We specify that we expect full-content syncs in the server capabilities,
|
||||
// so here we assume the only change passed is a change of the entire document's content.
|
||||
let TextDocumentContentChangeEvent { text, .. } =
|
||||
params.content_changes.into_iter().next().unwrap();
|
||||
let TextDocumentContentChangeEvent { text, .. } = params
|
||||
.content_changes
|
||||
.into_iter()
|
||||
.last()
|
||||
.expect("textDocument change event had no changes ");
|
||||
|
||||
self.change(uri, text, version).await;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue