hackwaly / vscode-ocaml

An extension for VS Code which provides support for the OCaml language.
MIT License
170 stars 26 forks source link

Trouble with Autocomplete #109

Closed akcorp2003 closed 7 years ago

akcorp2003 commented 7 years ago

Using:

I'm having trouble with autocomplete. This is what I get:

screen shot 2017-08-07 at 4 54 02 pm

I'm sure I have merlin installed as I get:

The Merlin toolkit version 2.5.0, for Ocaml 4.04.0

I also included the file associations in my user settings to match *.ml with ocaml. I've also tried reinstalling the plugin but it didn't resolve the issue.

hackwaly commented 7 years ago

Did you setup opam env correctly? What will happen if you execute merlin in the vscode's integrated terminal?

akcorp2003 commented 7 years ago

How do I check my opam env? I'm pretty sure it's set up correctly as I can run the opam, ocaml and even utop in my bash terminal. I didn't, however, use brew to install it.

I can run ocamlmerlin -version in the integrated terminal and I get the correct version output as noted in my first comment.

hackwaly commented 7 years ago

Are you sure only autocomplete not works? Does hover tips (show types when hover on variable) and other merlin related features works well?

akcorp2003 commented 7 years ago

All the other features don't work either.

I just tried opam remove merlin and opam install merlin but it didn't fix anything.

hackwaly commented 7 years ago

Do you know typescript? You'd better debug ocaml extension to figure out what's happan.

akcorp2003 commented 7 years ago

Unfortunately, I don't know Typescript. But how would I get started with debugging an extension? I've never tried to before.

hackwaly commented 7 years ago

See this issue: https://github.com/hackwaly/vscode-ocaml/issues/1#issuecomment-224950931 And this https://code.visualstudio.com/docs/extensions/debugging-extensions

akcorp2003 commented 7 years ago

I opened the debug window and got this:

screen shot 2017-08-08 at 6 16 37 pm

And then I opened the debugger but got no output from the console even if I started typing inside.

'/Applications/Visual Studio Code.app/Contents/MacOS/Electron' --debugBrkPluginHost=46109 --extensionDevelopmentPath=/Users/akuang/OCamlPlugin/vscode-ocaml 
hackwaly commented 7 years ago

The new debug window appears after you press F5 is a new vscode instance with the extension under debugging. You then open your test project folder under that window to check things. The warning is unimportant you can simply ignored.

akcorp2003 commented 7 years ago

Where are some suggested breakpoints? I tried hovering over some variables but I get no output in the debug console in the main window (not the new instance). Also, the branch mentioned in the referenced issue doesn't exist.

hackwaly commented 7 years ago

You can define a env variable DEBUG_VSCODE_OCAML=1 to make it log things. Or set breakpoint at src/log.ts:2.

akcorp2003 commented 7 years ago

Sorry, I don't know much about TypeScript. How do I define this env variable? Even if I set the breakpoint at src/log.ts:2, it will never enter it if I don't have that variable defined.

akcorp2003 commented 7 years ago

Never mind. I got it to output some variables. Will update shortly.

akcorp2003 commented 7 years ago

Here is the output after I entered a new line.

command to merlin: ["protocol","version",2]
response from merlin: ["return",{"selected":2,"latest":3,"merlin":"The Merlin toolkit version 2.5.0, for Ocaml 4.04.0"}]
command to merlin: ["checkout","auto","/Users/akuang/OCamlDev/src/filereader.ml"]
response from merlin: ["return",true]
command to merlin: ["tell","start","end","open Printf\n\nlet file = \"/Users/akuang/mf/src/\";;\n\nlet readFirstLine file_name =\n    \n    let line = open_in (file ^ file_name) in\n    try\n        let line_in_file = input_line line in\n            print_endline line_in_file;\n            flush stdout;\n            close_in line\n    with e ->\n        close_in_noerr line;\n        raise e\n\n;;\n\n\n\n\nlet () =\n    readFirstLine \"classes/AccountHierarchyHelper.cls\";;"]

Here is the output after I typed in let.

command to merlin: ["protocol","version",2]
response from merlin: ["return",{"selected":2,"latest":3,"merlin":"The Merlin toolkit version 2.5.0, for Ocaml 4.04.0"}]
command to merlin: ["checkout","auto","/Users/akuang/OCamlDev/src/filereader.ml"]
response from merlin: ["return",true]
command to merlin: ["tell","start","end","open Printf\n\nlet file = \"/Users/akuang/mf/src/\";;\n\nlet readFirstLine file_name =\n    \n    let line = open_in (file ^ file_name) in\n    try\n        let line_in_file = input_line line in\n            print_endline line_in_file;\n            flush stdout;\n            close_in line\n    with e ->\n        close_in_noerr line;\n        raise e\n\n;;\n\nl\n\nlet () =\n    readFirstLine \"classes/AccountHierarchyHelper.cls\";;"]
response from merlin: ["return",true]
command to merlin: ["complete","prefix","l","at",{"line":19,"col":1},"with","doc"]
response from merlin: ["error",{"type":"type","sub":[],"valid":true,"message":"Error: /usr/local/lib/ocaml/pervasives.cmi\nis not a compiled interface for this version of OCaml.\nIt seems to be for a newer version of OCaml."}]
command to merlin: ["checkout","auto","/Users/akuang/OCamlDev/src/filereader.ml"]
response from merlin: ["return",true]
command to merlin: ["tell","start","end","open Printf\n\nlet file = \"/Users/akuang/mf/src/\";;\n\nlet readFirstLine file_name =\n    \n    let line = open_in (file ^ file_name) in\n    try\n        let line_in_file = input_line line in\n            print_endline line_in_file;\n            flush stdout;\n            close_in line\n    with e ->\n        close_in_noerr line;\n        raise e\n\n;;\n\nlet\n\nlet () =\n    readFirstLine \"classes/AccountHierarchyHelper.cls\";;"]
response from merlin: ["return",true]
command to merlin: ["errors"]
response from merlin: ["error",{"type":"type","sub":[],"valid":true,"message":"Error: /usr/local/lib/ocaml/pervasives.cmi\nis not a compiled interface for this version of OCaml.\nIt seems to be for a newer version of OCaml."}]
hackwaly commented 7 years ago

It seems your compiler used by project is not identical with your compiler in env. Do you use opam switch? You can add a option ocaml.useOpamToResolve: true to your workspace .settings.json file then try (You must install merlin under that switch).

akcorp2003 commented 7 years ago

I don't think I'm using it as my current version of ocaml is close to the latest:

The OCaml toplevel, version 4.04.0

Even if I set ocaml.useOpamToResolve: true, still no auto-complete.

hackwaly commented 7 years ago

See https://github.com/ocaml/merlin/issues/604. But your problem seems is not that case.

hackwaly commented 7 years ago

I can't help you any more. Open an issue at merlin project if necessary.

akcorp2003 commented 7 years ago

Alright. Thanks for giving some pointers though!