Skip to content

Commit

Permalink
update documentation, for real
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored and lpil committed Jan 9, 2025
1 parent e037535 commit 42c85df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 32 additions & 3 deletions compiler-core/src/language_server/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>,
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/language_server/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -336,7 +336,7 @@ where
actions.extend(ExpandFunctionCapture::new(module, &lines, &params).code_actions());
actions.extend(ExtractVariable::new(module, &lines, &params).code_actions());
actions.extend(
PatternMatchOnArgument::new(module, &lines, &params, &this.compiler).code_actions(),
PatternMatchOnValue::new(module, &lines, &params, &this.compiler).code_actions(),
);
GenerateDynamicDecoder::new(module, &lines, &params, &mut actions).code_actions();
AddAnnotations::new(module, &lines, &params).code_action(&mut actions);
Expand Down

0 comments on commit 42c85df

Please sign in to comment.