Skip to content

IntelliSense: alias-shadowing correctness in nested scopes #41

Description

@melonamin

Follow-up from #27. The core completion resolver handles alias.column for every case in #27 except implicit alias shadowing when the same alias name is bound at multiple nesting levels within a single statement.

Repro

Two tests live in crates/flowscope-core/tests/completion_items.rs, currently #[ignore]-d:

  • alias_shadowing_inner_subquery_wins — inner SELECT 1 FROM orders u shadows outer SELECT * FROM users u; cursor at inner u. should only surface orders columns (total), never users columns (email). Today it surfaces both.
  • alias_shadowing_outer_scope_unaffected — cursor at the outer u. after a shadowing subquery should still only surface users columns. Today it also surfaces the inner-scope shadow (total).

Working baseline for reference: alias_shadowing_across_statements (unignored, passing) — two statements separated by ; each bind alias t to a different table; statement 2 resolves correctly. Statement-level isolation is already robust.

Root cause (working theory)

crates/flowscope-core/src/completion/ast_extractor.rs produces a flat tables_in_scope: Vec<CompletionTable> — every FROM/JOIN/subquery entry is collected without scope-depth tagging. resolve_qualifier in context.rs:1417 then matches aliases across the full vector, so both bindings of a shadowed alias appear.

Fix direction: tag each entry with a scope identifier (or the enclosing SELECT node) and, before resolution, filter to scopes that enclose the cursor — picking the innermost on ambiguity.

Acceptance

Un-`#[ignore]` the two tests and get `cargo test -p flowscope-core --test completion_items alias_shadowing` green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions