1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

perf(lsp): check tsc request cancellation before execution (#21447)

This commit is contained in:
Nayeem Rahman 2023-12-03 22:07:40 +00:00 committed by GitHub
parent 28c527c8f5
commit 0a738dc49d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 30 deletions

View file

@ -502,7 +502,12 @@ impl DiagnosticsServer {
)
.await
.map_err(|err| {
error!("Error generating TypeScript diagnostics: {}", err);
if !token.is_cancelled() {
error!(
"Error generating TypeScript diagnostics: {}",
err
);
}
})
.unwrap_or_default();
@ -1615,35 +1620,6 @@ let c: number = "a";
.diagnostics
}
#[tokio::test]
async fn test_cancelled_ts_diagnostics_request() {
let temp_dir = TempDir::new();
let (snapshot, cache_location) = setup(
&temp_dir,
&[(
"file:///a.ts",
r#"export let a: string = 5;"#,
1,
LanguageId::TypeScript,
)],
None,
);
let snapshot = Arc::new(snapshot);
let cache =
Arc::new(GlobalHttpCache::new(cache_location, RealDenoCacheEnv));
let ts_server = TsServer::new(Default::default(), cache);
let config = mock_config();
let token = CancellationToken::new();
token.cancel();
let diagnostics =
generate_ts_diagnostics(snapshot.clone(), &config, &ts_server, token)
.await
.unwrap();
// should be none because it's cancelled
assert_eq!(diagnostics.len(), 0);
}
#[tokio::test]
async fn test_deno_diagnostics_with_import_map() {
let temp_dir = TempDir::new();

View file

@ -4414,6 +4414,9 @@ fn request(
request: TscRequest,
token: CancellationToken,
) -> Result<Value, AnyError> {
if token.is_cancelled() {
return Err(anyhow!("Operation was cancelled."));
}
let (performance, id) = {
let op_state = runtime.op_state();
let mut op_state = op_state.borrow_mut();