Skip to content

Commit c8a7834

Browse files
GearsDatapackslpil
authored andcommitted
Only track start and end locations of statements
1 parent 2d3ef4b commit c8a7834

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

compiler-core/src/language_server/code_action.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8439,18 +8439,15 @@ impl<'a> ExtractedFunction<'a> {
84398439
fn location(&self) -> SrcSpan {
84408440
match &self.value {
84418441
ExtractedValue::Expression(expression) => expression.location(),
8442-
ExtractedValue::Statements(statements) => SrcSpan::new(
8443-
statements.first().location().start,
8444-
statements.last().location().end,
8445-
),
8442+
ExtractedValue::Statements(location) => *location,
84468443
}
84478444
}
84488445
}
84498446

84508447
#[derive(Debug)]
84518448
enum ExtractedValue<'a> {
84528449
Expression(&'a TypedExpr),
8453-
Statements(Vec1<&'a TypedStatement>),
8450+
Statements(SrcSpan),
84548451
}
84558452

84568453
impl<'a> ExtractFunction<'a> {
@@ -8486,8 +8483,8 @@ impl<'a> ExtractFunction<'a> {
84868483
ExtractedValue::Expression(expression) => {
84878484
self.extract_expression(expression, extracted.parameters, end)
84888485
}
8489-
ExtractedValue::Statements(statements) => self.extract_statements(
8490-
statements,
8486+
ExtractedValue::Statements(location) => self.extract_statements(
8487+
location,
84918488
extracted.parameters,
84928489
extracted.returned_variables,
84938490
end,
@@ -8599,16 +8596,11 @@ impl<'a> ExtractFunction<'a> {
85998596

86008597
fn extract_statements(
86018598
&mut self,
8602-
statements: Vec1<&TypedStatement>,
8599+
location: SrcSpan,
86038600
parameters: Vec<(EcoString, Arc<Type>)>,
86048601
returned_variables: Vec<(EcoString, Arc<Type>)>,
86058602
function_end: u32,
86068603
) {
8607-
let first = statements.first();
8608-
let last = statements.last();
8609-
8610-
let location = SrcSpan::new(first.location().start, last.location().end);
8611-
86128604
let code = code_at(self.module, location);
86138605

86148606
let returns_anything = !returned_variables.is_empty();
@@ -8720,20 +8712,18 @@ impl<'ast> ast::visit::Visit<'ast> for ExtractFunction<'ast> {
87208712
if within(range, self.params.range) {
87218713
match &mut self.extract {
87228714
None => {
8723-
self.extract = Some(ExtractedFunction::new(ExtractedValue::Statements(vec1![
8724-
statement,
8725-
])));
8715+
self.extract = Some(ExtractedFunction::new(ExtractedValue::Statements(
8716+
statement.location(),
8717+
)));
87268718
}
87278719
Some(ExtractedFunction {
87288720
value: ExtractedValue::Expression(_),
87298721
..
87308722
}) => {}
87318723
Some(ExtractedFunction {
8732-
value: ExtractedValue::Statements(statements),
8724+
value: ExtractedValue::Statements(location),
87338725
..
8734-
}) => {
8735-
statements.push(statement);
8736-
}
8726+
}) => *location = location.merge(&statement.location()),
87378727
}
87388728
}
87398729
ast::visit::visit_typed_statement(self, statement);

0 commit comments

Comments
 (0)