Skip to content

Commit

Permalink
perf(lsp): check tsc request cancellation before execution (denoland#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Dec 3, 2023
1 parent 28c527c commit 0a738dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
36 changes: 6 additions & 30 deletions cli/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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:https:///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();
Expand Down
3 changes: 3 additions & 0 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0a738dc

Please sign in to comment.