From 633c5aab1f28538dde619fe755f8ec9fa77a3719 Mon Sep 17 00:00:00 2001 From: jeiea Date: Sun, 6 Jun 2021 14:00:17 +0900 Subject: fix(#10747): cannot read config option in windows (#10791) Fixes #10747 --- cli/tests/integration_tests_lsp.rs | 62 +++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'cli/tests/integration_tests_lsp.rs') diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs index 10797a326..b6d9cde54 100644 --- a/cli/tests/integration_tests_lsp.rs +++ b/cli/tests/integration_tests_lsp.rs @@ -31,7 +31,10 @@ fn init(init_path: &str) -> LspClient { client } -fn did_open(client: &mut LspClient, params: V) +fn did_open( + client: &mut LspClient, + params: V, +) -> Vec where V: Serialize, { @@ -45,12 +48,16 @@ where .write_response(id, json!({ "enable": true })) .unwrap(); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); + let mut diagnostics = vec![]; + for _ in 0..3 { + let (method, response) = client + .read_notification::() + .unwrap(); + assert_eq!(method, "textDocument/publishDiagnostics"); + diagnostics.push(response.unwrap()); + } + + diagnostics } fn shutdown(client: &mut LspClient) { @@ -66,6 +73,47 @@ fn lsp_startup_shutdown() { shutdown(&mut client); } +#[test] +fn lsp_init_tsconfig() { + let temp_dir = TempDir::new().expect("could not create temp dir"); + let mut params: lsp::InitializeParams = + serde_json::from_value(load_fixture("initialize_params.json")).unwrap(); + let tsconfig = + serde_json::to_vec_pretty(&load_fixture("lib.tsconfig.json")).unwrap(); + fs::write(temp_dir.path().join("lib.tsconfig.json"), tsconfig).unwrap(); + + params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap()); + if let Some(Value::Object(mut map)) = params.initialization_options { + map.insert("config".to_string(), json!("./lib.tsconfig.json")); + params.initialization_options = Some(Value::Object(map)); + } + + let deno_exe = deno_exe_path(); + let mut client = LspClient::new(&deno_exe).unwrap(); + client + .write_request::<_, _, Value>("initialize", params) + .unwrap(); + + client.write_notification("initialized", json!({})).unwrap(); + + let diagnostics = did_open( + &mut client, + json!({ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "location.pathname;\n" + } + }), + ); + + let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics); + assert_eq!(diagnostics.count(), 0); + + shutdown(&mut client); +} + #[test] fn lsp_hover() { let mut client = init("initialize_params.json"); -- cgit v1.2.3