refactor(parser): use var_id for most constants in ResolvedImportPattern (#14920)

# Description

This PR replaces most of the constants in `ResolvedImportPattern` from
values to VarIds, this has benefits of:
1. less duplicated variables in state
2. precise span of variable, for example when calling `goto def` on a
const imported by the `use` command, this allows it to find the original
definition, instead of where the `use` command is.

Note that the logic is different here for nested submodules, not all
values are flattened and propagated to the outmost record variable, but
I didn't find any differences in real world usage.

I noticed that it was changed from `VarId` to `Value` in #10049.
Maybe @kubouch can find some edge cases where this PR fails to work as
expected.

In my view, the record constants for `ResolvedImportPattern` should even
reduced to single entry, if not able to get rid of.

# User-Facing Changes

# Tests + Formatting

# After Submitting
This commit is contained in:
zc he
2025-01-26 21:43:34 +08:00
committed by GitHub
parent f88ed6ecd5
commit f46f8b286b
3 changed files with 58 additions and 24 deletions

View File

@ -296,10 +296,10 @@ fn try_find_id_in_use(
.find_module(name)
.and_then(|module_id| (module_id == *module_id_ref).then_some(Id::Module(module_id))),
None => working_set
.find_variable(name)
.map(Id::Variable)
.find_module(name)
.map(Id::Module)
.or(working_set.find_decl(name).map(Id::Declaration))
.or(working_set.find_module(name).map(Id::Module)),
.or(working_set.find_variable(name).map(Id::Variable)),
_ => None,
};
let check_location = |span: &Span| location.map_or(true, |pos| span.contains(*pos));