From a724d836f655c1a36eb74241df18223aa13566d7 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Nov 2022 15:59:50 -0300 Subject: [PATCH 1/6] update tests --- analysis/tests/src/expected/Hover.res.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index b46f0dfdb..8f21c71de 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -39,10 +39,10 @@ Hover src/Hover.res 46:10 {"contents": "```rescript\nint\n```"} Hover src/Hover.res 49:13 -{"contents": "```rescript\nmodule Logger = {\n let log: string => unit\n}\n```"} +{"contents": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```"} Hover src/Hover.res 54:7 -{"contents": "```rescript\nmodule Logger = {\n let log: string => unit\n}\n```"} +{"contents": "```rescript\nmodule type Logger = {\n let log: string => unit\n}\n```"} Definition src/Hover.res 60:14 {"uri": "Hover.res", "range": {"start": {"line": 49, "character": 12}, "end": {"line": 49, "character": 18}}} From 698eba844f29286684883bd5465872d87758ca59 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Nov 2022 16:00:54 -0300 Subject: [PATCH 2/6] fix: Incorrect type hint for module type Close #571 --- analysis/src/Hover.ml | 8 +++++++- analysis/src/ProcessCmt.ml | 8 ++++---- analysis/src/References.ml | 4 ++-- analysis/src/ResolvePath.ml | 2 +- analysis/src/SharedTypes.ml | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index 371418b8a..9229ef440 100644 --- a/analysis/src/Hover.ml +++ b/analysis/src/Hover.ml @@ -28,7 +28,13 @@ let rec showModule ~docstring ~(file : File.t) ~name (declared : Module.t Declared.t option) = match declared with | None -> showModuleTopLevel ~docstring ~name file.structure.items - | Some {item = Structure {items}} -> showModuleTopLevel ~docstring ~name items + | Some {item = Structure {items}; modulePath} -> + let newName = + match modulePath with + | ExportedModule (_, _, isModType) when isModType = true -> "type " ^ name + | _ -> name + in + showModuleTopLevel ~docstring ~name:newName items | Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) -> (* show the interface *) showModule ~docstring ~file ~name diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index b5f9e8fe2..5f282b292 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -375,7 +375,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item = mtd_loc; } -> let env = - {env with modulePath = ExportedModule (name.txt, env.modulePath)} + {env with modulePath = ExportedModule (name.txt, env.modulePath, true)} in let modTypeItem = forTypeModule env modType in let declared = @@ -425,7 +425,7 @@ and forModule env mod_desc moduleName = | Tmod_ident (path, _lident) -> Ident path | Tmod_structure structure -> let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath)} + {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} in let contents = forStructure ~env structure.str_items in Structure contents @@ -447,14 +447,14 @@ and forModule env mod_desc moduleName = forModule env functor_.mod_desc moduleName | Tmod_unpack (_expr, moduleType) -> let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath)} + {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} in forTypeModule env moduleType | Tmod_constraint (expr, typ, _constraint, _coercion) -> (* TODO do this better I think *) let modKind = forModule env expr.mod_desc moduleName in let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath)} + {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} in let modTypeKind = forTypeModule env typ in Constraint (modKind, modTypeKind) diff --git a/analysis/src/References.ml b/analysis/src/References.ml index 72430d594..4f3194919 100644 --- a/analysis/src/References.ml +++ b/analysis/src/References.ml @@ -430,7 +430,7 @@ let isVisible (declared : _ Declared.t) = | File _ -> true | NotVisible -> false | IncludedModule (_, inner) -> loop inner - | ExportedModule (_, inner) -> loop inner + | ExportedModule (_, inner, _) -> loop inner in loop declared.modulePath @@ -438,7 +438,7 @@ let rec pathFromVisibility visibilityPath current = match visibilityPath with | File _ -> Some current | IncludedModule (_, inner) -> pathFromVisibility inner current - | ExportedModule (name, inner) -> pathFromVisibility inner (name :: current) + | ExportedModule (name, inner, _) -> pathFromVisibility inner (name :: current) | NotVisible -> None let pathFromVisibility visibilityPath tipName = diff --git a/analysis/src/ResolvePath.ml b/analysis/src/ResolvePath.ml index d75748edf..c478bedc5 100644 --- a/analysis/src/ResolvePath.ml +++ b/analysis/src/ResolvePath.ml @@ -144,4 +144,4 @@ let rec getSourceUri ~(env : QueryEnv.t) ~package path = Log.log "NOT FOUND"; getSourceUri ~env ~package inner | Some (env, _declared) -> env.file.uri) - | ExportedModule (_, inner) -> getSourceUri ~env ~package inner + | ExportedModule (_, inner, _) -> getSourceUri ~env ~package inner diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 906669e78..f90964431 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -6,7 +6,7 @@ type modulePath = | File of Uri.t * string | NotVisible | IncludedModule of Path.t * modulePath - | ExportedModule of string * modulePath + | ExportedModule of string * modulePath * bool type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr} From 0cccc3f32252e2f0505807446f729bb67a1d130f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Nov 2022 16:02:37 -0300 Subject: [PATCH 3/6] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ae071a0..b3821f519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ - 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 +- Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/620 + ## v1.8.2 #### :rocket: New Feature From 830b07dc94f51607b936b68141f2f851417ec3f2 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Nov 2022 16:04:04 -0300 Subject: [PATCH 4/6] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3821f519..329d2900c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - 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 -- 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 +- 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 - Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/620 From 87efb2742ac72e3ec61082e9346eeb69b7c62f88 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Nov 2022 16:09:08 -0300 Subject: [PATCH 5/6] update changelog: fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329d2900c..672068d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - 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 -- Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/620 +- Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/626 ## v1.8.2 From 4f50641cf7e67e419b0b17d2a849537419dcc356 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 13 Nov 2022 18:20:58 -0300 Subject: [PATCH 6/6] refactor: create inline record --- analysis/src/Hover.ml | 6 +++--- analysis/src/ProcessCmt.ml | 28 ++++++++++++++++++++++++---- analysis/src/References.ml | 5 +++-- analysis/src/ResolvePath.ml | 2 +- analysis/src/SharedTypes.ml | 2 +- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index 9229ef440..b4dc183a7 100644 --- a/analysis/src/Hover.ml +++ b/analysis/src/Hover.ml @@ -29,12 +29,12 @@ let rec showModule ~docstring ~(file : File.t) ~name match declared with | None -> showModuleTopLevel ~docstring ~name file.structure.items | Some {item = Structure {items}; modulePath} -> - let newName = + let name = match modulePath with - | ExportedModule (_, _, isModType) when isModType = true -> "type " ^ name + | ExportedModule {isType} when isType = true -> "type " ^ name | _ -> name in - showModuleTopLevel ~docstring ~name:newName items + showModuleTopLevel ~docstring ~name items | Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) -> (* show the interface *) showModule ~docstring ~file ~name diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index 5f282b292..9cee20165 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -375,7 +375,12 @@ let rec forStructureItem ~env ~(exported : Exported.t) item = mtd_loc; } -> let env = - {env with modulePath = ExportedModule (name.txt, env.modulePath, true)} + { + env with + modulePath = + ExportedModule + {name = name.txt; modulePath = env.modulePath; isType = true}; + } in let modTypeItem = forTypeModule env modType in let declared = @@ -425,7 +430,12 @@ and forModule env mod_desc moduleName = | Tmod_ident (path, _lident) -> Ident path | Tmod_structure structure -> let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} + { + env with + modulePath = + ExportedModule + {name = moduleName; modulePath = env.modulePath; isType = false}; + } in let contents = forStructure ~env structure.str_items in Structure contents @@ -447,14 +457,24 @@ and forModule env mod_desc moduleName = forModule env functor_.mod_desc moduleName | Tmod_unpack (_expr, moduleType) -> let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} + { + env with + modulePath = + ExportedModule + {name = moduleName; modulePath = env.modulePath; isType = false}; + } in forTypeModule env moduleType | Tmod_constraint (expr, typ, _constraint, _coercion) -> (* TODO do this better I think *) let modKind = forModule env expr.mod_desc moduleName in let env = - {env with modulePath = ExportedModule (moduleName, env.modulePath, false)} + { + env with + modulePath = + ExportedModule + {name = moduleName; modulePath = env.modulePath; isType = false}; + } in let modTypeKind = forTypeModule env typ in Constraint (modKind, modTypeKind) diff --git a/analysis/src/References.ml b/analysis/src/References.ml index 4f3194919..649572499 100644 --- a/analysis/src/References.ml +++ b/analysis/src/References.ml @@ -430,7 +430,7 @@ let isVisible (declared : _ Declared.t) = | File _ -> true | NotVisible -> false | IncludedModule (_, inner) -> loop inner - | ExportedModule (_, inner, _) -> loop inner + | ExportedModule {modulePath = inner} -> loop inner in loop declared.modulePath @@ -438,7 +438,8 @@ let rec pathFromVisibility visibilityPath current = match visibilityPath with | File _ -> Some current | IncludedModule (_, inner) -> pathFromVisibility inner current - | ExportedModule (name, inner, _) -> pathFromVisibility inner (name :: current) + | ExportedModule {name; modulePath = inner} -> + pathFromVisibility inner (name :: current) | NotVisible -> None let pathFromVisibility visibilityPath tipName = diff --git a/analysis/src/ResolvePath.ml b/analysis/src/ResolvePath.ml index c478bedc5..36b6c333a 100644 --- a/analysis/src/ResolvePath.ml +++ b/analysis/src/ResolvePath.ml @@ -144,4 +144,4 @@ let rec getSourceUri ~(env : QueryEnv.t) ~package path = Log.log "NOT FOUND"; getSourceUri ~env ~package inner | Some (env, _declared) -> env.file.uri) - | ExportedModule (_, inner, _) -> getSourceUri ~env ~package inner + | ExportedModule {modulePath = inner} -> getSourceUri ~env ~package inner diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index f90964431..60362179b 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -6,7 +6,7 @@ type modulePath = | File of Uri.t * string | NotVisible | IncludedModule of Path.t * modulePath - | ExportedModule of string * modulePath * bool + | ExportedModule of {name: string; modulePath: modulePath; isType: bool} type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr}