diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ae071a0..672068d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,9 @@ - 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/626 ## v1.8.2 diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index 371418b8a..b4dc183a7 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 name = + match modulePath with + | ExportedModule {isType} when isType = true -> "type " ^ name + | _ -> name + in + 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 b5f9e8fe2..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)} + { + 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)} + { + 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)} + { + 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)} + { + 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 72430d594..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 d75748edf..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 906669e78..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 + | ExportedModule of {name: string; modulePath: modulePath; isType: bool} type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr} 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}}}