Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Handle hover rustfmt panic
Browse files Browse the repository at this point in the history
* Enable logging in test_tooltip tests
  • Loading branch information
alexheretic committed Dec 10, 2018
1 parent ce886d2 commit 398f0d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,19 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
format!("{}{{}}", trimmed)
};

let formatted = match rustfmt.format(object.clone(), config) {
Ok(lines) => match lines.rfind('{') {
let formatted = match std::panic::catch_unwind(|| rustfmt.format(object.clone(), config)) {
Ok(Ok(lines)) => match lines.rfind('{') {
Some(pos) => lines[0..pos].into(),
None => lines,
},
Err(e) => {
Ok(Err(e)) => {
error!("format_object: error: {:?}, input: {:?}", e, object);
trimmed.to_string()
}
Err(_) => {
error!("format_object: rustfmt panicked on input: {:?}", object);
trimmed.to_string()
}
};

// If it's a tuple, remove the trailing ';' and hide non-pub components
Expand Down Expand Up @@ -2035,6 +2039,7 @@ pub mod test {

#[test]
fn test_tooltip() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};
use std::env;

Expand Down Expand Up @@ -2125,6 +2130,7 @@ pub mod test {
#[test]
#[ignore]
fn test_tooltip_std() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};
use std::env;

Expand Down

0 comments on commit 398f0d6

Please sign in to comment.