Completion for Object Methods in Merlin/OCaml LSP Server

This feels like a notable omission, or perhaps I’m missing something:

Let us say the OCaml class of an object is known e.g. abc : <some_class; ...>.

When I type abc# in the editor (with merlin or ocaml-lsp-server enabled) , I should be able to get an autocomplete on all the methods in some_class but I don’t.

But it gets worse, supposing I have foo: < bar: int -> int; baz: int -> string > where the methods are explictly listed, even here when I do foo# I should be given an autocomplete which allows me to choose between bar and baz methods, but I dont…

I am using merlin 4.8-500. I’ve tried with ocaml-lsp-server and am aware that it uses merlin in the backend.

How can merlin help me select methods on an object?

(P.S. Also posted as Completion for object methods · Issue #1575 · ocaml/merlin · GitHub )


@rgrinberg @vds Sorry for the ping, but its highly likely that either of you know the answer to this question and I’m very curious about the answer :slight_smile: ! Thanks !

Hi @sid, I have seen your issue on Github and agree that the ‘O’ in OCaml probably need some love from Merlin in general. However I didn’t had the time to investigate you’re specific case and still don’t have it right now. Merlin’s tracker was the correct place to post and cross-posting won’t make things go faster. (One good way to help however would be to open a PR with a reproduction test :slightly_smiling_face:)

1 Like

Thanks for your response!

To reproduce manually add the following snippet in any merlin enabled editor:

let foo = object
  method bar i = i + 5
  method baz _k = "hello"

(* EXPECTATION: Upon typing `#` we should get a menu drop down for bar and baz *)
(* However this does not happen :-(                                                                            *)
(* Interestingly utop gives me bar and baz as expected!                                             *)
let something = foo#

If you point me to any simple merlin test involving autocomplete that can serve as a template for the above situation, I’ll create a proper OCaml version and post a PR.

I did find merlin/tests/test-dirs/completion/infix.t at master · ocaml/merlin · GitHub which seems like a good candidate but I don’t know how I can generate an expected result of the json ie. run.t as merlin simply does not work here.

Merlin’s tracker was the correct place to post and cross-posting won’t make things go faster.

Sorry about the cross post. There was no ack on the github issue so I thought maybe this might be a more informal place to elicit a response. Issue trackers tend to be more formal and people don’t post an answer unless they are sure about it. A discussion forum such as this one might get a faster though more approximate answer. Thanks for taking the time!