Skip to content

Go-to definition fails for module aliases (stdlib and user code) #8003

@cristianoc

Description

@cristianoc

Overview

Go-to definition fails whenever a module alias is involved. Minimal repro:

module Base = {
  let value = 1
  module Nested = { let value = 42 }
}

module Alias = {
  module B = Base
}

let x = Alias.B.value
let y = Alias.B.Nested.value

Running the analysis binary with the cursor on Alias.B.value:

./_build/install/default/bin/rescript-editor-analysis definition /tmp/self_alias.res 8 16

Expected: jump to Base.value. Actual: returns null, so editors stay put.

Stdlib impact

packages/@rescript/runtime/Stdlib.res exposes aliases exactly like this (e.g. module List = Stdlib_List), and navigating on List.map hits the same path and lands at (0,0).

Details

  • .cmt metadata still contains the correct spans (Stdlib_List.cmt shows Value map (402,04--402,07)), so location info is present.
  • Instrumented analysis/src/Commands.ml and analysis/src/References.ml. The alias case produces locItem=… LModule GlobalReference. resolveModuleReference takes the GlobalMod branch (resolveModuleReference GlobalMod Stdlib_List), which yields (file, None).
  • resolveModuleDefinition then returns Uri.toTopLevelLoc, so the emitted range is (0,0) even though declaredForLoc already carries the real location.
  • The same behaviour reproduces outside the stdlib with the self-contained example above (e.g. Alias.B.value returns null).

Ask

Teach References.definition (or its resolver) to follow module aliases through to the underlying declaration so both stdlib and user-defined aliases resolve to the actual source location.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions