From 942b2aaca57880152877a34006b30d2e982dec00 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 1 Mar 2024 21:25:38 -0500 Subject: [PATCH] fix(lsp): output more information on error (#22665) --- cli/lsp/language_server.rs | 82 ++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 1c0a134d9e..b565246290 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -327,7 +327,7 @@ impl LanguageServer { if let Some(lockfile) = cli_options.maybe_lockfile() { let lockfile = lockfile.lock(); if let Err(err) = lockfile.write() { - lsp_warn!("Error writing lockfile: {}", err); + lsp_warn!("Error writing lockfile: {:#}", err); } } @@ -340,6 +340,7 @@ impl LanguageServer { match inner.prepare_cache(specifiers, referrer, force_global_cache) { Ok(maybe_cache_result) => maybe_cache_result, Err(err) => { + lsp_warn!("Error preparing caching: {:#}", err); self .0 .read() @@ -358,6 +359,7 @@ impl LanguageServer { create_graph_for_caching(cli_options, roots, open_docs).await }); if let Err(err) = handle.await.unwrap() { + lsp_warn!("Error caching: {:#}", err); self .0 .read() @@ -444,7 +446,7 @@ impl LanguageServer { ) .map_err(|err| { error!( - "Failed to serialize virtual_text_document response: {}", + "Failed to serialize virtual_text_document response: {:#}", err ); LspError::internal_error() @@ -885,7 +887,7 @@ impl Inner { let deno_dir = match DenoDir::new(self.maybe_global_cache_path.clone()) { Ok(deno_dir) => deno_dir, Err(err) => { - lsp_warn!("Error getting deno dir: {}", err); + lsp_warn!("Error getting deno dir: {:#}", err); return; } }; @@ -1067,7 +1069,7 @@ impl Inner { if let Err(err) = ls.cache(specifiers, referrer, false).await { - lsp_warn!("{}", err); + lsp_warn!("{:#}", err); } }); })); @@ -1110,6 +1112,7 @@ impl Inner { "useUnknownInCatchVariables": false, })); if let Err(err) = self.merge_user_tsconfig(&mut tsconfig) { + lsp_warn!("Error merging tsconfig: {:#}", err); self.client.show_message(MessageType::WARNING, err); } let _ok = self.ts_server.configure(self.snapshot(), tsconfig).await?; @@ -1260,15 +1263,19 @@ impl Inner { self.update_debug_flag(); // Check to see if we need to change the cache path if let Err(err) = self.update_cache().await { + lsp_warn!("Error updating cache: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_config_file().await { + lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_package_json() { + lsp_warn!("Error updating package.json: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_tsconfig().await { + lsp_warn!("Error updating tsconfig: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1282,10 +1289,12 @@ impl Inner { // Check to see if we need to setup the import map if let Err(err) = self.update_import_map().await { + lsp_warn!("Error updating import map: {:#}", err); self.client.show_message(MessageType::WARNING, err); } // Check to see if we need to setup any module registries if let Err(err) = self.update_registries().await { + lsp_warn!("Error updating registries: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1340,7 +1349,7 @@ impl Inner { .language_id .parse() .unwrap_or_else(|err| { - error!("{}", err); + error!("{:#}", err); LanguageId::Unknown }); if language_id == LanguageId::Unknown { @@ -1381,7 +1390,7 @@ impl Inner { self.send_testing_update(); } } - Err(err) => error!("{}", err), + Err(err) => error!("{:#}", err), } self.performance.measure(mark); } @@ -1425,7 +1434,7 @@ impl Inner { self.send_testing_update(); } if let Err(err) = self.documents.close(&specifier) { - error!("{}", err); + error!("{:#}", err); } self.performance.measure(mark); } @@ -1451,21 +1460,27 @@ impl Inner { self.update_debug_flag(); if let Err(err) = self.update_cache().await { + lsp_warn!("Error updating cache: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_registries().await { + lsp_warn!("Error updating registries: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_config_file().await { + lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_package_json() { + lsp_warn!("Error updating package.json: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_import_map().await { + lsp_warn!("Error updating import map: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Err(err) = self.update_tsconfig().await { + lsp_warn!("Error updating tsconfig: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1571,6 +1586,7 @@ impl Inner { } // Update config. if let Err(err) = self.update_config_file().await { + lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } // Collect new config specifiers. @@ -1599,6 +1615,7 @@ impl Inner { ); } if let Err(err) = self.update_tsconfig().await { + lsp_warn!("Error updating tsconfig: {:#}", err); self.client.show_message(MessageType::WARNING, err); } touched = true; @@ -1614,6 +1631,7 @@ impl Inner { files_to_check.insert(package_json.specifier()); } if let Err(err) = self.update_package_json() { + lsp_warn!("Error updating package.json: {:#}", err); self.client.show_message(MessageType::WARNING, err); } if let Some(package_json) = &self.maybe_package_json { @@ -1657,6 +1675,7 @@ impl Inner { .unwrap_or(false); if touched || import_map_changed { if let Err(err) = self.update_import_map().await { + lsp_warn!("Error updating import map: {:#}", err); self.client.show_message(MessageType::WARNING, err); } touched = true; @@ -1722,7 +1741,7 @@ impl Inner { let navigation_tree = self.get_navigation_tree(&specifier).await.map_err(|err| { error!( - "Error getting document symbols for \"{}\": {}", + "Error getting document symbols for \"{}\": {:#}", specifier, err ); LspError::internal_error() @@ -1766,7 +1785,7 @@ impl Inner { specifier = params.text_document.uri.clone(); } let file_path = specifier_to_file_path(&specifier).map_err(|err| { - error!("{}", err); + error!("{:#}", err); LspError::invalid_request() })?; let mark = self.performance.mark_with_args("lsp.formatting", ¶ms); @@ -1780,7 +1799,7 @@ impl Inner { Some(Ok(parsed_source)) => { format_parsed_source(&parsed_source, &fmt_options) } - Some(Err(err)) => Err(anyhow!("{}", err)), + Some(Err(err)) => Err(anyhow!("{:#}", err)), None => { // the file path is only used to determine what formatter should // be used to format the file, so give the filepath an extension @@ -1978,7 +1997,7 @@ impl Inner { code_actions .add_ts_fix_action(&specifier, &action, diagnostic, self) .map_err(|err| { - error!("Unable to convert fix: {}", err); + error!("Unable to convert fix: {:#}", err); LspError::internal_error() })?; if code_actions.is_fix_all_action( @@ -2004,7 +2023,7 @@ impl Inner { code_actions .add_deno_fix_action(&specifier, diagnostic) .map_err(|err| { - error!("{}", err); + error!("{:#}", err); LspError::internal_error() })? } @@ -2016,7 +2035,7 @@ impl Inner { asset_or_doc.maybe_parsed_source().and_then(|r| r.ok()), ) .map_err(|err| { - error!("Unable to fix lint error: {}", err); + error!("Unable to fix lint error: {:#}", err); LspError::internal_error() })?, _ => (), @@ -2111,7 +2130,7 @@ impl Inner { { let code_action_data: CodeActionData = from_value(data).map_err(|err| { - error!("Unable to decode code action data: {}", err); + error!("Unable to decode code action data: {:#}", err); LspError::invalid_params("The CodeAction's data is invalid.") })?; let combined_code_actions = self @@ -2139,7 +2158,7 @@ impl Inner { &self.get_ts_response_import_mapper(), ) .map_err(|err| { - error!("Unable to remap changes: {}", err); + error!("Unable to remap changes: {:#}", err); LspError::internal_error() })? } else { @@ -2147,7 +2166,7 @@ impl Inner { }; let mut code_action = params; code_action.edit = ts_changes_to_edit(&changes, self).map_err(|err| { - error!("Unable to convert changes to edits: {}", err); + error!("Unable to convert changes to edits: {:#}", err); LspError::internal_error() })?; code_action @@ -2155,7 +2174,7 @@ impl Inner { let mut code_action = params; let action_data: refactor::RefactorCodeActionData = from_value(data) .map_err(|err| { - error!("Unable to decode code action data: {}", err); + error!("Unable to decode code action data: {:#}", err); LspError::invalid_params("The CodeAction's data is invalid.") })?; let asset_or_doc = self.get_asset_or_document(&action_data.specifier)?; @@ -2222,7 +2241,7 @@ impl Inner { code_lens::collect_test(&specifier, parsed_source).map_err( |err| { error!( - "Error getting test code lenses for \"{}\": {}", + "Error getting test code lenses for \"{}\": {:#}", &specifier, err ); LspError::internal_error() @@ -2234,7 +2253,7 @@ impl Inner { if settings.code_lens.implementations || settings.code_lens.references { let navigation_tree = self.get_navigation_tree(&specifier).await.map_err(|err| { - error!("Error getting code lenses for \"{}\": {}", specifier, err); + error!("Error getting code lenses for \"{}\": {:#}", specifier, err); LspError::internal_error() })?; let line_index = asset_or_doc.line_index(); @@ -2248,7 +2267,7 @@ impl Inner { .await .map_err(|err| { error!( - "Error getting ts code lenses for \"{}\": {}", + "Error getting ts code lenses for \"{:#}\": {:#}", &specifier, err ); LspError::internal_error() @@ -2274,7 +2293,7 @@ impl Inner { code_lens::resolve_code_lens(code_lens, self) .await .map_err(|err| { - error!("Error resolving code lens: {}", err); + error!("Error resolving code lens: {:#}", err); LspError::internal_error() }) } else { @@ -2572,7 +2591,7 @@ impl Inner { let completion_item = if let Some(data) = ¶ms.data { let data: completions::CompletionItemData = serde_json::from_value(data.clone()).map_err(|err| { - error!("{}", err); + error!("{:#}", err); LspError::invalid_params( "Could not decode data field of completion item.", ) @@ -2603,7 +2622,7 @@ impl Inner { .as_completion_item(¶ms, data, specifier, self) .map_err(|err| { error!( - "Failed to serialize virtual_text_document response: {}", + "Failed to serialize virtual_text_document response: {:#}", err ); LspError::internal_error() @@ -2616,7 +2635,7 @@ impl Inner { } } Err(err) => { - error!("Unable to get completion info from TypeScript: {}", err); + error!("Unable to get completion info from TypeScript: {:#}", err); return Ok(params); } } @@ -2911,7 +2930,7 @@ impl Inner { .into_workspace_edit(¶ms.new_name, self) .await .map_err(|err| { - error!("Failed to get workspace edits: {}", err); + error!("Failed to get workspace edits: {:#}", err); LspError::internal_error() })?; self.performance.measure(mark); @@ -3170,7 +3189,7 @@ impl Inner { url_map: self.url_map.clone(), }; if let Err(err) = self.diagnostics_server.update(snapshot) { - error!("Cannot update diagnostics: {}", err); + error!("Cannot update diagnostics: {:#}", err); } } @@ -3179,7 +3198,7 @@ impl Inner { fn send_testing_update(&self) { if let Some(testing_server) = &self.maybe_testing_server { if let Err(err) = testing_server.update(self.snapshot()) { - error!("Cannot update testing server: {}", err); + error!("Cannot update testing server: {:#}", err); } } } @@ -3321,6 +3340,7 @@ impl tower_lsp::LanguageServer for LanguageServer { let mut ls = self.0.write().await; init_log_file(ls.config.log_file()); if let Err(err) = ls.update_tsconfig().await { + lsp_warn!("Error updating tsconfig: {:#}", err); ls.client.show_message(MessageType::WARNING, err); } ls.refresh_documents_config().await; @@ -3407,7 +3427,7 @@ impl tower_lsp::LanguageServer for LanguageServer { specifier }; if let Err(err) = self.cache(vec![], specifier.clone(), false).await { - lsp_warn!("Failed to cache \"{}\" on save: {}", &specifier, err); + lsp_warn!("Failed to cache \"{}\" on save: {:#}", &specifier, err); } } @@ -3769,7 +3789,7 @@ impl Inner { let text_span = tsc::TextSpan::from_range(¶ms.range, line_index.clone()).map_err( |err| { - error!("Failed to convert range to text_span: {}", err); + error!("Failed to convert range to text_span: {:#}", err); LspError::internal_error() }, )?; @@ -3800,11 +3820,11 @@ impl Inner { remove_dir_all_if_exists(&self.module_registries_location) .await .map_err(|err| { - error!("Unable to remove registries cache: {}", err); + error!("Unable to remove registries cache: {:#}", err); LspError::internal_error() })?; self.update_registries().await.map_err(|err| { - error!("Unable to update registries: {}", err); + error!("Unable to update registries: {:#}", err); LspError::internal_error() })?; Ok(Some(json!(true)))