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

Configure Feed

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

Support `textDocument/reference` for imports

author
Gavin Morrow
committer
Louis Pilfold
date (Jul 9, 2026, 6:07 PM +0100) commit 48f6a0e5 parent 5b1de421 change-id zvksyqwo
+68 -9
+20 -7
compiler-core/src/ast.rs
··· 1001 1001 return None; 1002 1002 } 1003 1003 1004 - if let Some(unqualified) = self 1004 + if let Some(UnqualifiedImport { 1005 + location, 1006 + imported_name_location, 1007 + name, 1008 + as_name: _, 1009 + }) = self 1005 1010 .unqualified_values 1006 1011 .iter() 1007 1012 .find(|unqualified_value| unqualified_value.location.contains(byte_index)) 1008 1013 { 1009 1014 return Some(Located::UnqualifiedImport( 1010 1015 crate::build::UnqualifiedImport { 1011 - name: &unqualified.name, 1016 + name, 1012 1017 module: &self.module, 1013 1018 is_type: false, 1014 - location: &unqualified.location, 1019 + location, 1020 + imported_name_location, 1015 1021 }, 1016 1022 )); 1017 1023 } 1018 1024 1019 - if let Some(unqualified) = self 1025 + if let Some(UnqualifiedImport { 1026 + location, 1027 + imported_name_location, 1028 + name, 1029 + as_name: _, 1030 + }) = self 1020 1031 .unqualified_types 1021 1032 .iter() 1022 1033 .find(|unqualified_value| unqualified_value.location.contains(byte_index)) 1023 1034 { 1024 1035 return Some(Located::UnqualifiedImport( 1025 1036 crate::build::UnqualifiedImport { 1026 - name: &unqualified.name, 1037 + name, 1027 1038 module: &self.module, 1028 1039 is_type: true, 1029 - location: &unqualified.location, 1040 + location, 1041 + imported_name_location, 1030 1042 }, 1031 1043 )); 1032 1044 } ··· 1310 1322 #[derive(Debug, Clone, PartialEq, Eq)] 1311 1323 pub struct UnqualifiedImport { 1312 1324 pub location: SrcSpan, 1313 - /// The location excluding the potential `as ...` clause, or the `type` keyword 1325 + /// The location excluding the potential `as ...` clause, or the `type` keyword. 1326 + /// For example, in `type Wibble as Wobble`, it covers `Wibble`. 1314 1327 pub imported_name_location: SrcSpan, 1315 1328 pub name: EcoString, 1316 1329 pub as_name: Option<EcoString>,
+19
compiler-core/src/build.rs
··· 25 25 TypedModuleConstant, TypedPattern, TypedRecordConstructor, TypedStatement, TypedTypeAlias, 26 26 }; 27 27 use crate::reference; 28 + use crate::type_::error::Named; 28 29 use crate::type_::{Type, TypedCallArg}; 29 30 use crate::{ 30 31 ast::{Definition, SrcSpan, TypedModule}, ··· 425 426 pub module: &'a EcoString, 426 427 pub is_type: bool, 427 428 pub location: &'a SrcSpan, 429 + /// The location excluding the potential `as ...` clause, or the `type` keyword. 430 + /// For example, in `type Wibble as Wobble`, it covers `Wibble`. 431 + pub imported_name_location: &'a SrcSpan, 432 + } 433 + 434 + impl<'a> UnqualifiedImport<'a> { 435 + pub fn name_kind(&self) -> Named { 436 + let is_upname = match self.name.chars().next() { 437 + Some(c) => c.is_uppercase(), 438 + None => false, 439 + }; 440 + 441 + if is_upname { 442 + Named::CustomTypeVariant 443 + } else { 444 + Named::Function 445 + } 446 + } 428 447 } 429 448 430 449 /// The position of a located expression. Used to determine extra context,
+1
language-server/src/engine.rs
··· 1311 1311 module: module_name, 1312 1312 is_type, 1313 1313 location, 1314 + imported_name_location: _, 1314 1315 }) => this 1315 1316 .compiler 1316 1317 .get_module_interface(module_name.as_str())
+28 -2
language-server/src/reference.rs
··· 12 12 self, ArgNames, AssignName, BitArraySize, ClauseGuard, CustomType, Function, 13 13 ModuleConstant, Pattern, RecordConstructor, SrcSpan, TypedExpr, TypedModule, visit::Visit, 14 14 }, 15 - build::Located, 15 + build::{Located, UnqualifiedImport}, 16 16 reference::RecordLabel, 17 17 type_::{ 18 18 ModuleInterface, ModuleValueConstructor, Type, ValueConstructor, ValueConstructorVariant, ··· 379 379 target_kind: RenameTarget::Qualified, 380 380 }), 381 381 382 + Located::UnqualifiedImport( 383 + import @ UnqualifiedImport { 384 + name, 385 + module, 386 + is_type, 387 + location: _, 388 + imported_name_location, 389 + }, 390 + ) => { 391 + if is_type { 392 + Some(Referenced::ModuleType { 393 + module: module.clone(), 394 + name: name.clone(), 395 + location: *imported_name_location, 396 + target_kind: RenameTarget::Unqualified, 397 + }) 398 + } else { 399 + Some(Referenced::ModuleValue { 400 + module: module.clone(), 401 + name: name.clone(), 402 + location: *imported_name_location, 403 + name_kind: import.name_kind(), 404 + target_kind: RenameTarget::Unqualified, 405 + }) 406 + } 407 + } 408 + 382 409 Located::RecordLabelUsage { 383 410 record_type, 384 411 label, ··· 419 446 | Located::Statement(_) 420 447 | Located::Expression { .. } 421 448 | Located::FunctionBody(_) 422 - | Located::UnqualifiedImport(_) 423 449 | Located::Label { .. } 424 450 | Located::Constant(_) 425 451 | Located::ModuleFunction(_)