Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method completion doesn't work #71

Open
db4 opened this issue Oct 31, 2016 · 20 comments
Open

Method completion doesn't work #71

db4 opened this issue Oct 31, 2016 · 20 comments

Comments

@db4
Copy link
Contributor

db4 commented Oct 31, 2016

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.

@hackwaly hackwaly added the bug label Oct 31, 2016
@hackwaly hackwaly added this to the 0.6.x milestone Oct 31, 2016
@db4
Copy link
Contributor Author

db4 commented Oct 31, 2016

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
Copy link
Contributor Author

db4 commented Oct 31, 2016

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
Copy link
Contributor Author

db4 commented Nov 4, 2016

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?

@hackwaly hackwaly reopened this Nov 4, 2016
@hackwaly
Copy link
Owner

hackwaly commented Nov 4, 2016

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

@hcarty
Copy link

hcarty commented Nov 4, 2016

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.

@hackwaly
Copy link
Owner

hackwaly commented Nov 4, 2016

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 hackwaly added tough and removed upstream labels Nov 4, 2016
@db4
Copy link
Contributor Author

db4 commented Nov 5, 2016

@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
Copy link
Contributor Author

db4 commented Nov 5, 2016

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.

@hackwaly
Copy link
Owner

hackwaly commented Nov 5, 2016

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

@db4
Copy link
Contributor Author

db4 commented Nov 5, 2016

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

@db4
Copy link
Contributor Author

db4 commented Nov 5, 2016

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

@hackwaly
Copy link
Owner

hackwaly commented Nov 5, 2016

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
Copy link
Owner

hackwaly commented Nov 5, 2016

Seems my merlin env is not configured correct.

The Merlin toolkit version 2.5.1, for Ocaml 4.03.0

image

@db4
Copy link
Contributor Author

db4 commented Nov 5, 2016

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
Copy link
Contributor Author

db4 commented Nov 5, 2016

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

hackwaly added a commit that referenced this issue Nov 5, 2016
@hackwaly
Copy link
Owner

hackwaly commented Nov 5, 2016

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
Copy link
Owner

hackwaly commented Nov 6, 2016

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

@db4
Copy link
Contributor Author

db4 commented Nov 6, 2016

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.

@hackwaly
Copy link
Owner

hackwaly commented Nov 7, 2016

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.

@db4
Copy link
Contributor Author

db4 commented Nov 7, 2016

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

@hackwaly hackwaly modified the milestones: Long term, 0.6.x Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants