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

Configure Feed

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

LS: correctly update import on rename imported item with an import alias

author
Andrey
committer
Louis Pilfold
date (Jun 18, 2026, 11:29 AM +0100) commit 522ed22b parent 87e0e4a9 change-id xnvspply
+36 -14
+19 -3
compiler-core/src/analyse/imports.rs
··· 119 119 Publicity::Private, 120 120 ); 121 121 122 + let alias_location = SrcSpan { 123 + start: import.imported_name_location.end, 124 + end: import.location.end, 125 + }; 126 + 122 127 self.environment.references.register_type_reference( 123 128 type_info.module.clone(), 124 129 import.name.clone(), 125 130 imported_name, 126 131 import.imported_name_location, 127 - ReferenceKind::Import, 132 + ReferenceKind::Import(alias_location), 128 133 ); 129 134 130 135 if let Err(e) = self ··· 197 202 Publicity::Private, 198 203 ); 199 204 205 + let alias_location = SrcSpan { 206 + start: import.imported_name_location.end, 207 + end: import.location.end, 208 + }; 209 + 200 210 self.environment.references.register_value_reference( 201 211 module.clone(), 202 212 import_name.clone(), 203 213 used_name, 204 214 import.imported_name_location, 205 - ReferenceKind::Import, 215 + ReferenceKind::Import(alias_location), 206 216 ); 207 217 } 208 218 ValueConstructorVariant::ModuleConstant { module, .. } ··· 215 225 location, 216 226 Publicity::Private, 217 227 ); 228 + 229 + let alias_location = SrcSpan { 230 + start: import.imported_name_location.end, 231 + end: import.location.end, 232 + }; 233 + 218 234 self.environment.references.register_value_reference( 219 235 module.clone(), 220 236 import_name.clone(), 221 237 used_name, 222 238 import.imported_name_location, 223 - ReferenceKind::Import, 239 + ReferenceKind::Import(alias_location), 224 240 ); 225 241 } 226 242 ValueConstructorVariant::LocalVariable { .. } => {}
+1 -1
compiler-core/src/metadata/tests.rs
··· 1972 1972 vec![ 1973 1973 Reference { 1974 1974 location: SrcSpan::new(6, 9), 1975 - kind: ReferenceKind::Import, 1975 + kind: ReferenceKind::Import(SrcSpan::new(9, 9)), 1976 1976 }, 1977 1977 Reference { 1978 1978 location: SrcSpan::new(90, 108),
+9 -3
compiler-core/src/reference.rs
··· 73 73 /// import gleam/dynamic/decode.{type Dynamic} 74 74 /// // ^^^^^^^ Import 75 75 /// ``` 76 - Import, 76 + /// The contained span is the location of `as ...` part, if it exists, 77 + /// otherwise it will just be empty. For example: 78 + /// ```gleam 79 + /// import gleam/option.{None as Nothing} 80 + /// // ^^^^^^^^^^^ Alias span 81 + /// ``` 82 + Import(SrcSpan), 77 83 /// The original definition location of a type or value. This also counts as 78 84 /// a reference for renaming and "find references" purposes. For example: 79 85 /// ··· 597 603 }; 598 604 self.register_module_name_reference(module.clone(), reference); 599 605 } 600 - ReferenceKind::Import | ReferenceKind::Definition => {} 606 + ReferenceKind::Import(_) | ReferenceKind::Definition => {} 601 607 ReferenceKind::Alias | ReferenceKind::Unqualified => { 602 608 let target = self.get_or_create_node(referenced_name.clone(), EntityLayer::Value); 603 609 _ = self.graph.add_edge(self.current_node, target, ()); ··· 631 637 }; 632 638 self.register_module_name_reference(module.clone(), reference); 633 639 } 634 - ReferenceKind::Import | ReferenceKind::Definition => {} 640 + ReferenceKind::Import(_) | ReferenceKind::Definition => {} 635 641 ReferenceKind::Alias | ReferenceKind::Unqualified => { 636 642 self.register_type_reference_in_call_graph(referenced_name.clone()) 637 643 }
+3 -3
language-server/src/rename.rs
··· 226 226 ReferenceKind::Alias => {} 227 227 ReferenceKind::Qualified { .. } 228 228 | ReferenceKind::Unqualified 229 - | ReferenceKind::Import 229 + | ReferenceKind::Import(_) 230 230 | ReferenceKind::Definition => edits.replace(reference.location, new_name.clone()), 231 231 } 232 232 } ··· 367 367 ReferenceKind::Unqualified | ReferenceKind::Alias => { 368 368 edits.replace(reference.location, params.new_name.clone()) 369 369 } 370 - ReferenceKind::Import => { 371 - edits.insert(reference.location.end, format!(" as {}", params.new_name)); 370 + ReferenceKind::Import(alias_location) => { 371 + edits.replace(alias_location, format!(" as {}", params.new_name)); 372 372 found_import = true; 373 373 } 374 374 ReferenceKind::Definition => {}
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__rename__rename_item_with_import_alias.snap
··· 30 30 31 31 -- app.gleam 32 32 33 - import wibble.{Wibble as Wubble as Wobble} 33 + import wibble.{Wibble as Wubble} 34 34 35 35 pub fn main() { 36 36 let _ = Wubble
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__rename__rename_type_with_import_alias.snap
··· 30 30 31 31 -- app.gleam 32 32 33 - import wibble.{type Wibble as Wubble as Wobble} 33 + import wibble.{type Wibble as Wubble} 34 34 35 35 pub fn main() -> Wubble { 36 36 todo
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__rename__rename_type_with_import_alias_and_other_imported_items.snap
··· 30 30 31 31 -- app.gleam 32 32 33 - import wibble.{Wibble as Wobble, type Wibble as Wubble as Wobble} 33 + import wibble.{Wibble as Wobble, type Wibble as Wubble} 34 34 35 35 pub fn main() -> Wubble { 36 36 Wobble
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__rename__rename_value_with_import_alias_and_other_imported_items.snap
··· 30 30 31 31 -- app.gleam 32 32 33 - import wibble.{Wibble as Wubble as Wobble, type Wibble as Wobble} 33 + import wibble.{Wibble as Wubble, type Wibble as Wobble} 34 34 35 35 pub fn main() -> Wobble { 36 36 Wubble