Skip to content

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

Merged
kubouch merged 1 commit intonushell:mainfrom
blindFS:pr
Jan 26, 2025
Merged

refactor(parser): use var_id for most constants in ResolvedImportPattern#14920
kubouch merged 1 commit intonushell:mainfrom
blindFS:pr

Conversation

@blindFS
Copy link
Copy Markdown
Contributor

@blindFS blindFS commented Jan 26, 2025

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

@blindFS blindFS changed the title refactor(lsp): use var_id for most constants in ResolvedImportPattern refactor(parser): use var_id for most constants in ResolvedImportPattern Jan 26, 2025
@fdncred fdncred added A:LSP Language Server Protocol (nu-lsp) A:parser Issues related to parsing and removed A:LSP Language Server Protocol (nu-lsp) labels Jan 26, 2025
@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Jan 26, 2025

I think this is fine. Maybe VarId was changed to Value because it wasn't needed anymore? Anyway, I don't see any problem with this PR. Thanks!

@kubouch kubouch merged commit f46f8b2 into nushell:main Jan 26, 2025
@github-actions github-actions bot added this to the v0.102.0 milestone Jan 26, 2025
fdncred pushed a commit that referenced this pull request May 1, 2025
)

A bug introduced by #14920 

When `use module.nu` is called, all exported constants defined in it are
added to the scope.

# Description

On the branch of empty arguments, the constant var_id vector should be
empty, only constant_values (for `$module.foo` access) are injected.

# User-Facing Changes

# Tests + Formatting

~todo!~

adjusted

# After Submitting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants