Skip to content

fix: Incorrect type hint for module type #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion analysis/src/Hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,16 @@ 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

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 =
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/ResolvePath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
Expand Down