From 9c7ed1c98b75c3557ac9e269212dcf655f69c0a2 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Mon, 7 Feb 2022 10:39:07 +1100 Subject: fix(lsp): op_exists handles bad specifiers (#13612) Fixes: #13611 --- cli/lsp/tsc.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 28a3e7583..71606a05b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2396,7 +2396,13 @@ fn op_exists(state: &mut State, args: SpecifierArgs) -> Result { // forrest for the trees as well as it compounds any lsp performance // challenges, opening a single document in the editor causes some 3k worth // of op_exists requests... :omg: - let specifier = state.normalize_specifier(args.specifier)?; + let specifier = match state.normalize_specifier(&args.specifier) { + Ok(url) => url, + // sometimes tsc tries to query invalid specifiers, especially when + // something else isn't quite right, so instead of bubbling up the error + // back to tsc, we simply swallow it and say the file doesn't exist + Err(err) => return Ok(false), + }; let result = state.state_snapshot.documents.exists(&specifier); Ok(result) } @@ -3673,6 +3679,31 @@ mod tests { ); } + #[test] + fn test_op_exists() { + let (_, state_snapshot, _) = setup( + false, + json!({ + "target": "esnext", + "module": "esnext", + "lib": ["deno.ns", "deno.window"], + "noEmit": true, + }), + &[], + ); + let performance = Arc::new(Performance::default()); + let mut state = State::new(state_snapshot, performance); + let actual = op_exists( + &mut state, + SpecifierArgs { + specifier: "/error/unknown:something/index.d.ts".to_string(), + }, + ); + assert!(actual.is_ok()); + let actual = actual.unwrap(); + assert!(!actual); + } + #[test] fn test_completion_entry_filter_text() { let fixture = CompletionEntry { -- cgit v1.2.3