fix(lsp): fix asset cache lookup regression

Commit 2828690fc ("fix(lsp): fix deadlocks, use one big mutex") from
last month introduced a regression in asset cache lookups where results
of lazy caching were lost due to operating on a copy of the asset cache.

This commit fixes that by copying the asset from the copy to the real
cache.
This commit is contained in:
Ben Noordhuis 2021-02-06 13:39:01 +01:00
parent be10db10fd
commit e7a7bf8a79

View file

@ -146,11 +146,7 @@ impl Inner {
Err(anyhow!("asset is missing: {}", specifier)) Err(anyhow!("asset is missing: {}", specifier))
} }
} else { } else {
let mut state_snapshot = self.snapshot(); if let Some(asset) = self.get_asset(&specifier).await? {
if let Some(asset) =
tsc::get_asset(&specifier, &self.ts_server, &mut state_snapshot)
.await?
{
Ok(asset.line_index) Ok(asset.line_index)
} else { } else {
Err(anyhow!("asset is missing: {}", specifier)) Err(anyhow!("asset is missing: {}", specifier))
@ -508,6 +504,17 @@ impl Inner {
) -> Option<i32> { ) -> Option<i32> {
self.documents.version(&specifier) self.documents.version(&specifier)
} }
async fn get_asset(
&mut self,
specifier: &ModuleSpecifier,
) -> Result<Option<AssetDocument>, AnyError> {
let mut state_snapshot = self.snapshot();
let maybe_asset =
tsc::get_asset(&specifier, &self.ts_server, &mut state_snapshot).await?;
self.assets.insert(specifier.clone(), maybe_asset.clone());
Ok(maybe_asset)
}
} }
// lspower::LanguageServer methods. This file's LanguageServer delegates to us. // lspower::LanguageServer methods. This file's LanguageServer delegates to us.
@ -1773,11 +1780,10 @@ impl Inner {
None None
} }
} else { } else {
let mut state_snapshot = self.snapshot(); if let Some(asset) = self
if let Some(asset) = .get_asset(&specifier)
tsc::get_asset(&specifier, &self.ts_server, &mut state_snapshot) .await
.await .map_err(|_| LspError::internal_error())?
.map_err(|_| LspError::internal_error())?
{ {
Some(asset.text) Some(asset.text)
} else { } else {