vscode-ocaml
vscode-ocaml copied to clipboard
Method completion doesn't work
In the following code snippet
class test =
object
method m = ()
end
let _ =
let obj = new test in
obj#
I expected that typing #
would trigger completion list with available test
class methods. I doesn't work. Typing #
doesn't trigger completion at all and explicit Ctrl-tab just shows all available OCaml keywords.
Thank a lot for the fast responce but it still does not work. For the example above it gives incorrect result
if I run it under VSCode debugger with a breakpoint set. If I run it normally, no completion list is ever shown after typeing
#
. From the merlin conversation
command to merlin: ["tell","source-eof","class test =\r\nobject\r\n method m = ()\r\nend\r\n\r\nlet _ =\r\n let obj = new test in\r\n obj#"]
response from merlin: ["return",{"cursor":{"line":8,"col":8},"marker":false}]
command to merlin: ["errors"]
response from merlin: ["return",[{"type":"type","start":{"line":8,"col":4},"end":{"line":8,"col":7},"valid":true,"message":"Error: This expression has type test\n It has no method "},{"type":"parser","start":{"line":9,"col":0},"end":{"line":9,"col":0},"valid":true,"message":"Syntax error inside `let', expecting label"}]]
it looks like obj#
triggers tell
,errors
commands to merlin before complete
one and the former's error block further completion.
BTW, I also see
command to merlin: ["protocol","version",2]
response from merlin: ["failure","invalid arguments"]
Not a big deal but it's better to fix it as well.
As for protocol
command: looks like my merlin is old enough and just don't know it. Looks like you do it right, sorry for the false alarm.
Maybe I was not clear enough in my last comment: method completion still does not work as expected (with merlin 2.3.1). Can you reproduce the problem in your environment?
Looks like it's a missing or incomplete feature of merlin. I can't get it works in merlin.
FWIW method completion does work under vim using merlin

so it seems to be generally possible. This is using OCaml 4.02.3 and merlin 2.5.1.
I still have no idea about how to issue commands to merlin to get correct results of method completion. I am not familiar with debugging on vim or emacs script.
@hcarty, can you provide some additional details on how merlin completion works in vim. When do you see the completion list for the first time: right after typing o#
or some initial method name chars are needed before?
OK, I'have installed VIM myself and tried to use merlin auto-completion there. Indeed, it works as expected for methods. The differences from vscode-ocaml I see:
- Then completing
obj#
, merlin/vim does not use '#' asprefix
argument tocomplete
command. It uses emptyprefix
instead. Then completingobj#m
prefix
is set tom
. - vscode-ocaml sends the whole file to merlin after each character typed while merlin/vim only sends deltas, maintaining sync with merlin. Hopefully this only affect performance for big files, not completion capabilities.
@db4 , if I use empty prefix at cursor, merlin result us all the global namespace entities. Maybe there are some commands I missed that to select which document to complete. I'll also try to change the sync mode to deltas.
Hmm, I tried empty prefix and it worked. The cursor position was right after obj#
BTW, you can easily see the whole vim/merlin conversation using env variable MERLIN_LOG (set it to the log file name)
This is the merlin conversation I've got in vscode-ocaml. Wasn't the cursor right after o#
?
command to merlin: ["tell","start","end","let o = object\n method print_a = print_endline \"a\";\n method print_b = print_endline \"b\";\nend\n\nlet () =\n o#\n"]
response from merlin: ["return",true]
command to merlin: ["complete","prefix","","at",{"line":7,"col":4},"with","doc"]
response from merlin: ["return",{"entries":[{"name":"()","kind":"Constructor","desc":"unit","info":""},{"name":"at_exit","kind":"Value","desc":"(unit -> unit) -> unit","info":" Register the given function to be called at program\n termination time. The functions registered with [at_exit]\n will be called when the program executes {!Pervasives.exit},\n or terminates, either normally or because of an uncaught exception.\n The functions are called in 'last in, first out' order:\n the function most recently added with [at_exit] is called first. "}, ...]}]
Seems my merlin env is not configured correct.
The Merlin toolkit version 2.5.1, for Ocaml 4.03.0
Here is a fresh merlin conversation (merlin is started directly the from command line):
["tell","source-eof","let o = object\n method print_a = print_endline \"a\";\n method print_b = print_endline \"b\";\nend\n\nlet () =\n o#\n"]
["return",{"cursor":{"line":8,"col":0},"marker":false}]
["complete","prefix","","at",{"line":7,"col":4},"with","doc"]
["return",{"entries":[{"name":"print_a","kind":"#","desc":"unit","info":""},{"name":"print_b","kind":"#","desc":"unit","info":""}],"context":null}]
@hackwaly, why o#()
? type o#
and then press Ctrl-X Ctrl-O
Yes, the ()
is auto inserted by vim after I type o#
and then press Ctrl-X Ctrl-O.
Please try v0.6.8, It use empty prefix instead of including #
. I'll check why my merlin doesn't work later.
It's better now. Auto-completion on typing #
works as expected:
But if you hit backspace twice and then type
o#
several times, eventually you'll see the following:
Log shows that in that case you send
complete
command before #
input is processed by merlin (you issue merlin commands asynchronously, right?) Maybe some synchronization is needed?
Another problem: move cursor back and forward, place it after o#
and then hit Ctrl-space. You'll see the following:
Strange enough that the correct
complete
command is send to merlin here and it responses with the correct method list.
My dev env seems broken after updated to macOS Sierra previously. I'm going to reinstall macOS and then solve this issue.
Merlin still doesn't work on my fresh installed macOS. I'll report it to merlin project.
@db4 , the async problem looks like a bug of VS Code self.
Currently, I'm mainly work on the ocaml-language-server. I plan to make this extension use it at next major version.
the async problem looks like a bug of VS Code self.
Could you file a bug report to vscode team?
Currently, I'm mainly work on the ocaml-language-server. I plan to make this extension use it at next major version.
This is great news! I definitely know OCaml better than TypeScript, so I will submit PRs more frequently :) And a standalone language server can be used in other IDEs, such as Eclipse