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

Configure Feed

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

Allow triggering rename or references in as clause

author
Gavin Morrow
committer
Louis Pilfold
date (Jul 9, 2026, 6:07 PM +0100) commit c64ca9c9 parent 8524dc06 change-id oluxlzow
+73 -12
+4 -2
compiler-core/src/ast.rs
··· 1005 1005 location, 1006 1006 imported_name_location, 1007 1007 name, 1008 - as_name: _, 1008 + as_name, 1009 1009 }) = self 1010 1010 .unqualified_values 1011 1011 .iter() ··· 1018 1018 is_type: false, 1019 1019 location, 1020 1020 imported_name_location, 1021 + as_name: as_name.as_ref(), 1021 1022 }, 1022 1023 )); 1023 1024 } ··· 1026 1027 location, 1027 1028 imported_name_location, 1028 1029 name, 1029 - as_name: _, 1030 + as_name, 1030 1031 }) = self 1031 1032 .unqualified_types 1032 1033 .iter() ··· 1039 1040 is_type: true, 1040 1041 location, 1041 1042 imported_name_location, 1043 + as_name: as_name.as_ref(), 1042 1044 }, 1043 1045 )); 1044 1046 }
+19
compiler-core/src/build.rs
··· 429 429 /// The location excluding the potential `as ...` clause, or the `type` keyword. 430 430 /// For example, in `type Wibble as Wobble`, it covers `Wibble`. 431 431 pub imported_name_location: &'a SrcSpan, 432 + pub as_name: Option<&'a EcoString>, 432 433 } 433 434 434 435 impl<'a> UnqualifiedImport<'a> { 436 + /// If the import is aliased, it is the start of the alias. Otherwise, it is 437 + /// the start of the imported name. 438 + /// 439 + /// For example, in `type Wibble as Wobble`, the used name will start at 440 + /// `Wobble`. In `type Wibble`, it will start at `Wibble`. 441 + pub fn used_name_start(&self) -> u32 { 442 + match self.as_name { 443 + // For aliases, the location span will cover the whole of `type 444 + // Wibble as Wobble`. 445 + // So, the used name will start 6 chars (length of `Wobble`) before 446 + // the span ends. 447 + Some(as_name) => self.location.end - as_name.len() as u32, 448 + // For non-aliased imports, use the start of the imported name 449 + // location. It covers `Wibble` in `type Wibble as Wobble`. 450 + None => self.imported_name_location.start, 451 + } 452 + } 453 + 435 454 pub fn name_kind(&self) -> Named { 436 455 let is_upname = match self.name.chars().next() { 437 456 Some(c) => c.is_uppercase(),
+19 -6
language-server/src/engine.rs
··· 888 888 Referenced::ModuleValue { 889 889 module, 890 890 location, 891 + name_start, 891 892 target_kind, 892 893 .. 893 894 } 894 895 | Referenced::ModuleType { 895 896 module, 896 897 location, 898 + name_start, 897 899 target_kind, 898 900 .. 899 901 }, ··· 904 906 RenameTarget::Unqualified | RenameTarget::Definition => true, 905 907 }; 906 908 if rename_allowed { 909 + // The location field is sometimes larger than the 910 + // location of the actual name. In most cases they are 911 + // the same, but in import statements that are for types 912 + // and/or are aliased, the location is larger than the 913 + // name. 914 + // 915 + // For example, in `import m.{type Wibble as Wobble}`, 916 + // location will cover `type Wibble as Wobble` but 917 + // the name is just `Wobble`. In every case (including 918 + // non-imports), the name is at the very end of the 919 + // location span. 920 + let location = SrcSpan { 921 + start: name_start, 922 + end: location.end, 923 + }; 907 924 success_response(location) 908 925 } else { 909 926 None ··· 1134 1151 )) 1135 1152 } 1136 1153 }, 1137 - Some(Referenced::ModuleType { 1138 - module, 1139 - name, 1140 - location, 1141 - .. 1142 - }) if location.contains(byte_index) => match search_scope { 1154 + Some(Referenced::ModuleType { module, name, .. }) => match search_scope { 1143 1155 FindReferencesSearchScope::AllModules => Some(find_module_references( 1144 1156 module, 1145 1157 name, ··· 1312 1324 is_type, 1313 1325 location, 1314 1326 imported_name_location: _, 1327 + as_name: _, 1315 1328 }) => this 1316 1329 .compiler 1317 1330 .get_module_interface(module_name.as_str())
+31 -4
language-server/src/reference.rs
··· 41 41 module: EcoString, 42 42 name: EcoString, 43 43 location: SrcSpan, 44 + /// The starting position of the name. 45 + /// 46 + /// For example, when location covers an aliased import statement, e.g. 47 + /// `wibble as wobble`, this will point to the start of `wobble`. 48 + /// In all other cases, this is the same as `location.start`. 49 + name_start: u32, 44 50 name_kind: Named, 45 51 target_kind: RenameTarget, 46 52 }, ··· 48 54 module: EcoString, 49 55 name: EcoString, 50 56 location: SrcSpan, 57 + /// The starting position of the name. 58 + /// 59 + /// For example, when location covers an aliased import statement, e.g. 60 + /// `type Wibble as Wobble`, this will point to the start of `Wobble`. 61 + /// When location covers a non-aliased import statement, e.g. `type 62 + /// Wibble`, this will point to the start of `Wibble`. 63 + /// In all other cases, this is the same as `location.start`. 64 + name_start: u32, 51 65 target_kind: RenameTarget, 52 66 }, 53 67 TypeVariable { ··· 161 175 module: module.clone(), 162 176 name: name.clone(), 163 177 location: *location, 178 + name_start: location.start, 164 179 name_kind: Named::Function, 165 180 target_kind: RenameTarget::Unqualified, 166 181 }), ··· 181 196 module: module_name.clone(), 182 197 name: label.clone(), 183 198 location: SrcSpan::new(*field_start, location.end), 199 + name_start: *field_start, 184 200 name_kind: Named::Function, 185 201 target_kind: RenameTarget::Qualified, 186 202 }), ··· 197 213 module: current_module.clone(), 198 214 name: name.clone(), 199 215 location: *location, 216 + name_start: location.start, 200 217 name_kind: Named::Function, 201 218 target_kind: RenameTarget::Definition, 202 219 }), ··· 216 233 module: module.clone(), 217 234 name: name.clone(), 218 235 location: *location, 236 + name_start: location.start, 219 237 name_kind: Named::CustomTypeVariant, 220 238 target_kind: RenameTarget::Unqualified, 221 239 }), ··· 234 252 module: module_name.clone(), 235 253 name: label.clone(), 236 254 location: SrcSpan::new(*field_start, location.end), 255 + name_start: *field_start, 237 256 name_kind: Named::CustomTypeVariant, 238 257 target_kind: RenameTarget::Qualified, 239 258 }), ··· 245 264 module: current_module.clone(), 246 265 name: name.clone(), 247 266 location: *name_location, 267 + name_start: name_location.start, 248 268 name_kind: Named::CustomTypeVariant, 249 269 target_kind: RenameTarget::Definition, 250 270 }), ··· 257 277 module: constructor.module.clone(), 258 278 name: constructor.name.clone(), 259 279 location: *location, 280 + name_start: location.start, 260 281 name_kind: Named::CustomTypeVariant, 261 282 target_kind: if module_select.is_some() { 262 283 RenameTarget::Qualified ··· 287 308 module, 288 309 name, 289 310 location, 311 + name_start: location.start, 290 312 target_kind, 291 313 }) 292 314 } ··· 312 334 module: current_module.clone(), 313 335 name: name.clone(), 314 336 location: *name_location, 337 + name_start: name_location.start, 315 338 target_kind: RenameTarget::Definition, 316 339 }), 317 340 Located::ModuleName { ··· 375 398 module: module_name.clone(), 376 399 name: label.clone(), 377 400 location: SrcSpan::new(*field_start, location.end), 401 + name_start: *field_start, 378 402 name_kind: Named::Function, 379 403 target_kind: RenameTarget::Qualified, 380 404 }), ··· 384 408 name, 385 409 module, 386 410 is_type, 387 - location: _, 388 - imported_name_location, 411 + location, 412 + imported_name_location: _, 413 + as_name: _, 389 414 }, 390 415 ) => { 391 416 if is_type { 392 417 Some(Referenced::ModuleType { 393 418 module: module.clone(), 394 419 name: name.clone(), 395 - location: *imported_name_location, 420 + location: *location, 421 + name_start: import.used_name_start(), 396 422 target_kind: RenameTarget::Unqualified, 397 423 }) 398 424 } else { 399 425 Some(Referenced::ModuleValue { 400 426 module: module.clone(), 401 427 name: name.clone(), 402 - location: *imported_name_location, 428 + location: *location, 429 + name_start: import.used_name_start(), 403 430 name_kind: import.name_kind(), 404 431 target_kind: RenameTarget::Unqualified, 405 432 })