vscode-ocaml icon indicating copy to clipboard operation
vscode-ocaml copied to clipboard

Method completion doesn't work

Open db4 opened this issue 8 years ago • 20 comments

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.

db4 avatar Oct 31 '16 08:10 db4

Thank a lot for the fast responce but it still does not work. For the example above it gives incorrect result image 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.

db4 avatar Oct 31 '16 10:10 db4

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.

db4 avatar Oct 31 '16 11:10 db4

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?

db4 avatar Nov 04 '16 10:11 db4

Looks like it's a missing or incomplete feature of merlin. I can't get it works in merlin.

hackwaly avatar Nov 04 '16 15:11 hackwaly

FWIW method completion does work under vim using merlin

screen shot 2016-11-04 at 12 13 25 pm

so it seems to be generally possible. This is using OCaml 4.02.3 and merlin 2.5.1.

hcarty avatar Nov 04 '16 16:11 hcarty

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.

hackwaly avatar Nov 04 '16 17:11 hackwaly

@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?

db4 avatar Nov 05 '16 06:11 db4

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:

  1. Then completing obj#, merlin/vim does not use '#' as prefix argument to complete command. It uses empty prefix instead. Then completing obj#m prefix is set to m.
  2. 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 avatar Nov 05 '16 14:11 db4

@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.

hackwaly avatar Nov 05 '16 15:11 hackwaly

Hmm, I tried empty prefix and it worked. The cursor position was right after obj#

db4 avatar Nov 05 '16 15:11 db4

BTW, you can easily see the whole vim/merlin conversation using env variable MERLIN_LOG (set it to the log file name)

db4 avatar Nov 05 '16 15:11 db4

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. "}, ...]}]

hackwaly avatar Nov 05 '16 16:11 hackwaly

Seems my merlin env is not configured correct.

The Merlin toolkit version 2.5.1, for Ocaml 4.03.0

image

hackwaly avatar Nov 05 '16 17:11 hackwaly

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}]

db4 avatar Nov 05 '16 17:11 db4

@hackwaly, why o#()? type o# and then press Ctrl-X Ctrl-O

db4 avatar Nov 05 '16 17:11 db4

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.

hackwaly avatar Nov 05 '16 17:11 hackwaly

It's better now. Auto-completion on typing # works as expected: image But if you hit backspace twice and then type o# several times, eventually you'll see the following: image 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: image Strange enough that the correct complete command is send to merlin here and it responses with the correct method list.

db4 avatar Nov 06 '16 09:11 db4

My dev env seems broken after updated to macOS Sierra previously. I'm going to reinstall macOS and then solve this issue.

hackwaly avatar Nov 06 '16 09:11 hackwaly

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.

hackwaly avatar Nov 07 '16 09:11 hackwaly

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

db4 avatar Nov 07 '16 10:11 db4