Open anzhi0708 opened 1 year ago
The error message from neovim is expected - it just means you don't have dune running in watch mode. ocamllsp should work as expected.
The error message from neovim is expected - it just means you don't have dune running in watch mode. ocamllsp should work as expected.
Thanks a lot for replying!
I'm a beginner in OCaml, and that's why I really need LSP related tools to help me learn OCaml.
Could you kindly show me how to set dune
in watch mode, so that I can use ocamllsp
within nvim
? Appreciate it!
you can add --watch
to basically any dune build
command. But as mentioned earlier this is not necessary for ocamllsp to work. Having dune running in watch mode will add some features like reporting of errors happening outside of the file you are currently editing.
@anzhi0708 I just ran into the same issue, the LSP wasn't working in a directory with a plain ocaml source file. I was able to resolve it by running git init
on the directory, which forced the root directory to be populated and the LSP to actually attach. I think any file listed under root_dir
here would suffice to have root directory be found and the L:SP should work after that.
Thanks @rsulli55 the workaround works.
However, is there a way to disable this root_dir
requirement?
The same folder without .git, .opam files, etc. works fine on VSCode, however it does not on NeoVim.
Workaround #2:
lspconfig.ocamllsp.setup {
filetypes = { "ocaml", "ocaml.menhir", "ocaml.interface", "ocaml.ocamllex", "reason", "dune" },
root_dir = lspconfig.util.root_pattern("*.opam", "esy.json", "package.json", ".git", "dune-project", "dune-workspace", "*.ml"),
on_attach = on_attach,
capabilities = capabilities
}
The error message from
~/.local/state/nvim/lsp.log
:OCaml version:
OPAM version:
Packages installed:
NeoVim OCaml LSP configuration (init.lua):
(At first I simply tried
lspconfig.ocamllsp.setup {}
but no success, same error message as above config. I also tried to add 'ml' toroot_dir
but still no luck. Instead oflspconfig.util.root_pattern
, I also tried another form ofroot_dir
configuration, basically a lua table if I remembered correctly, but still got the same error when started to edit a.ml
buffer)Note
ocamllsp
confirmed working, because helix(editor) uses the exact same binary ($ which ocamllsp
) and everything works fine onhelix
So I'm somewhat confused, both
helix
andneovim
uses default configuration butneovim
lsp is not working