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

fix(lsp): output more information on error (#22665)

This commit is contained in:
David Sherret 2024-03-01 21:25:38 -05:00 committed by GitHub
parent 0973e8e859
commit 942b2aaca5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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