Skip to content

Commit

Permalink
fix(lsp): fix asset cache lookup regression
Browse files Browse the repository at this point in the history
Commit 2828690 ("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.
  • Loading branch information
bnoordhuis committed Feb 8, 2021
1 parent be10db1 commit e7a7bf8
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e7a7bf8

Please sign in to comment.