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

improve definitions naming

authored by giacomocavalieri.me and committed by Louis Pilfold c73ae495 82b12def

Changed files
+166 -135
compiler-core
+46 -37
compiler-core/src/analyse.rs
··· 8 8 GLEAM_CORE_PACKAGE_NAME, 9 9 ast::{ 10 10 self, Arg, BitArrayOption, CustomType, Definition, DefinitionLocation, Function, 11 - GroupedStatements, Import, ModuleConstant, Publicity, RecordConstructor, 11 + GroupedDefinitions, Import, ModuleConstant, Publicity, RecordConstructor, 12 12 RecordConstructorArg, SrcSpan, Statement, TypeAlias, TypeAst, TypeAstConstructor, 13 13 TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, TypedDefinition, TypedExpr, 14 14 TypedFunction, TypedModule, UntypedArg, UntypedCustomType, UntypedFunction, UntypedImport, ··· 223 223 } 224 224 .build(); 225 225 226 - let statements = GroupedStatements::new(module.into_iter_statements(self.target)); 227 - let statements_count = statements.len(); 226 + let definitions = GroupedDefinitions::new(module.into_iter_definitions(self.target)); 227 + let definitions_count = definitions.len(); 228 228 229 229 // Register any modules, types, and values being imported 230 230 // We process imports first so that anything imported can be referenced 231 231 // anywhere in the module. 232 - let mut env = Importer::run(self.origin, env, &statements.imports, &mut self.problems); 232 + let mut env = Importer::run(self.origin, env, &definitions.imports, &mut self.problems); 233 233 234 234 // Register types so they can be used in constructors and functions 235 235 // earlier in the module. 236 - for t in &statements.custom_types { 237 - if let Err(error) = self.register_types_from_custom_type(t, &mut env) { 236 + for type_ in &definitions.custom_types { 237 + if let Err(error) = self.register_types_from_custom_type(type_, &mut env) { 238 238 return self.all_errors(error); 239 239 } 240 240 } 241 241 242 - let sorted_aliases = match sorted_type_aliases(&statements.type_aliases) { 243 - Ok(it) => it, 242 + let sorted_aliases = match sorted_type_aliases(&definitions.type_aliases) { 243 + Ok(sorted_aliases) => sorted_aliases, 244 244 Err(error) => return self.all_errors(error), 245 245 }; 246 - for t in sorted_aliases { 247 - self.register_type_alias(t, &mut env); 246 + for type_alias in sorted_aliases { 247 + self.register_type_alias(type_alias, &mut env); 248 248 } 249 249 250 - for f in &statements.functions { 251 - self.register_value_from_function(f, &mut env); 250 + for function in &definitions.functions { 251 + self.register_value_from_function(function, &mut env); 252 252 } 253 253 254 254 // Infer the types of each statement in the module 255 - let mut typed_statements = Vec::with_capacity(statements_count); 256 - for i in statements.imports { 257 - optionally_push(&mut typed_statements, self.analyse_import(i, &env)); 255 + let mut typed_definitions = Vec::with_capacity(definitions_count); 256 + for import in definitions.imports { 257 + optionally_push(&mut typed_definitions, self.analyse_import(import, &env)); 258 258 } 259 - for t in statements.custom_types { 260 - optionally_push(&mut typed_statements, self.analyse_custom_type(t, &mut env)); 259 + for type_ in definitions.custom_types { 260 + optionally_push( 261 + &mut typed_definitions, 262 + self.analyse_custom_type(type_, &mut env), 263 + ); 261 264 } 262 - for t in statements.type_aliases { 263 - typed_statements.push(analyse_type_alias(t, &mut env)); 265 + for type_alias in definitions.type_aliases { 266 + typed_definitions.push(analyse_type_alias(type_alias, &mut env)); 264 267 } 265 268 266 - // Sort functions and constants into dependency order for inference. Definitions that do 267 - // not depend on other definitions are inferred first, then ones that depend 268 - // on those, etc. 269 + // Sort functions and constants into dependency order for inference. 270 + // Definitions that do not depend on other definitions are inferred 271 + // first, then ones that depend on those, etc. 269 272 let definition_groups = 270 - match into_dependency_order(statements.functions, statements.constants) { 271 - Ok(it) => it, 273 + match into_dependency_order(definitions.functions, definitions.constants) { 274 + Ok(definition_groups) => definition_groups, 272 275 Err(error) => return self.all_errors(error), 273 276 }; 274 277 let mut working_group = vec![]; 275 278 276 279 for group in definition_groups { 277 - // A group may have multiple functions that depend on each other through 278 - // mutual recursion. 280 + // A group may have multiple functions that depend on each other 281 + // through mutual recursion. 279 282 280 283 for definition in group { 281 - let def = match definition { 282 - CallGraphNode::Function(f) => self.infer_function(f, &mut env), 283 - CallGraphNode::ModuleConstant(c) => self.infer_module_constant(c, &mut env), 284 + let definition = match definition { 285 + CallGraphNode::Function(function) => self.infer_function(function, &mut env), 286 + CallGraphNode::ModuleConstant(constant) => { 287 + self.infer_module_constant(constant, &mut env) 288 + } 284 289 }; 285 - working_group.push(def); 290 + working_group.push(definition); 286 291 } 287 292 288 293 // Now that the entire group has been inferred, generalise their types. 289 294 for inferred in working_group.drain(..) { 290 - typed_statements.push(generalise_statement(inferred, &self.module_name, &mut env)); 295 + typed_definitions.push(generalise_definition( 296 + inferred, 297 + &self.module_name, 298 + &mut env, 299 + )); 291 300 } 292 301 } 293 302 ··· 335 344 let module = ast::Module { 336 345 documentation: documentation.clone(), 337 346 name: self.module_name.clone(), 338 - definitions: typed_statements, 347 + definitions: typed_definitions, 339 348 names: type_names, 340 349 unused_definition_positions, 341 350 type_info: ModuleInterface { ··· 1686 1695 } 1687 1696 } 1688 1697 1689 - fn generalise_statement( 1690 - s: TypedDefinition, 1698 + fn generalise_definition( 1699 + definition: TypedDefinition, 1691 1700 module_name: &EcoString, 1692 1701 environment: &mut Environment<'_>, 1693 1702 ) -> TypedDefinition { 1694 - match s { 1703 + match definition { 1695 1704 Definition::Function(function) => generalise_function(function, environment, module_name), 1696 1705 Definition::ModuleConstant(constant) => { 1697 1706 generalise_module_constant(constant, environment, module_name) 1698 1707 } 1699 - statement @ (Definition::TypeAlias(TypeAlias { .. }) 1708 + definition @ (Definition::TypeAlias(TypeAlias { .. }) 1700 1709 | Definition::CustomType(CustomType { .. }) 1701 - | Definition::Import(Import { .. })) => statement, 1710 + | Definition::Import(Import { .. })) => definition, 1702 1711 } 1703 1712 } 1704 1713
+22 -22
compiler-core/src/ast.rs
··· 50 50 pub type UntypedModule = Module<(), TargetedDefinition>; 51 51 52 52 #[derive(Debug, Clone, PartialEq, Eq)] 53 - pub struct Module<Info, Statements> { 53 + pub struct Module<Info, Definitions> { 54 54 pub name: EcoString, 55 55 pub documentation: Vec<EcoString>, 56 56 pub type_info: Info, 57 - pub definitions: Vec<Statements>, 57 + pub definitions: Vec<Definitions>, 58 58 pub names: Names, 59 59 /// The source byte locations of definition that are unused. 60 60 /// This is used in code generation to know when definitions can be safely omitted. 61 61 pub unused_definition_positions: HashSet<u32>, 62 62 } 63 63 64 - impl<Info, Statements> Module<Info, Statements> { 64 + impl<Info, Definitions> Module<Info, Definitions> { 65 65 pub fn erlang_name(&self) -> EcoString { 66 66 module_erlang_name(&self.name) 67 67 } ··· 71 71 pub fn find_node(&self, byte_index: u32) -> Option<Located<'_>> { 72 72 self.definitions 73 73 .iter() 74 - .find_map(|statement| statement.find_node(byte_index)) 74 + .find_map(|definition| definition.find_node(byte_index)) 75 75 } 76 76 77 77 pub fn find_statement(&self, byte_index: u32) -> Option<&TypedStatement> { ··· 105 105 106 106 impl UntypedModule { 107 107 pub fn dependencies(&self, target: Target) -> Vec<(EcoString, SrcSpan)> { 108 - self.iter_statements(target) 109 - .flat_map(|s| match s { 108 + self.iter_definitions(target) 109 + .flat_map(|definition| match definition { 110 110 Definition::Import(Import { 111 111 module, location, .. 112 112 }) => Some((module.clone(), *location)), ··· 115 115 .collect() 116 116 } 117 117 118 - pub fn iter_statements(&self, target: Target) -> impl Iterator<Item = &UntypedDefinition> { 118 + pub fn iter_definitions(&self, target: Target) -> impl Iterator<Item = &UntypedDefinition> { 119 119 self.definitions 120 120 .iter() 121 - .filter(move |def| def.is_for(target)) 122 - .map(|def| &def.definition) 121 + .filter(move |definition| definition.is_for(target)) 122 + .map(|definition| &definition.definition) 123 123 } 124 124 125 - pub fn into_iter_statements(self, target: Target) -> impl Iterator<Item = UntypedDefinition> { 125 + pub fn into_iter_definitions(self, target: Target) -> impl Iterator<Item = UntypedDefinition> { 126 126 self.definitions 127 127 .into_iter() 128 - .filter(move |def| def.is_for(target)) 129 - .map(|def| def.definition) 128 + .filter(move |definition| definition.is_for(target)) 129 + .map(|definition| definition.definition) 130 130 } 131 131 } 132 132 ··· 2846 2846 } 2847 2847 2848 2848 #[derive(Debug, Default)] 2849 - pub struct GroupedStatements { 2849 + pub struct GroupedDefinitions { 2850 2850 pub functions: Vec<UntypedFunction>, 2851 2851 pub constants: Vec<UntypedModuleConstant>, 2852 2852 pub custom_types: Vec<UntypedCustomType>, ··· 2854 2854 pub type_aliases: Vec<UntypedTypeAlias>, 2855 2855 } 2856 2856 2857 - impl GroupedStatements { 2858 - pub fn new(statements: impl IntoIterator<Item = UntypedDefinition>) -> Self { 2857 + impl GroupedDefinitions { 2858 + pub fn new(definitions: impl IntoIterator<Item = UntypedDefinition>) -> Self { 2859 2859 let mut this = Self::default(); 2860 2860 2861 - for statement in statements { 2862 - this.add(statement) 2861 + for definition in definitions { 2862 + this.add(definition) 2863 2863 } 2864 2864 2865 2865 this ··· 2882 2882 2883 2883 fn add(&mut self, statement: UntypedDefinition) { 2884 2884 match statement { 2885 - Definition::Import(i) => self.imports.push(i), 2886 - Definition::Function(f) => self.functions.push(f), 2887 - Definition::TypeAlias(t) => self.type_aliases.push(t), 2888 - Definition::CustomType(c) => self.custom_types.push(c), 2889 - Definition::ModuleConstant(c) => self.constants.push(c), 2885 + Definition::Import(import) => self.imports.push(import), 2886 + Definition::Function(function) => self.functions.push(function), 2887 + Definition::TypeAlias(type_alias) => self.type_aliases.push(type_alias), 2888 + Definition::CustomType(custom_type) => self.custom_types.push(custom_type), 2889 + Definition::ModuleConstant(constant) => self.constants.push(constant), 2890 2890 } 2891 2891 } 2892 2892 }
+2 -2
compiler-core/src/ast/visit.rs
··· 587 587 where 588 588 V: Visit<'a> + ?Sized, 589 589 { 590 - for def in &module.definitions { 591 - v.visit_typed_definition(def); 590 + for definition in &module.definitions { 591 + v.visit_typed_definition(definition); 592 592 } 593 593 } 594 594
+23 -21
compiler-core/src/ast_folder.rs
··· 22 22 #[allow(dead_code)] 23 23 pub trait UntypedModuleFolder: TypeAstFolder + UntypedExprFolder { 24 24 /// You probably don't want to override this method. 25 - fn fold_module(&mut self, mut m: UntypedModule) -> UntypedModule { 26 - m.definitions = m 25 + fn fold_module(&mut self, mut module: UntypedModule) -> UntypedModule { 26 + module.definitions = module 27 27 .definitions 28 28 .into_iter() 29 - .map(|d| { 30 - let TargetedDefinition { definition, target } = d; 29 + .map(|definition| { 30 + let TargetedDefinition { definition, target } = definition; 31 31 match definition { 32 - Definition::Function(f) => { 33 - let f = self.fold_function_definition(f, target); 34 - let definition = self.walk_function_definition(f); 32 + Definition::Function(function) => { 33 + let function = self.fold_function_definition(function, target); 34 + let definition = self.walk_function_definition(function); 35 35 TargetedDefinition { definition, target } 36 36 } 37 37 38 - Definition::TypeAlias(a) => { 39 - let a = self.fold_type_alias(a, target); 40 - let definition = self.walk_type_alias(a); 38 + Definition::TypeAlias(type_alias) => { 39 + let type_alias = self.fold_type_alias(type_alias, target); 40 + let definition = self.walk_type_alias(type_alias); 41 41 TargetedDefinition { definition, target } 42 42 } 43 43 44 - Definition::CustomType(t) => { 45 - let t = self.fold_custom_type(t, target); 46 - let definition = self.walk_custom_type(t); 44 + Definition::CustomType(custom_type) => { 45 + let custom_type = self.fold_custom_type(custom_type, target); 46 + let definition = self.walk_custom_type(custom_type); 47 47 TargetedDefinition { definition, target } 48 48 } 49 49 50 - Definition::Import(i) => { 51 - let i = self.fold_import(i, target); 52 - let definition = self.walk_import(i); 50 + Definition::Import(import) => { 51 + let import = self.fold_import(import, target); 52 + let definition = self.walk_import(import); 53 53 TargetedDefinition { definition, target } 54 54 } 55 55 56 - Definition::ModuleConstant(c) => { 57 - let c = self.fold_module_constant(c, target); 58 - let definition = self.walk_module_constant(c); 56 + Definition::ModuleConstant(constant) => { 57 + let constant = self.fold_module_constant(constant, target); 58 + let definition = self.walk_module_constant(constant); 59 59 TargetedDefinition { definition, target } 60 60 } 61 61 } 62 62 }) 63 63 .collect(); 64 - m 64 + module 65 65 } 66 66 67 67 /// You probably don't want to override this method. 68 68 fn walk_function_definition(&mut self, mut function: UntypedFunction) -> UntypedDefinition { 69 - function.body = function.body.mapped(|s| self.fold_statement(s)); 69 + function.body = function 70 + .body 71 + .mapped(|statement| self.fold_statement(statement)); 70 72 function.return_annotation = function 71 73 .return_annotation 72 74 .map(|type_| self.fold_type(type_));
+7 -7
compiler-core/src/build.rs
··· 272 272 273 273 self.ast.type_info.documentation = self.ast.documentation.clone(); 274 274 275 - // Order statements to avoid misassociating doc comments after the 275 + // Order definitions to avoid misassociating doc comments after the 276 276 // order has changed during compilation. 277 - let mut statements: Vec<_> = self.ast.definitions.iter_mut().collect(); 278 - statements.sort_by(|a, b| a.location().start.cmp(&b.location().start)); 277 + let mut definitions: Vec<_> = self.ast.definitions.iter_mut().collect(); 278 + definitions.sort_by(|a, b| a.location().start.cmp(&b.location().start)); 279 279 280 280 // Doc Comments 281 281 let mut doc_comments = self.extra.doc_comments.iter().peekable(); 282 - for statement in &mut statements { 282 + for definition in &mut definitions { 283 283 let (docs_start, docs): (u32, Vec<&str>) = doc_comments_before( 284 284 &mut doc_comments, 285 285 &self.extra, 286 - statement.location().start, 286 + definition.location().start, 287 287 &self.code, 288 288 ); 289 289 if !docs.is_empty() { 290 290 let doc = docs.join("\n").into(); 291 - statement.put_doc((docs_start, doc)); 291 + definition.put_doc((docs_start, doc)); 292 292 } 293 293 294 - if let Definition::CustomType(CustomType { constructors, .. }) = statement { 294 + if let Definition::CustomType(CustomType { constructors, .. }) = definition { 295 295 for constructor in constructors { 296 296 let (docs_start, docs): (u32, Vec<&str>) = doc_comments_before( 297 297 &mut doc_comments,
+2 -2
compiler-core/src/docs.rs
··· 212 212 .ast 213 213 .definitions 214 214 .iter() 215 - .filter_map(|statement| printer.type_definition(&source_links, statement)) 215 + .filter_map(|definition| printer.type_definition(&source_links, definition)) 216 216 .sorted() 217 217 .collect(); 218 218 ··· 220 220 .ast 221 221 .definitions 222 222 .iter() 223 - .filter_map(|statement| printer.value(&source_links, statement)) 223 + .filter_map(|definition| printer.value(&source_links, definition)) 224 224 .sorted() 225 225 .collect(); 226 226
+3 -3
compiler-core/src/docs/tests.rs
··· 192 192 .definitions 193 193 .iter() 194 194 .filter_map( 195 - |statement: &crate::ast::Definition< 195 + |definition: &crate::ast::Definition< 196 196 std::sync::Arc<type_::Type>, 197 197 crate::ast::TypedExpr, 198 198 EcoString, 199 199 EcoString, 200 - >| printer.type_definition(&source_links, statement), 200 + >| printer.type_definition(&source_links, definition), 201 201 ) 202 202 .sorted() 203 203 .collect_vec(); ··· 205 205 let values = module 206 206 .definitions 207 207 .iter() 208 - .filter_map(|statement| printer.value(&source_links, statement)) 208 + .filter_map(|definition| printer.value(&source_links, definition)) 209 209 .sorted() 210 210 .collect_vec(); 211 211
+20 -15
compiler-core/src/erlang.rs
··· 91 91 module 92 92 .definitions 93 93 .iter() 94 - .filter_map(|s| match s { 94 + .filter_map(|definition| match definition { 95 95 Definition::CustomType(CustomType { 96 96 publicity: Publicity::Public, 97 97 constructors, ··· 173 173 // would result in an error as it tries to reference this private function. 174 174 let overridden_publicity = find_private_functions_referenced_in_importable_constants(module); 175 175 176 - for s in &module.definitions { 176 + for definition in &module.definitions { 177 177 register_imports_and_exports( 178 - s, 178 + definition, 179 179 &mut exports, 180 180 &mut type_exports, 181 181 &mut type_defs, ··· 297 297 } 298 298 299 299 fn register_imports_and_exports( 300 - s: &TypedDefinition, 300 + definition: &TypedDefinition, 301 301 exports: &mut Vec<Document<'_>>, 302 302 type_exports: &mut Vec<Document<'_>>, 303 303 type_defs: &mut Vec<Document<'_>>, ··· 306 306 unused_definition_positions: &HashSet<u32>, 307 307 ) { 308 308 // Do not generate any code for unused items 309 - if unused_definition_positions.contains(&s.location().start) { 309 + if unused_definition_positions.contains(&definition.location().start) { 310 310 return; 311 311 } 312 312 313 - match s { 313 + match definition { 314 314 Definition::Function(Function { 315 315 publicity, 316 316 name: Some((_, name)), ··· 379 379 } else { 380 380 let constructors = constructors 381 381 .iter() 382 - .map(|c| { 383 - let name = atom_string(to_snake_case(&c.name)); 384 - if c.arguments.is_empty() { 382 + .map(|constructor| { 383 + let name = atom_string(to_snake_case(&constructor.name)); 384 + if constructor.arguments.is_empty() { 385 385 name 386 386 } else { 387 387 let type_printer = TypePrinter::new(module_name); 388 - let args = c.arguments.iter().map(|a| type_printer.print(&a.type_)); 388 + let args = constructor 389 + .arguments 390 + .iter() 391 + .map(|argument| type_printer.print(&argument.type_)); 389 392 tuple(std::iter::once(name).chain(args)) 390 393 } 391 394 }) ··· 395 398 .nest(INDENT); 396 399 let type_printer = TypePrinter::new(module_name); 397 400 let params = join( 398 - typed_parameters.iter().map(|a| type_printer.print(a)), 401 + typed_parameters 402 + .iter() 403 + .map(|type_| type_printer.print(type_)), 399 404 ", ".to_doc(), 400 405 ); 401 406 let doc = if *opaque { "-opaque " } else { "-type " } ··· 3082 3087 ) -> im::HashSet<EcoString> { 3083 3088 let mut overridden_publicity = im::HashSet::new(); 3084 3089 3085 - for def in module.definitions.iter() { 3086 - if let Definition::ModuleConstant(c) = def { 3087 - if c.publicity.is_importable() { 3088 - find_referenced_private_functions(&c.value, &mut overridden_publicity) 3090 + for definition in module.definitions.iter() { 3091 + if let Definition::ModuleConstant(constant) = definition { 3092 + if constant.publicity.is_importable() { 3093 + find_referenced_private_functions(&constant.value, &mut overridden_publicity) 3089 3094 } 3090 3095 } 3091 3096 }
+8 -8
compiler-core/src/javascript.rs
··· 119 119 self.module 120 120 .definitions 121 121 .iter() 122 - .flat_map(|s| self.statement(s)), 122 + .flat_map(|definition| self.definition(definition)), 123 123 ); 124 124 125 125 // Two lines between each statement ··· 298 298 imports.register_module(path, [], [member]); 299 299 } 300 300 301 - pub fn statement(&mut self, statement: &'a TypedDefinition) -> Option<Output<'a>> { 302 - match statement { 301 + pub fn definition(&mut self, definition: &'a TypedDefinition) -> Option<Output<'a>> { 302 + match definition { 303 303 Definition::TypeAlias(TypeAlias { .. }) => None, 304 304 305 305 // Handled in collect_imports ··· 430 430 self.module 431 431 .definitions 432 432 .iter() 433 - .flat_map(|statement| match statement { 433 + .flat_map(|definition| match definition { 434 434 // If a custom type is unused then we don't need to generate code for it 435 435 Definition::CustomType(CustomType { location, .. }) 436 436 if self ··· 459 459 fn collect_imports(&mut self) -> Imports<'a> { 460 460 let mut imports = Imports::new(); 461 461 462 - for statement in &self.module.definitions { 463 - match statement { 462 + for definition in &self.module.definitions { 463 + match definition { 464 464 Definition::Import(Import { 465 465 module, 466 466 as_name, ··· 683 683 } 684 684 685 685 fn register_module_definitions_in_scope(&mut self) { 686 - for statement in self.module.definitions.iter() { 687 - match statement { 686 + for definition in self.module.definitions.iter() { 687 + match definition { 688 688 Definition::ModuleConstant(ModuleConstant { name, .. }) => { 689 689 self.register_in_scope(name) 690 690 }
+3 -3
compiler-core/src/javascript/typescript.rs
··· 197 197 .module 198 198 .definitions 199 199 .iter() 200 - .flat_map(|s| self.statement(s)); 200 + .flat_map(|definition| self.definition(definition)); 201 201 202 202 // Two lines between each statement 203 203 let mut statements: Vec<_> = ··· 364 364 } 365 365 } 366 366 367 - fn statement(&mut self, statement: &'a TypedDefinition) -> Vec<Output<'a>> { 368 - match statement { 367 + fn definition(&mut self, definition: &'a TypedDefinition) -> Vec<Output<'a>> { 368 + match definition { 369 369 Definition::TypeAlias(TypeAlias { 370 370 alias, 371 371 publicity,
+4 -4
compiler-core/src/language_server/code_action.rs
··· 1352 1352 ) -> Option<&'a Import<EcoString>> { 1353 1353 let mut matching_import = None; 1354 1354 1355 - for def in &self.module.ast.definitions { 1356 - if let ast::Definition::Import(import) = def { 1355 + for definition in &self.module.ast.definitions { 1356 + if let ast::Definition::Import(import) = definition { 1357 1357 let imported = if layer.is_value() { 1358 1358 &import.unqualified_values 1359 1359 } else { ··· 1906 1906 .ast 1907 1907 .definitions 1908 1908 .iter() 1909 - .find_map(|def| match def { 1909 + .find_map(|definition| match definition { 1910 1910 ast::Definition::Import(import) if import.module == *module_name => import 1911 1911 .unqualified_values 1912 1912 .iter() ··· 1928 1928 .ast 1929 1929 .definitions 1930 1930 .iter() 1931 - .find_map(|def| match def { 1931 + .find_map(|definition| match definition { 1932 1932 ast::Definition::Import(import) => { 1933 1933 if let Some(ty) = import 1934 1934 .unqualified_types
+15 -5
compiler-core/src/language_server/completer.rs
··· 565 565 566 566 // Find the function that the cursor is in and push completions for 567 567 // its arguments and local variables. 568 - if let Some(fun) = self.module.ast.definitions.iter().find_map(|d| match d { 569 - Definition::Function(f) if f.full_location().contains(cursor) => Some(f), 570 - _ => None, 571 - }) { 568 + if let Some(function) = 569 + self.module 570 + .ast 571 + .definitions 572 + .iter() 573 + .find_map(|definition| match definition { 574 + Definition::Function(function) 575 + if function.full_location().contains(cursor) => 576 + { 577 + Some(function) 578 + } 579 + _ => None, 580 + }) 581 + { 572 582 completions.extend( 573 - LocalCompletion::new(mod_name, insert_range, cursor).fn_completions(fun), 583 + LocalCompletion::new(mod_name, insert_range, cursor).fn_completions(function), 574 584 ); 575 585 } 576 586
+11 -6
compiler-core/src/language_server/engine.rs
··· 1565 1565 ast: &TypedModule, 1566 1566 hex_deps: &HashSet<EcoString>, 1567 1567 ) -> Option<String> { 1568 - let package_name = ast.definitions.iter().find_map(|def| match def { 1569 - Definition::Import(p) if p.module == module_name && hex_deps.contains(&p.package) => { 1570 - Some(&p.package) 1571 - } 1572 - _ => None, 1573 - })?; 1568 + let package_name = ast 1569 + .definitions 1570 + .iter() 1571 + .find_map(|definition| match definition { 1572 + Definition::Import(import) 1573 + if import.module == module_name && hex_deps.contains(&import.package) => 1574 + { 1575 + Some(&import.package) 1576 + } 1577 + _ => None, 1578 + })?; 1574 1579 1575 1580 Some(format_hexdocs_link_section( 1576 1581 package_name,