diff --git a/compiler-core/src/language_server/code_action.rs b/compiler-core/src/language_server/code_action.rs index da649590125..65791ffcfae 100644 --- a/compiler-core/src/language_server/code_action.rs +++ b/compiler-core/src/language_server/code_action.rs @@ -3255,8 +3255,37 @@ impl<'a> DecoderPrinter<'a> { /// Builder for code action to pattern match on things like (anonymous) function /// arguments or variables. +/// For example: /// -pub struct PatternMatchOnArgument<'a, A> { +/// ```gleam +/// pub fn wibble(arg: #(key, value)) { +/// // ^ [pattern match on argument] +/// } +/// +/// // Generates +/// +/// pub fn wibble(arg: #(key, value)) { +/// let #(value_0, value_1) = arg +/// } +/// ``` +/// +/// Another example with variables: +/// +/// ```gleam +/// pub fn main() { +/// let pair = #(1, 3) +/// // ^ [pattern match on value] +/// } +/// +/// // Generates +/// +/// pub fn main() { +/// let pair = #(1, 3) +/// let #(value_0, value_1) = pair +/// } +/// ``` +/// +pub struct PatternMatchOnValue<'a, A> { module: &'a Module, params: &'a CodeActionParams, compiler: &'a LspProjectCompiler, @@ -3292,7 +3321,7 @@ pub enum PatternMatchedValue<'a> { }, } -impl<'a, IO> PatternMatchOnArgument<'a, IO> +impl<'a, IO> PatternMatchOnValue<'a, IO> where IO: CommandExecutor + FileSystemWriter + FileSystemReader + BeamCompiler + Clone, { @@ -3562,7 +3591,7 @@ where } } -impl<'ast, IO> ast::visit::Visit<'ast> for PatternMatchOnArgument<'ast, IO> +impl<'ast, IO> ast::visit::Visit<'ast> for PatternMatchOnValue<'ast, IO> where IO: CommandExecutor + FileSystemWriter + FileSystemReader + BeamCompiler + Clone, { diff --git a/compiler-core/src/language_server/engine.rs b/compiler-core/src/language_server/engine.rs index 220e3167208..9fb3c7a6ddc 100644 --- a/compiler-core/src/language_server/engine.rs +++ b/compiler-core/src/language_server/engine.rs @@ -34,7 +34,7 @@ use super::{ code_action_convert_unqualified_constructor_to_qualified, code_action_import_module, code_action_inexhaustive_let_to_case, AddAnnotations, CodeActionBuilder, DesugarUse, ExpandFunctionCapture, ExtractVariable, FillInMissingLabelledArgs, GenerateDynamicDecoder, - LabelShorthandSyntax, LetAssertToCase, PatternMatchOnArgument, RedundantTupleInCaseSubject, + LabelShorthandSyntax, LetAssertToCase, PatternMatchOnValue, RedundantTupleInCaseSubject, TurnIntoUse, }, completer::Completer, @@ -336,7 +336,7 @@ where actions.extend(ExpandFunctionCapture::new(module, &lines, ¶ms).code_actions()); actions.extend(ExtractVariable::new(module, &lines, ¶ms).code_actions()); actions.extend( - PatternMatchOnArgument::new(module, &lines, ¶ms, &this.compiler).code_actions(), + PatternMatchOnValue::new(module, &lines, ¶ms, &this.compiler).code_actions(), ); GenerateDynamicDecoder::new(module, &lines, ¶ms, &mut actions).code_actions(); AddAnnotations::new(module, &lines, ¶ms).code_action(&mut actions);