From c22ff197dbcbf3fb589bb5dfcf0c4fdc3d72f0a0 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 21 Aug 2024 20:00:23 +0100 Subject: fix(lsp): resolve jsx import source with types mode (#25064) --- tests/integration/lsp_tests.rs | 60 ++++++++++++++++++++++++++++++++++++++++++ tests/util/server/src/lsp.rs | 2 ++ 2 files changed, 62 insertions(+) (limited to 'tests') diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 02a4bfeea..fd6f7e484 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -11724,6 +11724,66 @@ fn lsp_jsx_import_source_config_file_automatic_cache() { client.shutdown(); } +#[test] +fn lsp_jsx_import_source_byonm_preact() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .add_npm_env_vars() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "deno.json", + json!({ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "npm:preact@^10.19.6" + }, + "unstable": ["byonm"], + }) + .to_string(), + ); + temp_dir.write( + "package.json", + json!({ + "dependencies": { + "preact": "^10.19.6", + }, + }) + .to_string(), + ); + let file = source_file(temp_dir.path().join("file.tsx"), r#"
;"#); + context.run_npm("install"); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let diagnostics = client.did_open_file(&file); + assert_eq!(json!(diagnostics.all()), json!([])); + let res = client.write_request( + "textDocument/hover", + json!({ + "textDocument": { "uri": file.uri() }, + "position": { "line": 0, "character": 1 }, + }), + ); + assert_eq!( + res, + json!({ + "contents": [ + { + "language": "typescript", + "value": "(property) JSXInternal.IntrinsicElements.div: JSXInternal.HTMLAttributes", + }, + "", + ], + "range": { + "start": { "line": 0, "character": 1 }, + "end": { "line": 0, "character": 4 }, + }, + }), + ); + client.shutdown(); +} + #[test] fn lsp_jsx_import_source_types_pragma() { let context = TestContextBuilder::new() diff --git a/tests/util/server/src/lsp.rs b/tests/util/server/src/lsp.rs index b615ed475..85879d9d8 100644 --- a/tests/util/server/src/lsp.rs +++ b/tests/util/server/src/lsp.rs @@ -1301,6 +1301,8 @@ impl SourceFile { let lang = match path.as_path().extension().unwrap().to_str().unwrap() { "js" => "javascript", "ts" | "d.ts" => "typescript", + "jsx" => "javascriptreact", + "tsx" => "typescriptreact", "json" => "json", "md" => "markdown", other => panic!("unsupported file extension: {other}"), -- cgit v1.2.3