Repository: casey/just
File: src/summary.rs (Rust)

Code before:
            arguments.push(Expression::new(arg));
          }
          Expression::Call {
            name: name.lexeme().to_owned(),
            arguments,
          }
        }
        full::Thunk::Ternary {
          name,
          args: [a, b, c],
          ..
        } => Expression::Call {
          name: name.lexeme().to_owned(),
          arguments: vec![Expression::new(a), Expression::new(b), Expression::new(c)],
        },
      },
      Concatenation { lhs, rhs } => Expression::Concatenation {
        lhs: Box::new(Expression::new(lhs)),
        rhs: Box::new(Expression::new(rhs)),
      },
      Join { lhs, rhs } => Expression::Join {
        lhs: if lhs.is_some() {
          Some(Box::new(Expression::new(lhs.as_ref().unwrap())))
        } else {
          None
        },
        rhs: Box::new(Expression::new(rhs)),
      },
      Conditional {
        lhs,
        operator,
        otherwise,
        rhs,
        then,
      } => Expression::Conditional {
        lhs: Box::new(Expression::new(lhs)),
        operator: ConditionalOperator::new(*operator),
        otherwise: Box::new(Expression::new(otherwise)),
        rhs: Box::new(Expression::new(rhs)),
        then: Box::new(Expression::new(then)),
      },
      StringLiteral { string_literal } => Expression::String {
        text: string_literal.cooked.clone(),
      },
      Variable { name, .. } => Expression::Variable {
        name: name.lexeme().to_owned(),
      },
      Group { contents } => Expression::new(contents),
    }
  }
}

Review comment (suggestion):
I tried cleaning this up a bit by using the `if let Some()` syntax here but was getting some odd warnings and hints from rust-analyzer.

<img width="1282" alt="Screen Shot 2022-09-02 at 12 02 03 AM" src="https://user-images.githubusercontent.com/10244162/188056708-e64c6ce6-763d-4c2f-a1c8-0aa3ccf40301.png">

I was able to pass the tests using that syntax but held off on committing that version. Not sure if there is an issue with the Rust LSP implementation or an actual issue with using that syntax in this context.

Code after:
            arguments.push(Expression::new(arg));
          }
          Expression::Call {
            name: name.lexeme().to_owned(),
            arguments,
          }
        }
        full::Thunk::Ternary {
          name,
          args: [a, b, c],
          ..
        } => Expression::Call {
          name: name.lexeme().to_owned(),
          arguments: vec![Expression::new(a), Expression::new(b), Expression::new(c)],
        },
      },
      Concatenation { lhs, rhs } => Expression::Concatenation {
        lhs: Box::new(Expression::new(lhs)),
        rhs: Box::new(Expression::new(rhs)),
      },
      Join { lhs, rhs } => Expression::Join {
        lhs: lhs.as_ref().map(|lhs| Box::new(Expression::new(lhs))),
        rhs: Box::new(Expression::new(rhs)),
      },
      Conditional {
        lhs,
        operator,
        otherwise,
        rhs,
        then,
      } => Expression::Conditional {
        lhs: Box::new(Expression::new(lhs)),
        operator: ConditionalOperator::new(*operator),
        otherwise: Box::new(Expression::new(otherwise)),
        rhs: Box::new(Expression::new(rhs)),
        then: Box::new(Expression::new(then)),
      },
      StringLiteral { string_literal } => Expression::String {
        text: string_literal.cooked.clone(),
      },
      Variable { name, .. } => Expression::Variable {
        name: name.lexeme().to_owned(),
      },
      Group { contents } => Expression::new(contents),
    }
  }
}

#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
pub enum ConditionalOperator {
  Equality,