1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00

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))
}
} else {
let mut state_snapshot = self.snapshot();
if let Some(asset) =
tsc::get_asset(&specifier, &self.ts_server, &mut state_snapshot)
.await?
{
if let Some(asset) = self.get_asset(&specifier).await? {
Ok(asset.line_index)
} else {
Err(anyhow!("asset is missing: {}", specifier))
@ -508,6 +504,17 @@ impl Inner {
) -> Option<i32> {
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.
@ -1773,11 +1780,10 @@ impl Inner {
None
}
} else {
let mut state_snapshot = self.snapshot();
if let Some(asset) =
tsc::get_asset(&specifier, &self.ts_server, &mut state_snapshot)
.await
.map_err(|_| LspError::internal_error())?
if let Some(asset) = self
.get_asset(&specifier)
.await
.map_err(|_| LspError::internal_error())?
{
Some(asset.text)
} else {