···85248524 parameters: Vec<(EcoString, Arc<Type>)>,
85258525 function_end: u32,
85268526 ) {
85278527- let expression_code = code_at(self.module, expression.location());
85278527+ // If we extract a block, it isn't very helpful to have the body of the
85288528+ // extracted function just be a single block expression, so instead we
85298529+ // extract the statements inside the block. For example, the following
85308530+ // code:
85318531+ //
85328532+ // ```gleam
85338533+ // pub fn main() {
85348534+ // let x = {
85358535+ // // ^ Select from here
85368536+ // let a = 1
85378537+ // let b = 2
85388538+ // a + b
85398539+ // }
85408540+ // //^ Until here
85418541+ // x
85428542+ // }
85438543+ // ```
85448544+ //
85458545+ // Would produce the following extracted function:
85468546+ //
85478547+ // ```gleam
85488548+ // fn function() {
85498549+ // let a = 1
85508550+ // let b = 2
85518551+ // a + b
85528552+ // }
85538553+ // ```
85548554+ //
85558555+ // Rather than:
85568556+ //
85578557+ // ```gleam
85588558+ // fn function() {
85598559+ // {
85608560+ // let a = 1
85618561+ // let b = 2
85628562+ // a + b
85638563+ // }
85648564+ // }
85658565+ // ```
85668566+ //
85678567+ let extracted_code_location = if let TypedExpr::Block { statements, .. } = expression {
85688568+ SrcSpan::new(
85698569+ statements.first().location().start,
85708570+ statements.last().location().end,
85718571+ )
85728572+ } else {
85738573+ expression.location()
85748574+ };
85758575+85768576+ let expression_code = code_at(self.module, extracted_code_location);
8528857785298578 let name = self.function_name();
85308579 let arguments = parameters.iter().map(|(name, _)| name).join(", ");