⭐️ A friendly language for building type-safe, scalable systems!

Fix extracting `use` statements

authored by gearsco.de and committed by Louis Pilfold 67d2a144 372e09ef

Changed files
+22 -15
compiler-core
src
language_server
+4
CHANGELOG.md
··· 145 145 with the wrong number of labels. 146 146 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 147 147 148 + - Fixed a bug where the language server would generate invalid code when the 149 + "Extract variable" code action was used on a `use` expression. 150 + ([Surya Rose](https://github.com/GearsDatapacks)) 151 + 148 152 ## v1.11.1 - 2025-06-05 149 153 150 154 ### Compiler
+1 -15
compiler-core/src/language_server/code_action.rs
··· 3012 3012 | ExtractVariablePosition::InsideCaseClause 3013 3013 | ExtractVariablePosition::CallArg, 3014 3014 ) 3015 - | None => { 3016 - match expr { 3017 - // We don't extract variables, they're already good. 3018 - // And we don't extract module selects by themselves but always 3019 - // want to consider those as part of a function call. 3020 - TypedExpr::Var { .. } | TypedExpr::ModuleSelect { .. } => (), 3021 - _ => { 3022 - self.selected_expression = Some((expr_location, expr.type_())); 3023 - 3024 - if !matches!(self.position, Some(ExtractVariablePosition::CallArg)) { 3025 - self.statement_before_selected_expression = self.latest_statement; 3026 - } 3027 - } 3028 - } 3029 - } 3015 + | None => {} 3030 3016 } 3031 3017 3032 3018 match expr {
+17
compiler-core/src/language_server/tests/action.rs
··· 8738 8738 .to_selection() 8739 8739 ); 8740 8740 } 8741 + 8742 + // https://github.com/gleam-lang/gleam/issues/4675 8743 + #[test] 8744 + fn extract_variable_use() { 8745 + assert_no_code_actions!( 8746 + EXTRACT_VARIABLE, 8747 + " 8748 + pub fn main() { 8749 + #({ 8750 + use <- todo 8751 + todo 8752 + }) 8753 + } 8754 + ", 8755 + find_position_of("use").to_selection() 8756 + ); 8757 + }