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

fix(lsp): op_exists handles bad specifiers (#13612)

Fixes: #13611
This commit is contained in:
Kitson Kelly 2022-02-07 10:39:07 +11:00 committed by GitHub
parent d0dd838521
commit 9c7ed1c98b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2396,7 +2396,13 @@ fn op_exists(state: &mut State, args: SpecifierArgs) -> Result<bool, AnyError> {
// 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 {