Treat included members as copies of their original declarations in editor analysis
Why
An include copies the members of a module under new stamps, at the positions of the original declarations. Analysis registered each copy as a declaration of the including file. An include does not rename constructors, so the copied Dot and Box below keep their stamps from Lib's compilation, which are the stamps of v0 and v1 in Main. That hid v0 and v1, listed bogus locations and lost their uses in other files. The copy of fv was a second declaration at the position of let fv, so references from the declaration and from the use split.
modifiedReferences include
// Lib.resmodule type T = { type t}module Make = (X: T) => { type shape = Dot | Box(X.t)} // Main.resinclude Lib.Make({ type t = int})let v0 = 0let v1 = 1let v2 = 2module type T = { type t}module F = (X: T) => { let fv = 1}include F({ type t = int})let u = fv // Other.reslet w = Main.v0 + Main.v1
text
modifiedReferences constructor of an included type
// Main.res, with Lib.res as aboveinclude Lib.Make({ type t = int})let v0 = 0let v1 = 1let dot = Dotlet box = Box(1)
text
A copy whose original member is found is no longer a declaration of the including file: it gets no definition item and no declaration reference, and the constructors of an included type are not put in the stamp table. Find References on a value, type or module collects the original member and all its copies in the file. Constructors and record fields of an included type are looked up in the type they were copied from, which links them to their declaration in the other file.
Review
- How is the original member found? The copy's module path is
IncludedModule (source, _), sosource.nameis resolved like any other path. In this file that gives the original stamp. - And when the member is in another file? Find References on the copy adds the references of the original member, found in its file, to the copy's own: the uses of the copy in this file and the uses other files record under this file's path. For a constructor or field the copy has the other file's stamps, so its uses here are recorded under the other file and the stamp is not looked up in this file. Going the other way, from a use linked to the other file, the copies included into this file add the uses recorded under this file's path. From the declaration in the other file, uses through this file's path are still not found, as on master.
- What about members of a module nested in the included one? A nested module copied by an include now records itself in its members' module path, as
ExportedModuleunder theIncludedModule, andModule_path.included_pathrebuildssource.Nested.name. Without that, the copy ofNested.xwould resolve tosource.xand merge the references of the two values. - Why do constructor and field references also go through the family of their type? Other files reference a constructor of an included type by the copy's path (
Main.L1), while uses in the file are linked to the original type. Each type in the family contributes the references under its own path. The constructors of a type and of its copies share stamps, so a location found twice is reported once; a lone stamp is handled as before. - What if the source can't be resolved, such as a module type included in a
.resi, which analysis does not register? Then the copy stays a declaration, as before.