From 261f32ef651a6515fbac664302adcfbe34a04372 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 2 Jan 2024 23:48:34 +0000 Subject: feat(lsp): cache jsxImportSource automatically (#21687) --- cli/tests/integration/lsp_tests.rs | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 78aff93ab..e9a4db535 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -9469,6 +9469,61 @@ export function B() { client.shutdown(); } +#[test] +fn lsp_jsx_import_source_config_file_automatic_cache() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "deno.json", + json!({ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "http://localhost:4545/jsx", + }, + }) + .to_string(), + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let mut diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.tsx").unwrap(), + "languageId": "typescriptreact", + "version": 1, + "text": " + export function Foo() { + return
; + } + ", + }, + })); + // The caching is done on an asynchronous task spawned after init, so there's + // a chance it wasn't done in time and we need to wait for another batch of + // diagnostics. + while !diagnostics.all().is_empty() { + std::thread::sleep(std::time::Duration::from_millis(50)); + // The post-cache diagnostics update triggers inconsistently on CI for some + // reason. Force it with this notification. + diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.tsx").unwrap(), + "languageId": "typescriptreact", + "version": 1, + "text": " + export function Foo() { + return
; + } + ", + }, + })); + } + assert_eq!(diagnostics.all(), vec![]); + client.shutdown(); +} + #[derive(Debug, Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct TestData { -- cgit v1.2.3