Skip to content

Commit d7d3c96

Browse files
cknittclaude
andcommitted
Map the members of an applied functor's module types to their declarations
Codex review on #9084: only a module type's own identifier was mapped to the functor body's, not those inside its signature, so a member reached through the applied module type, such as `X.value` with `X: Applied.S`, was missing from the references and renames of `S.value`. Module type signatures are now walked like those of modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 752dbc8 commit d7d3c96

3 files changed

Lines changed: 311 additions & 6 deletions

File tree

‎analysis/src/process_cmt.ml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,16 @@ let rec record_renamed_stamps table (original : Types.module_type)
227227
match (item, renamed_item) with
228228
| Sig_value (id, _), Sig_value (id', _)
229229
| Sig_type (id, _, _), Sig_type (id', _, _)
230-
| Sig_typext (id, _, _), Sig_typext (id', _, _)
231-
| Sig_modtype (id, _), Sig_modtype (id', _) ->
230+
| Sig_typext (id, _, _), Sig_typext (id', _, _) ->
232231
Some (id, id')
233232
| Sig_module (id, md, _), Sig_module (id', md', _) ->
234233
record_renamed_stamps table md.md_type md'.md_type;
235234
Some (id, id')
235+
| Sig_modtype (id, mtd), Sig_modtype (id', mtd') ->
236+
(match (mtd.mtd_type, mtd'.mtd_type) with
237+
| Some mty, Some mty' -> record_renamed_stamps table mty mty'
238+
| _ -> ());
239+
Some (id, id')
236240
| _ -> None
237241
in
238242
match ids with

‎tests/analysis_tests/tests/src/AppliedFunctor.res‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ let py = p.x
6666
module WithModType = (O: Ord) => {
6767
module type S = {
6868
let value: int
69+
// ^ref
6970
}
7071
module Nested: S = {
7172
let value = 1
@@ -79,3 +80,68 @@ let nv = Applied.Nested.value
7980

8081
// let nv2 = Applied.Nested.
8182
// ^com
83+
84+
let nv3 = Applied.Nested.value
85+
// ^ren renamed
86+
87+
module WithDeepModType = (O: Ord) => {
88+
module Outer = {
89+
module type T = {
90+
module Inner: {
91+
let deep: int
92+
// ^ref
93+
}
94+
module type Abstract
95+
}
96+
module First: T = {
97+
module Inner = {
98+
let deep = 1
99+
}
100+
module type Abstract = {}
101+
}
102+
module Second: T = {
103+
module Inner = {
104+
let deep = 2
105+
}
106+
module type Abstract = {}
107+
}
108+
}
109+
}
110+
111+
module Deep = WithDeepModType(IntOrd)
112+
113+
let d1 = Deep.Outer.First.Inner.deep
114+
let d2 = Deep.Outer.Second.Inner.deep
115+
// ^ref
116+
117+
module type WithSig = {
118+
module type S = {
119+
let sigValue: int
120+
// ^ref
121+
}
122+
module Nested: S
123+
}
124+
125+
module WithSigResult = (O: Ord): WithSig => {
126+
module type S = {
127+
let sigValue: int
128+
}
129+
module Nested = {
130+
let sigValue = 1
131+
}
132+
}
133+
134+
module AppliedSig = WithSigResult(IntOrd)
135+
136+
let sv = AppliedSig.Nested.sigValue
137+
// ^ref
138+
139+
module UseAppliedModType = (X: Applied.S) => {
140+
let v = X.value
141+
// ^ref
142+
}
143+
144+
module UseDeepModType = (Y: Deep.Outer.T) => {
145+
let d = Y.Inner.deep
146+
// ^ref
147+
}

‎tests/analysis_tests/tests/src/expected/AppliedFunctor.res.txt‎

Lines changed: 239 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,251 @@ Rename src/AppliedFunctor.res 62:11 y
223223
}
224224
]
225225

226-
Hover src/AppliedFunctor.res 76:24
226+
References src/AppliedFunctor.res 67:8
227+
[
228+
{
229+
"range": {
230+
"end": { "character": 18, "line": 67 },
231+
"start": { "character": 4, "line": 67 }
232+
},
233+
"uri": "file:///AppliedFunctor.res"
234+
},
235+
{
236+
"range": {
237+
"end": { "character": 29, "line": 77 },
238+
"start": { "character": 24, "line": 77 }
239+
},
240+
"uri": "file:///AppliedFunctor.res"
241+
},
242+
{
243+
"range": {
244+
"end": { "character": 30, "line": 83 },
245+
"start": { "character": 25, "line": 83 }
246+
},
247+
"uri": "file:///AppliedFunctor.res"
248+
},
249+
{
250+
"range": {
251+
"end": { "character": 17, "line": 139 },
252+
"start": { "character": 12, "line": 139 }
253+
},
254+
"uri": "file:///AppliedFunctor.res"
255+
}
256+
]
257+
258+
Hover src/AppliedFunctor.res 77:24
227259
{ "contents": { "kind": "markdown", "value": "```rescript\nint\n```" } }
228260

229-
Complete src/AppliedFunctor.res 79:28
230-
pos_cursor:[79:28] pos_no_white:[79:27] Found expr:[79:13->79:28]
231-
Pexp_ident Applied.Nested.:[79:13->79:28]
261+
Complete src/AppliedFunctor.res 80:28
262+
pos_cursor:[80:28] pos_no_white:[80:27] Found expr:[80:13->80:28]
263+
Pexp_ident Applied.Nested.:[80:13->80:28]
232264
Completable: Cpath Value[Applied, Nested, ""]
233265
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
234266
Resolved opens 1 Stdlib
235267
ContextPath Value[Applied, Nested, ""]
236268
Path Applied.Nested.
237269
[ { "detail": "int", "kind": 12, "label": "value", "tags": [] } ]
238270

271+
Rename src/AppliedFunctor.res 83:25 renamed
272+
[
273+
{
274+
"edits": [
275+
{
276+
"newText": "renamed",
277+
"range": {
278+
"end": { "character": 18, "line": 67 },
279+
"start": { "character": 4, "line": 67 }
280+
}
281+
},
282+
{
283+
"newText": "renamed",
284+
"range": {
285+
"end": { "character": 29, "line": 77 },
286+
"start": { "character": 24, "line": 77 }
287+
}
288+
},
289+
{
290+
"newText": "renamed",
291+
"range": {
292+
"end": { "character": 30, "line": 83 },
293+
"start": { "character": 25, "line": 83 }
294+
}
295+
},
296+
{
297+
"newText": "renamed",
298+
"range": {
299+
"end": { "character": 17, "line": 139 },
300+
"start": { "character": 12, "line": 139 }
301+
}
302+
}
303+
],
304+
"textDocument": { "uri": "file:///AppliedFunctor.res", "version": 0 }
305+
}
306+
]
307+
308+
References src/AppliedFunctor.res 90:12
309+
[
310+
{
311+
"range": {
312+
"end": { "character": 21, "line": 90 },
313+
"start": { "character": 8, "line": 90 }
314+
},
315+
"uri": "file:///AppliedFunctor.res"
316+
},
317+
{
318+
"range": {
319+
"end": { "character": 36, "line": 112 },
320+
"start": { "character": 32, "line": 112 }
321+
},
322+
"uri": "file:///AppliedFunctor.res"
323+
},
324+
{
325+
"range": {
326+
"end": { "character": 37, "line": 113 },
327+
"start": { "character": 33, "line": 113 }
328+
},
329+
"uri": "file:///AppliedFunctor.res"
330+
},
331+
{
332+
"range": {
333+
"end": { "character": 22, "line": 144 },
334+
"start": { "character": 18, "line": 144 }
335+
},
336+
"uri": "file:///AppliedFunctor.res"
337+
}
338+
]
339+
340+
References src/AppliedFunctor.res 113:33
341+
[
342+
{
343+
"range": {
344+
"end": { "character": 21, "line": 90 },
345+
"start": { "character": 8, "line": 90 }
346+
},
347+
"uri": "file:///AppliedFunctor.res"
348+
},
349+
{
350+
"range": {
351+
"end": { "character": 36, "line": 112 },
352+
"start": { "character": 32, "line": 112 }
353+
},
354+
"uri": "file:///AppliedFunctor.res"
355+
},
356+
{
357+
"range": {
358+
"end": { "character": 37, "line": 113 },
359+
"start": { "character": 33, "line": 113 }
360+
},
361+
"uri": "file:///AppliedFunctor.res"
362+
},
363+
{
364+
"range": {
365+
"end": { "character": 22, "line": 144 },
366+
"start": { "character": 18, "line": 144 }
367+
},
368+
"uri": "file:///AppliedFunctor.res"
369+
}
370+
]
371+
372+
References src/AppliedFunctor.res 118:8
373+
get_loc_item #8: heuristic for JSX with at most one child
374+
heuristic for: [makeProps, make, createElement], give the loc of `make`
375+
[
376+
{
377+
"range": {
378+
"end": { "character": 21, "line": 118 },
379+
"start": { "character": 4, "line": 118 }
380+
},
381+
"uri": "file:///AppliedFunctor.res"
382+
},
383+
{
384+
"range": {
385+
"end": { "character": 35, "line": 135 },
386+
"start": { "character": 27, "line": 135 }
387+
},
388+
"uri": "file:///AppliedFunctor.res"
389+
}
390+
]
391+
392+
References src/AppliedFunctor.res 135:27
393+
[
394+
{
395+
"range": {
396+
"end": { "character": 21, "line": 118 },
397+
"start": { "character": 4, "line": 118 }
398+
},
399+
"uri": "file:///AppliedFunctor.res"
400+
},
401+
{
402+
"range": {
403+
"end": { "character": 35, "line": 135 },
404+
"start": { "character": 27, "line": 135 }
405+
},
406+
"uri": "file:///AppliedFunctor.res"
407+
}
408+
]
409+
410+
References src/AppliedFunctor.res 139:12
411+
[
412+
{
413+
"range": {
414+
"end": { "character": 18, "line": 67 },
415+
"start": { "character": 4, "line": 67 }
416+
},
417+
"uri": "file:///AppliedFunctor.res"
418+
},
419+
{
420+
"range": {
421+
"end": { "character": 29, "line": 77 },
422+
"start": { "character": 24, "line": 77 }
423+
},
424+
"uri": "file:///AppliedFunctor.res"
425+
},
426+
{
427+
"range": {
428+
"end": { "character": 30, "line": 83 },
429+
"start": { "character": 25, "line": 83 }
430+
},
431+
"uri": "file:///AppliedFunctor.res"
432+
},
433+
{
434+
"range": {
435+
"end": { "character": 17, "line": 139 },
436+
"start": { "character": 12, "line": 139 }
437+
},
438+
"uri": "file:///AppliedFunctor.res"
439+
}
440+
]
441+
442+
References src/AppliedFunctor.res 144:18
443+
[
444+
{
445+
"range": {
446+
"end": { "character": 21, "line": 90 },
447+
"start": { "character": 8, "line": 90 }
448+
},
449+
"uri": "file:///AppliedFunctor.res"
450+
},
451+
{
452+
"range": {
453+
"end": { "character": 36, "line": 112 },
454+
"start": { "character": 32, "line": 112 }
455+
},
456+
"uri": "file:///AppliedFunctor.res"
457+
},
458+
{
459+
"range": {
460+
"end": { "character": 37, "line": 113 },
461+
"start": { "character": 33, "line": 113 }
462+
},
463+
"uri": "file:///AppliedFunctor.res"
464+
},
465+
{
466+
"range": {
467+
"end": { "character": 22, "line": 144 },
468+
"start": { "character": 18, "line": 144 }
469+
},
470+
"uri": "file:///AppliedFunctor.res"
471+
}
472+
]
473+

0 commit comments

Comments
 (0)