Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Mittal <[email protected]>
  • Loading branch information
shashank-iitbhu committed Feb 16, 2024
1 parent c5ce405 commit a80327e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
14 changes: 5 additions & 9 deletions kclvm/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
) -> &mut Self {
let diag = Diagnostic::new_with_code(
Expand All @@ -149,7 +145,7 @@ impl Handler {
);
// println!("{:?}",suggestions.clone());
self.add_diagnostic(diag);

self
}

Expand Down
29 changes: 14 additions & 15 deletions kclvm/tools/src/LSP/src/quick_fix.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,7 +14,8 @@ pub(crate) fn quick_fix(uri: &Url, diags: &Vec<Diagnostic>) -> Vec<lsp_types::Co
match id {
DiagnosticId::Error(error) => 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(),
Expand Down Expand Up @@ -88,19 +89,17 @@ pub(crate) fn quick_fix(uri: &Url, diags: &Vec<Diagnostic>) -> Vec<lsp_types::Co
}

fn extract_suggested_replacement(data: &Option<Value>) -> Option<String> {
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,
})
}

Expand Down
9 changes: 5 additions & 4 deletions kclvm/tools/src/LSP/src/to_lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,7 +78,7 @@ fn kcl_msg_to_lsp_diags(
message: msg.message.clone(),
related_information,
tags: None,
data: data,
data,
}
}

Expand Down

0 comments on commit a80327e

Please sign in to comment.