feat(lsp): implement quickfix for utf8 byte array is valid hex string warning
This commit is contained in:
parent
858a9621fc
commit
1503b525b2
|
@ -1618,8 +1618,8 @@ impl ExtraData for Warning {
|
||||||
| Warning::UnusedType { .. }
|
| Warning::UnusedType { .. }
|
||||||
| Warning::UnusedVariable { .. }
|
| Warning::UnusedVariable { .. }
|
||||||
| Warning::DiscardedLetAssignment { .. }
|
| Warning::DiscardedLetAssignment { .. }
|
||||||
| Warning::Utf8ByteArrayIsValidHexString { .. }
|
|
||||||
| Warning::ValidatorInLibraryModule { .. } => None,
|
| Warning::ValidatorInLibraryModule { .. } => None,
|
||||||
|
Warning::Utf8ByteArrayIsValidHexString { value, .. } => Some(value.clone()),
|
||||||
Warning::UnusedImportedModule { location, .. } => {
|
Warning::UnusedImportedModule { location, .. } => {
|
||||||
Some(format!("{},{}", false, location.start))
|
Some(format!("{},{}", false, location.start))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ const UNKNOWN_CONSTRUCTOR: &str = "aiken::check::unknown::type_constructor";
|
||||||
const UNKNOWN_MODULE: &str = "aiken::check::unknown::module";
|
const UNKNOWN_MODULE: &str = "aiken::check::unknown::module";
|
||||||
const UNUSED_IMPORT_VALUE: &str = "aiken::check::unused:import::value";
|
const UNUSED_IMPORT_VALUE: &str = "aiken::check::unused:import::value";
|
||||||
const UNUSED_IMPORT_MODULE: &str = "aiken::check::unused::import::module";
|
const UNUSED_IMPORT_MODULE: &str = "aiken::check::unused::import::module";
|
||||||
|
const UTF8_BYTE_ARRAY_IS_VALID_HEX_STRING: &str =
|
||||||
|
"aiken::check::syntax::bytearray_literal_is_hex_string";
|
||||||
|
|
||||||
/// Errors for which we can provide quickfixes
|
/// Errors for which we can provide quickfixes
|
||||||
#[allow(clippy::enum_variant_names)]
|
#[allow(clippy::enum_variant_names)]
|
||||||
|
@ -18,6 +20,7 @@ pub enum Quickfix {
|
||||||
UnknownModule(lsp_types::Diagnostic),
|
UnknownModule(lsp_types::Diagnostic),
|
||||||
UnknownConstructor(lsp_types::Diagnostic),
|
UnknownConstructor(lsp_types::Diagnostic),
|
||||||
UnusedImports(Vec<lsp_types::Diagnostic>),
|
UnusedImports(Vec<lsp_types::Diagnostic>),
|
||||||
|
Utf8ByteArrayIsValidHexString(lsp_types::Diagnostic),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_code(
|
fn match_code(
|
||||||
|
@ -54,6 +57,14 @@ pub fn assert(diagnostic: lsp_types::Diagnostic) -> Option<Quickfix> {
|
||||||
return Some(Quickfix::UnusedImports(vec![diagnostic]));
|
return Some(Quickfix::UnusedImports(vec![diagnostic]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if match_code(
|
||||||
|
&diagnostic,
|
||||||
|
Severity::WARNING,
|
||||||
|
UTF8_BYTE_ARRAY_IS_VALID_HEX_STRING,
|
||||||
|
) {
|
||||||
|
return Some(Quickfix::Utf8ByteArrayIsValidHexString(diagnostic));
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +110,12 @@ pub fn quickfix(
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Quickfix::Utf8ByteArrayIsValidHexString(diagnostic) => each_as_distinct_action(
|
||||||
|
&mut actions,
|
||||||
|
text_document,
|
||||||
|
diagnostic,
|
||||||
|
utf8_byte_array_is_hex_string(diagnostic),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,3 +269,19 @@ fn unused_imports(
|
||||||
|
|
||||||
edits
|
edits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn utf8_byte_array_is_hex_string(diagnostic: &lsp_types::Diagnostic) -> Vec<AnnotatedEdit> {
|
||||||
|
let mut edits = Vec::new();
|
||||||
|
|
||||||
|
if let Some(serde_json::Value::String(ref value)) = diagnostic.data.as_ref() {
|
||||||
|
edits.push((
|
||||||
|
"Prefix with #".to_string(),
|
||||||
|
lsp_types::TextEdit {
|
||||||
|
range: diagnostic.range,
|
||||||
|
new_text: format!("#\"{value}\""),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
edits
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue