Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Use correct line number information for generating functions in other modules

author
Gears
committer
Louis Pilfold
date (Oct 3, 2025, 12:21 PM +0100) commit 8bdec6d2 parent 03bfad92 change-id rwqqvqkv
+58 -6
+6
CHANGELOG.md
··· 16 16 incorrect extra patterns in addition to the correct missing patterns. 17 17 ([Adi Salimgereyev](https://github.com/abs0luty)) 18 18 19 + - Fixed a bug where triggering the "Generate function" code action to generate 20 + a function in a different module could cause the generated function to appear 21 + in the middle of an existing function, resulting in invalid code. 22 + 23 + ([Surya Rose](https://github.com/GearsDatapacks)) 24 + 19 25 ## v1.13.0-rc1 - 2025-09-29 20 26 21 27 ### Compiler
+6 -6
compiler-core/src/language_server/code_action.rs
··· 5208 5208 5209 5209 if let Some(module) = module { 5210 5210 if let Some(module) = self.modules.get(module) { 5211 - let insert_at = if module.code.is_empty() { 5212 - 0 5213 - } else { 5214 - (module.code.len() - 1) as u32 5215 - }; 5211 + let insert_at = module.code.len() as u32; 5216 5212 self.code_action_for_module( 5217 5213 module, 5218 5214 Publicity::Public, ··· 5230 5226 5231 5227 fn code_action_for_module( 5232 5228 mut self, 5233 - module: &Module, 5229 + module: &'a Module, 5234 5230 publicity: Publicity, 5235 5231 function_to_generate: FunctionToGenerate<'a>, 5236 5232 insert_at: u32, ··· 5272 5268 5273 5269 let publicity = if publicity.is_public() { "pub " } else { "" }; 5274 5270 5271 + // Make sure we use the line number information of the module we are 5272 + // editing, which might not be the module where the code action is 5273 + // triggered. 5274 + self.edits.line_numbers = &module.ast.type_info.line_numbers; 5275 5275 self.edits.insert( 5276 5276 insert_at, 5277 5277 format!("\n\n{publicity}fn {name}({arguments}) -> {return_type} {{\n todo\n}}"),
+23
compiler-core/src/language_server/tests/action.rs
··· 10637 10637 .select_until(find_position_of("}")) 10638 10638 ); 10639 10639 } 10640 + 10641 + // https://github.com/gleam-lang/gleam/issues/5036 10642 + #[test] 10643 + fn generate_function_in_other_module_correctly_appends() { 10644 + let src = "import module_breaker/another 10645 + 10646 + pub fn main() -> Nil { 10647 + another.function() 10648 + } 10649 + "; 10650 + 10651 + assert_code_action!( 10652 + GENERATE_FUNCTION, 10653 + TestProject::for_source(src).add_module( 10654 + "module_breaker/another", 10655 + "pub fn useless() { 10656 + Nil 10657 + } 10658 + " 10659 + ), 10660 + find_position_of("function").to_selection() 10661 + ); 10662 + }
+23
compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__generate_function_in_other_module_correctly_appends.snap
··· 1 + --- 2 + source: compiler-core/src/language_server/tests/action.rs 3 + expression: "import module_breaker/another\n\npub fn main() -> Nil {\n another.function()\n}\n" 4 + --- 5 + ----- BEFORE ACTION 6 + import module_breaker/another 7 + 8 + pub fn main() -> Nil { 9 + another.function() 10 + 11 + } 12 + 13 + 14 + ----- AFTER ACTION 15 + // --- Edits applied to module 'module_breaker/another' 16 + pub fn useless() { 17 + Nil 18 + } 19 + 20 + 21 + pub fn function() -> Nil { 22 + todo 23 + }