diff --git a/CHANGELOG.md b/CHANGELOG.md index fed5257d..7f9ef41a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v1.0.29-alpha - UNRELEASED +### Added + +- **aiken-lang**: new LSP quickfix for 'use let' warning. @KtorZ + ### Changed - **aiken-lang**: the keyword `fail` on property-based test semantic has changed and now consider a test to succeed only if **every** execution of the test failed (instead of just one). The previous behavior can be recovered by adding the keyword `once` after `fail`. @KtorZ diff --git a/crates/aiken-lsp/src/quickfix.rs b/crates/aiken-lsp/src/quickfix.rs index 06486bf2..1f98ba07 100644 --- a/crates/aiken-lsp/src/quickfix.rs +++ b/crates/aiken-lsp/src/quickfix.rs @@ -10,6 +10,7 @@ const UNKNOWN_CONSTRUCTOR: &str = "aiken::check::unknown::type_constructor"; const UNKNOWN_MODULE: &str = "aiken::check::unknown::module"; const UNUSED_IMPORT_VALUE: &str = "aiken::check::unused:import::value"; const UNUSED_IMPORT_MODULE: &str = "aiken::check::unused::import::module"; +const USE_LET: &str = "aiken::check::single_constructor_expect"; const UTF8_BYTE_ARRAY_IS_VALID_HEX_STRING: &str = "aiken::check::syntax::bytearray_literal_is_hex_string"; @@ -21,6 +22,7 @@ pub enum Quickfix { UnknownConstructor(lsp_types::Diagnostic), UnusedImports(Vec), Utf8ByteArrayIsValidHexString(lsp_types::Diagnostic), + UseLet(lsp_types::Diagnostic), } fn match_code( @@ -65,6 +67,10 @@ pub fn assert(diagnostic: lsp_types::Diagnostic) -> Option { return Some(Quickfix::Utf8ByteArrayIsValidHexString(diagnostic)); } + if match_code(&diagnostic, Severity::WARNING, USE_LET) { + return Some(Quickfix::UseLet(diagnostic)); + } + None } @@ -116,6 +122,12 @@ pub fn quickfix( diagnostic, utf8_byte_array_is_hex_string(diagnostic), ), + Quickfix::UseLet(diagnostic) => each_as_distinct_action( + &mut actions, + text_document, + diagnostic, + use_let(diagnostic), + ), }; } @@ -285,3 +297,13 @@ fn utf8_byte_array_is_hex_string(diagnostic: &lsp_types::Diagnostic) -> Vec Vec { + vec![( + "Use 'let' instead of 'expect'".to_string(), + lsp_types::TextEdit { + range: diagnostic.range, + new_text: "let".to_string(), + }, + )] +}