this repo has no description

Only track start and end locations of statements

authored by gearsco.de and committed by

Louis Pilfold c8a78349 2d3ef4b3

+10 -20
+10 -20
compiler-core/src/language_server/code_action.rs
··· 8439 fn location(&self) -> SrcSpan { 8440 match &self.value { 8441 ExtractedValue::Expression(expression) => expression.location(), 8442 - ExtractedValue::Statements(statements) => SrcSpan::new( 8443 - statements.first().location().start, 8444 - statements.last().location().end, 8445 - ), 8446 } 8447 } 8448 } ··· 8450 #[derive(Debug)] 8451 enum ExtractedValue<'a> { 8452 Expression(&'a TypedExpr), 8453 - Statements(Vec1<&'a TypedStatement>), 8454 } 8455 8456 impl<'a> ExtractFunction<'a> { ··· 8486 ExtractedValue::Expression(expression) => { 8487 self.extract_expression(expression, extracted.parameters, end) 8488 } 8489 - ExtractedValue::Statements(statements) => self.extract_statements( 8490 - statements, 8491 extracted.parameters, 8492 extracted.returned_variables, 8493 end, ··· 8599 8600 fn extract_statements( 8601 &mut self, 8602 - statements: Vec1<&TypedStatement>, 8603 parameters: Vec<(EcoString, Arc<Type>)>, 8604 returned_variables: Vec<(EcoString, Arc<Type>)>, 8605 function_end: u32, 8606 ) { 8607 - let first = statements.first(); 8608 - let last = statements.last(); 8609 - 8610 - let location = SrcSpan::new(first.location().start, last.location().end); 8611 - 8612 let code = code_at(self.module, location); 8613 8614 let returns_anything = !returned_variables.is_empty(); ··· 8720 if within(range, self.params.range) { 8721 match &mut self.extract { 8722 None => { 8723 - self.extract = Some(ExtractedFunction::new(ExtractedValue::Statements(vec1![ 8724 - statement, 8725 - ]))); 8726 } 8727 Some(ExtractedFunction { 8728 value: ExtractedValue::Expression(_), 8729 .. 8730 }) => {} 8731 Some(ExtractedFunction { 8732 - value: ExtractedValue::Statements(statements), 8733 .. 8734 - }) => { 8735 - statements.push(statement); 8736 - } 8737 } 8738 } 8739 ast::visit::visit_typed_statement(self, statement);
··· 8439 fn location(&self) -> SrcSpan { 8440 match &self.value { 8441 ExtractedValue::Expression(expression) => expression.location(), 8442 + ExtractedValue::Statements(location) => *location, 8443 } 8444 } 8445 } ··· 8447 #[derive(Debug)] 8448 enum ExtractedValue<'a> { 8449 Expression(&'a TypedExpr), 8450 + Statements(SrcSpan), 8451 } 8452 8453 impl<'a> ExtractFunction<'a> { ··· 8483 ExtractedValue::Expression(expression) => { 8484 self.extract_expression(expression, extracted.parameters, end) 8485 } 8486 + ExtractedValue::Statements(location) => self.extract_statements( 8487 + location, 8488 extracted.parameters, 8489 extracted.returned_variables, 8490 end, ··· 8596 8597 fn extract_statements( 8598 &mut self, 8599 + location: SrcSpan, 8600 parameters: Vec<(EcoString, Arc<Type>)>, 8601 returned_variables: Vec<(EcoString, Arc<Type>)>, 8602 function_end: u32, 8603 ) { 8604 let code = code_at(self.module, location); 8605 8606 let returns_anything = !returned_variables.is_empty(); ··· 8712 if within(range, self.params.range) { 8713 match &mut self.extract { 8714 None => { 8715 + self.extract = Some(ExtractedFunction::new(ExtractedValue::Statements( 8716 + statement.location(), 8717 + ))); 8718 } 8719 Some(ExtractedFunction { 8720 value: ExtractedValue::Expression(_), 8721 .. 8722 }) => {} 8723 Some(ExtractedFunction { 8724 + value: ExtractedValue::Statements(location), 8725 .. 8726 + }) => *location = location.merge(&statement.location()), 8727 } 8728 } 8729 ast::visit::visit_typed_statement(self, statement);