Skip to content

Commit f21af99

Browse files
authored
fix: Incorrect type hint for module type (#626)
* update tests * fix: Incorrect type hint for module type Close #571 * update changelog * update changelog * update changelog: fix typo * refactor: create inline record
1 parent 3e2076e commit f21af99

File tree

7 files changed

+41
-12
lines changed

7 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
- Adapt command to create interface files to latest JSX V4 (no key prop, possibly empty record) https://github.com/rescript-lang/rescript-vscode/issues/617
2626

27-
- Fix issue where pipes were not taken into account in the signature help, resulting in the highlighted argument in signature help always being off by one for unlabelled arguments in piped expressions https://github.com/rescript-lang/rescript-vscode/issues/618
27+
- Fix issue where pipes were not taken into account in the signature help, resulting in the highlighted argument in signature help always being off by one for unlabelled arguments in piped expressions https://github.com/rescript-lang/rescript-vscode/issues/626
28+
29+
- Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/626
2830

2931
- Fix file location in Document Symbols response. https://github.com/rescript-lang/rescript-vscode/issues/629
3032

analysis/src/Hover.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ let rec showModule ~docstring ~(file : File.t) ~name
2828
(declared : Module.t Declared.t option) =
2929
match declared with
3030
| None -> showModuleTopLevel ~docstring ~name file.structure.items
31-
| Some {item = Structure {items}} -> showModuleTopLevel ~docstring ~name items
31+
| Some {item = Structure {items}; modulePath} ->
32+
let name =
33+
match modulePath with
34+
| ExportedModule {isType} when isType = true -> "type " ^ name
35+
| _ -> name
36+
in
37+
showModuleTopLevel ~docstring ~name items
3238
| Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) ->
3339
(* show the interface *)
3440
showModule ~docstring ~file ~name

analysis/src/ProcessCmt.ml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,12 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
375375
mtd_loc;
376376
} ->
377377
let env =
378-
{env with modulePath = ExportedModule (name.txt, env.modulePath)}
378+
{
379+
env with
380+
modulePath =
381+
ExportedModule
382+
{name = name.txt; modulePath = env.modulePath; isType = true};
383+
}
379384
in
380385
let modTypeItem = forTypeModule env modType in
381386
let declared =
@@ -425,7 +430,12 @@ and forModule env mod_desc moduleName =
425430
| Tmod_ident (path, _lident) -> Ident path
426431
| Tmod_structure structure ->
427432
let env =
428-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
433+
{
434+
env with
435+
modulePath =
436+
ExportedModule
437+
{name = moduleName; modulePath = env.modulePath; isType = false};
438+
}
429439
in
430440
let contents = forStructure ~env structure.str_items in
431441
Structure contents
@@ -447,14 +457,24 @@ and forModule env mod_desc moduleName =
447457
forModule env functor_.mod_desc moduleName
448458
| Tmod_unpack (_expr, moduleType) ->
449459
let env =
450-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
460+
{
461+
env with
462+
modulePath =
463+
ExportedModule
464+
{name = moduleName; modulePath = env.modulePath; isType = false};
465+
}
451466
in
452467
forTypeModule env moduleType
453468
| Tmod_constraint (expr, typ, _constraint, _coercion) ->
454469
(* TODO do this better I think *)
455470
let modKind = forModule env expr.mod_desc moduleName in
456471
let env =
457-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
472+
{
473+
env with
474+
modulePath =
475+
ExportedModule
476+
{name = moduleName; modulePath = env.modulePath; isType = false};
477+
}
458478
in
459479
let modTypeKind = forTypeModule env typ in
460480
Constraint (modKind, modTypeKind)

analysis/src/References.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,16 @@ let isVisible (declared : _ Declared.t) =
430430
| File _ -> true
431431
| NotVisible -> false
432432
| IncludedModule (_, inner) -> loop inner
433-
| ExportedModule (_, inner) -> loop inner
433+
| ExportedModule {modulePath = inner} -> loop inner
434434
in
435435
loop declared.modulePath
436436

437437
let rec pathFromVisibility visibilityPath current =
438438
match visibilityPath with
439439
| File _ -> Some current
440440
| IncludedModule (_, inner) -> pathFromVisibility inner current
441-
| ExportedModule (name, inner) -> pathFromVisibility inner (name :: current)
441+
| ExportedModule {name; modulePath = inner} ->
442+
pathFromVisibility inner (name :: current)
442443
| NotVisible -> None
443444

444445
let pathFromVisibility visibilityPath tipName =

analysis/src/ResolvePath.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ let rec getSourceUri ~(env : QueryEnv.t) ~package path =
144144
Log.log "NOT FOUND";
145145
getSourceUri ~env ~package inner
146146
| Some (env, _declared) -> env.file.uri)
147-
| ExportedModule (_, inner) -> getSourceUri ~env ~package inner
147+
| ExportedModule {modulePath = inner} -> getSourceUri ~env ~package inner

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type modulePath =
66
| File of Uri.t * string
77
| NotVisible
88
| IncludedModule of Path.t * modulePath
9-
| ExportedModule of string * modulePath
9+
| ExportedModule of {name: string; modulePath: modulePath; isType: bool}
1010

1111
type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr}
1212

analysis/tests/src/expected/Hover.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ Hover src/Hover.res 46:10
3939
{"contents": "```rescript\nint\n```"}
4040

4141
Hover src/Hover.res 49:13
42-
{"contents": "```rescript\nmodule Logger = {\n let log: string => unit\n}\n```"}
42+
{"contents": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```"}
4343

4444
Hover src/Hover.res 54:7
45-
{"contents": "```rescript\nmodule Logger = {\n let log: string => unit\n}\n```"}
45+
{"contents": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```"}
4646

4747
Definition src/Hover.res 60:14
4848
{"uri": "Hover.res", "range": {"start": {"line": 49, "character": 12}, "end": {"line": 49, "character": 18}}}

0 commit comments

Comments
 (0)