Skip to content

Fix editor analysis for declarations in module types, signatures and .resi files - #9332

Merged
cknitt merged 1 commit into
fix-uri-is-interfacefrom
fix-9324-signature-declarations
Nov 19, 2026
Merged

cknitt merged 1 commit into
fix-uri-is-interfacefrom
fix-9324-signature-declarations

Conversation

@cknitt

@cknitt cknitt commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Editor analysis reads the declarations in module types and signature constraints from their types. A type only knows where a whole item is, not where its name is. This causes three bugs:

  • Renaming a value declared in a module type replaces its whole declaration, such as let x: int, with the new name instead of just the name.
  • Module types nested in another module type are not registered, so Find References on their values returns nothing.
  • Modules nested in a signature constraint lose their name in the module path, so Find References misses their uses in other files.

With this change, module types and signature constraints written in source are read from the typed tree, which has the location of each name. Nested modules keep their name in the module path.

Tests: new fixtures SignatureItems.res, SignatureItemsUse.res and SignatureItemsIntf.res/.resi. In the existing snapshots References, DefinitionWithInterface.res and three rescript-tools doc snapshots, locations now point at the name instead of the whole item.

Not fixed: renaming a value in a module type does not rename the modules that implement it.

Stacked on #9337.

Fixes #9324

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Fix editor rename, references and go to definition for values declared in module types, module signatures and .resi files.

Semantic Diff

1 commit · Full page

Read signature declarations by name in editor analysis

fe98bb0 · cknitt + Claude · Nov 19, 2026, 17:04 UTC

Why

Editor analysis reads the declarations in module types and signature constraints from their types. A type only knows where a whole item is, not where its name is. So rename replaces a value's whole declaration instead of its name, module types nested in a module type are not registered, and modules nested in a signature constraint lose their name in the module path, which hides their uses in other files.

Module types and signature constraints written in source are now read from the typed tree, which has the location of each name. Nested modules keep their name in the module path.

Rename modified (a value declared in a module type)

module type MT = {
  let inMt: int
}

text · renaming inMt to renamed

-`let inMt: int` ⇝ `renamed`
+`inMt` ⇝ `renamed`

References modified (a value of a module type nested in a module type)

module type WithSig = {
  module type S = {
    let sigValue: int
  }
  module Nested: S
}
module Sealed: WithSig = {
  module type S = {
    let sigValue: int
  }
  module Nested = {
    let sigValue = 1
  }
}
let sv = Sealed.Nested.sigValue

text · references of sigValue in the last line

-none
+`sigValue` in `let sigValue: int` of WithSig.S
+`sigValue` in `Sealed.Nested.sigValue`

References modified (a module nested in a signature constraint)

// SignatureItems.res
module M: {
  module Inner: {
    let v: int
  }
} = {
  module Inner = {
    let v = 1
  }
}
// SignatureItemsUse.res
let v = SignatureItems.M.Inner.v

text · references of v in M's signature

-`let v: int` (the whole declaration)
+`v` in `let v: int`
+`v` in `SignatureItems.M.Inner.v` in SignatureItemsUse.res

Review

  • Which existing snapshots change? References, DefinitionWithInterface.res and three rescript-tools doc snapshots (DocExtraction2, DocExtractionRes): their locations now point at a value's name, or at its let line instead of the doc comment above it.
  • Which signatures are still read from types? Signatures that have no source: those of include, module type of, with constraints and .cmi files. Their values still get the whole item as location; the types have nothing better.
  • What does not change? Module types copied by an include stay unregistered, and renaming a value in a module type still does not rename the modules that implement it.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 639,849,023 → 639,848,738 (±0.00%).

Generated projects: 629,813,782 → 629,813,711 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 9,210,478,767 → 9,210,478,767 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 25,919,386 → 25,919,386 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request fe98bb0 compared with base 42598c1 in this run.

@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from b6796a8 to 8ac0a09 Compare November 19, 2026 06:36
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.16%. Comparing base (8aa74ec) to head (fe98bb0).

Files with missing lines Patch % Lines
analysis/src/process_cmt.ml 92.00% 2 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           fix-uri-is-interface    #9332   +/-   ##
=====================================================
  Coverage                 82.15%   82.16%           
=====================================================
  Files                       456      456           
  Lines                     65656    65668   +12     
=====================================================
+ Hits                      53939    53955   +16     
+ Misses                    11717    11713    -4     
Files with missing lines Coverage Δ
analysis/src/process_cmt.ml 84.95% <92.00%> (-0.39%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9332

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9332

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9332

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9332

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9332

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9332

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9332

commit: fe98bb0

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-20T04:43:33.764214Z
We couldn’t complete this review. Comment @codex review to try again.
3a3ea2a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 8ac0a09366

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from 8ac0a09 to 39c4de9 Compare November 19, 2026 17:04
@cknitt
cknitt changed the base branch from master to fix-uri-is-interface November 19, 2026 17:05
@cknitt
cknitt added this pull request to stack #9338 November 19, 2026 17:05
@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from 39c4de9 to 7955ee9 Compare November 19, 2026 17:11
@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch 2 times, most recently from db7c37a to 3192a35 Compare November 19, 2026 18:39
@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from 3192a35 to d5a1470 Compare November 19, 2026 18:45
@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from d5a1470 to e6e856e Compare November 19, 2026 18:55
Why:
    Editor analysis reads the declarations in module types and signature
    constraints from their types. A type only knows where a whole item is,
    not where its name is. So rename replaces a value's whole declaration
    instead of its name, module types nested in a module type are not
    registered, and modules nested in a signature constraint lose their
    name in the module path, which hides their uses in other files.

    Module types and signature constraints written in source are now read
    from the typed tree, which has the location of each name. Nested
    modules keep their name in the module path.

Rename modified (a value declared in a module type):
Example:
    module type MT = {
      let inMt: int
    }
Before (text): renaming inMt to renamed
    `let inMt: int` ⇝ `renamed`
After (text): renaming inMt to renamed
    `inMt` ⇝ `renamed`

References modified (a value of a module type nested in a module type):
Example:
    module type WithSig = {
      module type S = {
        let sigValue: int
      }
      module Nested: S
    }
    module Sealed: WithSig = {
      module type S = {
        let sigValue: int
      }
      module Nested = {
        let sigValue = 1
      }
    }
    let sv = Sealed.Nested.sigValue
Before (text): references of sigValue in the last line
    none
After (text): references of sigValue in the last line
    `sigValue` in `let sigValue: int` of WithSig.S
    `sigValue` in `Sealed.Nested.sigValue`

References modified (a module nested in a signature constraint):
Example:
    // SignatureItems.res
    module M: {
      module Inner: {
        let v: int
      }
    } = {
      module Inner = {
        let v = 1
      }
    }
    // SignatureItemsUse.res
    let v = SignatureItems.M.Inner.v
Before (text): references of v in M's signature
    `let v: int` (the whole declaration)
After (text): references of v in M's signature
    `v` in `let v: int`
    `v` in `SignatureItems.M.Inner.v` in SignatureItemsUse.res

Review: Which existing snapshots change? References,
DefinitionWithInterface.res and three `rescript-tools doc` snapshots
(DocExtraction2, DocExtractionRes): their locations now point at a
value's name, or at its `let` line instead of the doc comment above it.

Review: Which signatures are still read from types? Signatures that have
no source: those of `include`, `module type of`, `with` constraints and
`.cmi` files. Their values still get the whole item as location; the
types have nothing better.

Review: What does not change? Module types copied by an `include` stay
unregistered, and renaming a value in a module type still does not
rename the modules that implement it.

Fixes: #9324
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the fix-9324-signature-declarations branch from e6e856e to fe98bb0 Compare November 19, 2026 18:57
@cknitt
cknitt marked this pull request as ready for review November 19, 2026 19:06
@cknitt
cknitt merged commit 3a3ea2a into master Nov 19, 2026
23 of 25 checks passed
@cknitt
cknitt deleted the fix-9324-signature-declarations branch November 19, 2026 19:43
@cknitt

cknitt commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@cknitt

cknitt commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor analysis mishandles declarations read from signatures

2 participants