···424424pub struct UnqualifiedImport<'a> {
425425 pub name: &'a EcoString,
426426 pub module: &'a EcoString,
427427- pub is_type: bool,
428427 pub location: &'a SrcSpan,
429429- /// The location excluding the potential `as ...` clause, or the `type` keyword.
430430- /// For example, in `type Wibble as Wobble`, it covers `Wibble`.
431431- pub imported_name_location: &'a SrcSpan,
428428+ /// The position of the original name. For example, in `type Wibble as
429429+ /// Wobble`, it points to the start of `Wibble`.
430430+ pub name_position: u32,
432431 pub as_name: Option<&'a EcoString>,
433432}
434433435434impl<'a> UnqualifiedImport<'a> {
435435+ /// The location of the original name, excluding the potential `as ...`
436436+ /// clause or the `type` keyword. For example, in `type Wibble as Wobble`,
437437+ /// it covers `Wibble`.
438438+ pub fn name_location(&self) -> SrcSpan {
439439+ SrcSpan::new(
440440+ self.name_position,
441441+ self.name_position + self.name.len() as u32,
442442+ )
443443+ }
444444+436445 /// If the import is aliased, it is the start of the alias. Otherwise, it is
437446 /// the start of the imported name.
438447 ///
439448 /// For example, in `type Wibble as Wobble`, the used name will start at
440449 /// `Wobble`. In `type Wibble`, it will start at `Wibble`.
441441- pub fn used_name_start(&self) -> u32 {
450450+ pub fn used_name_position(&self) -> u32 {
442451 match self.as_name {
443452 // For aliases, the location span will cover the whole of `type
444453 // Wibble as Wobble`.
···447456 Some(as_name) => self.location.end - as_name.len() as u32,
448457 // For non-aliased imports, use the start of the imported name
449458 // location. It covers `Wibble` in `type Wibble as Wobble`.
450450- None => self.imported_name_location.start,
459459+ None => self.name_position,
451460 }
452461 }
453462···462471 } else {
463472 Named::Function
464473 }
474474+ }
475475+476476+ pub fn is_type(&self) -> bool {
477477+ // If the position is not at the start location then that means
478478+ // that there is a `type` keyword before it, along with an amount of
479479+ // whitespace and optional comments
480480+ self.name_position != self.location.start
465481 }
466482}
467483···661677 module: None,
662678 span: record.location,
663679 }),
664664- Self::UnqualifiedImport(UnqualifiedImport {
665665- module,
666666- name,
667667- is_type,
668668- ..
669669- }) => importable_modules.get(*module).and_then(|m| {
670670- if *is_type {
671671- m.types.get(*name).map(|t| DefinitionLocation {
672672- module: Some((*module).clone()),
673673- span: t.origin,
674674- })
675675- } else {
676676- m.values.get(*name).map(|v| DefinitionLocation {
677677- module: Some((*module).clone()),
678678- span: v.definition_location().span,
679679- })
680680- }
681681- }),
680680+ Self::UnqualifiedImport(import @ UnqualifiedImport { module, name, .. }) => {
681681+ importable_modules.get(*module).and_then(|m| {
682682+ if import.is_type() {
683683+ m.types.get(*name).map(|t| DefinitionLocation {
684684+ module: Some((*module).clone()),
685685+ span: t.origin,
686686+ })
687687+ } else {
688688+ m.values.get(*name).map(|v| DefinitionLocation {
689689+ module: Some((*module).clone()),
690690+ span: v.definition_location().span,
691691+ })
692692+ }
693693+ })
694694+ }
682695 Self::Arg(_) => None,
683696 Self::Annotation { type_, .. } => self.type_location(importable_modules, type_.clone()),
684697 Self::Label { .. } => None,