The add-missing-import code action doesn't work when a variable has the same name
#4,513 opened on Apr 27, 2025
Description
(This might not be desired behavior, but I thought it was worth making the issue)[
Playground link](https://playground.gleam.run/#N4IgbgpgTgzglgewHYgFwEYA0IDGyAuES+aIADgK4BGABAGZI0C2AhnEgBQCUNwAOoxoAbCPhox8UdgHMaAXhp8QACzhKBNcZJk0APgD4tUpNIB0dOLHwCAviBtA).
The code action to import something that currently isn't imported doesn't trigger when a variable has the same name as your desired module, since the compiler assumes you're trying to access a field of the variable's type. I think it would be more intuitive if the code action was still offered.
One problem I see arising from this is if you have a custom type that provides the same record as your desired import. Here's some playground code to demonstrate this. It also could be slightly unintuitive if you have a field of a very similar name, and you just made a typo (example). If we really wanted to avoid cases like this, it could only trigger on variables that don't have any fields - since it's then much less likely that the user actually intended to access a field.