diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 0fa7f9d687..82ee2a0dd6 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -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 { self.documents.version(&specifier) } + + async fn get_asset( + &mut self, + specifier: &ModuleSpecifier, + ) -> Result, 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 {