diff --git a/kclvm/error/src/lib.rs b/kclvm/error/src/lib.rs index f805c3fcd..9fb127c15 100644 --- a/kclvm/error/src/lib.rs +++ b/kclvm/error/src/lib.rs @@ -125,18 +125,14 @@ impl Handler { } /// Construct a type error and put it into the handler diagnostic buffer - pub fn add_compile_error( - &mut self, - msg: &str, - range: Range - ) -> &mut Self { + pub fn add_compile_error(&mut self, msg: &str, range: Range) -> &mut Self { self.add_compile_error_with_suggestions(msg, range, None) } pub fn add_compile_error_with_suggestions( - &mut self, - msg: &str, - range: Range, + &mut self, + msg: &str, + range: Range, suggestions: Option>, ) -> &mut Self { let diag = Diagnostic::new_with_code( @@ -149,7 +145,7 @@ impl Handler { ); // println!("{:?}",suggestions.clone()); self.add_diagnostic(diag); - + self } diff --git a/kclvm/tools/src/LSP/src/quick_fix.rs b/kclvm/tools/src/LSP/src/quick_fix.rs index a46ba5408..1aa3f666c 100644 --- a/kclvm/tools/src/LSP/src/quick_fix.rs +++ b/kclvm/tools/src/LSP/src/quick_fix.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use kclvm_error::{DiagnosticId, WarningKind, ErrorKind}; +use kclvm_error::{DiagnosticId, ErrorKind, WarningKind}; use lsp_types::{ - CodeAction, CodeActionKind, CodeActionOrCommand, Diagnostic, NumberOrString, TextEdit, Url + CodeAction, CodeActionKind, CodeActionOrCommand, Diagnostic, NumberOrString, TextEdit, Url, }; use serde_json::Value; @@ -14,7 +14,8 @@ pub(crate) fn quick_fix(uri: &Url, diags: &Vec) -> Vec match error { ErrorKind::CompileError => { - let replacement_text = extract_suggested_replacement(&diag.data).unwrap_or_else(|| "".to_string()); + let replacement_text = extract_suggested_replacement(&diag.data) + .unwrap_or_else(|| "".to_string()); let mut changes = HashMap::new(); changes.insert( uri.clone(), @@ -88,19 +89,17 @@ pub(crate) fn quick_fix(uri: &Url, diags: &Vec) -> Vec) -> Option { - data.as_ref().and_then(|data| { - match data { - Value::Object(obj) => { - obj.get("suggested_replacement").and_then(|val| { - match val { - Value::String(s) => Some(s.clone()), - Value::Array(arr) if !arr.is_empty() => arr.iter().filter_map(|v| v.as_str()).next().map(String::from), - _ => None, - } - }) - }, + data.as_ref().and_then(|data| match data { + Value::Object(obj) => obj.get("suggested_replacement").and_then(|val| match val { + Value::String(s) => Some(s.clone()), + Value::Array(arr) if !arr.is_empty() => arr + .iter() + .filter_map(|v| v.as_str()) + .next() + .map(String::from), _ => None, - } + }), + _ => None, }) } diff --git a/kclvm/tools/src/LSP/src/to_lsp.rs b/kclvm/tools/src/LSP/src/to_lsp.rs index 168b0e165..f19ecefc0 100644 --- a/kclvm/tools/src/LSP/src/to_lsp.rs +++ b/kclvm/tools/src/LSP/src/to_lsp.rs @@ -44,9 +44,10 @@ fn kcl_msg_to_lsp_diags( let start_position = lsp_pos(&range.0); let end_position = lsp_pos(&range.1); - let data = msg.suggested_replacement.as_ref().map(|s| { - json!({ "suggested_replacement": [s] }) - }); + let data = msg + .suggested_replacement + .as_ref() + .map(|s| json!({ "suggested_replacement": [s] })); let related_information = if related_msg.is_empty() { None @@ -77,7 +78,7 @@ fn kcl_msg_to_lsp_diags( message: msg.message.clone(), related_information, tags: None, - data: data, + data, } }