Skip to content

Last-seen type alias replaces original type name on ALL code lenses and hover lookups. #1883

@dsimunic

Description

@dsimunic

When a type is aliased somewhere in an opened module (or even in the same file), all code lenses will pick up the alias name instead of the aliased type.

For example, Unix module internally aliases int to file_perm:

type file_perm = int

This leads to all sources opening the Unix module to change all occurrences of int annotations to file_perm:

Image

ocaml -i obviously reports the correct type as the program compiles.

val fd_of_int : int -> Unix.file_descr

ocamlmerlin also reports the correct type:

`"type": "int -> Unix.file_descr",`

Commenting out open Unix makes the code lens switch back to int moments after applying the comment.

Hovering also shows the wrong type: in this case, even hovering over a literal 1000 in let _ = 1000 will show a tooltip with file_perm.

It appears that the LSP server gets type info for code lens from merlin, but then does something else that leads to this annoyance. Presumably the problem is in symbol_info_of_outline_item that recursively collects the types from a Merlin response (though I don't understand what Merlin really returns) in the wrong order, and then somehow the type alias gets chosen as the type of the queried symbol.

This is on OCaml Platform for VSCode (ocaml-lsp-server 1.23.0) and OCaml 5.3 on macOS . Though I remember this problem existed months ago when I last tried OCaml in VSCode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions