Skip to content
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# unreleased

## Fixes

- Fix hover on method calls not showing the type. (#1553, fixes #1552)

# 1.23.0

## Features
Expand Down
6 changes: 4 additions & 2 deletions ocaml-lsp-server/src/hover_req.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ let hover_at_cursor parsetree (`Logical (cursor_line, cursor_col)) =
then (
match expr.pexp_desc with
| Pexp_constant _ | Pexp_variant _ | Pexp_pack _ -> result := Some `Type_enclosing
| Pexp_ident { loc; _ } | Pexp_construct ({ loc; _ }, _) | Pexp_field (_, { loc; _ })
->
| Pexp_ident { loc; _ }
| Pexp_construct ({ loc; _ }, _)
| Pexp_field (_, { loc; _ })
| Pexp_send (_, { loc; _ }) ->
if is_at_cursor loc
then result := Some `Type_enclosing
else Ast_iterator.default_iterator.expr self expr
Expand Down
1 change: 1 addition & 0 deletions ocaml-lsp-server/test/e2e-new/dune
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
document_flow
exit_notification
for_ppx
hover
hover_extended
inlay_hints
jump_to_typed_hole
Expand Down
43 changes: 43 additions & 0 deletions ocaml-lsp-server/test/e2e-new/hover.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
open Test.Import

let print_hover hover =
match hover with
| None -> print_endline "no hover response"
| Some hover ->
hover |> Hover.yojson_of_t |> Yojson.Safe.pretty_to_string ~std:false |> print_endline
;;

let hover client position =
Client.request
client
(TextDocumentHover
{ HoverParams.position
; textDocument = TextDocumentIdentifier.create ~uri:Helpers.uri
; workDoneToken = None
})
;;

let%expect_test "object method call" =
let source =
{ocaml|
let f (o : < g : int -> unit >) = o#g 4
|ocaml}
in
let position = Position.create ~line:1 ~character:38 in
let req client =
let* resp = hover client position in
let () = print_hover resp in
Fiber.return ()
in
Helpers.test source req;
[%expect
{|
{
"contents": { "kind": "plaintext", "value": "int -> unit" },
"range": {
"end": { "character": 38, "line": 1 },
"start": { "character": 35, "line": 1 }
}
}
|}]
;;
Loading