Read signature declarations by name in editor analysis
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.
modifiedRename a value declared in a module type
module type MT = { let inMt: int}
text
Before renaming inMt to renamed
After renaming inMt to renamed
`let inMt: int` ⇝ `renamed``inMt` ⇝ `renamed`
modifiedReferences 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
Before references of sigValue in the last line
After references of sigValue in the last line
none `sigValue` in `let sigValue: int` of WithSig.S`sigValue` in `Sealed.Nested.sigValue`
modifiedReferences a module nested in a signature constraint
// SignatureItems.resmodule M: { module Inner: { let v: int }} = { module Inner = { let v = 1 }}// SignatureItemsUse.reslet v = SignatureItems.M.Inner.v
text
Before references of v in M's signature
After 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 docsnapshots (DocExtraction2, DocExtractionRes): their locations now point at a value's name, or at itsletline 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,withconstraints and.cmifiles. Their values still get the whole item as location; the types have nothing better. - What does not change? Module types copied by an
includestay unregistered, and renaming a value in a module type still does not rename the modules that implement it.