-
Notifications
You must be signed in to change notification settings - Fork 141
Description
https://discuss.ocaml.org/t/ann-ocaml-lsp-server-1-11-0/9677 says that a new feature is integration with dune in watch mode.
However I keep getting this error:
ocamllsp: -32600: No dune instance found. Please run dune in watch mode for /home/edwin/o/foo/lib/dune
I was running dune in watch mode, but I've seen no attempts from ocamllsp
to connect to it:
(export DUNE_RPC_DEBUG=1; dune build --watch --no-buffer --verbose)
However the RPC server seemed to be working fine (dune rpc ping
and dune rpc status
both worked and showed up in the console of dune watch.
Tried stracing ocamllsp
on startup, and it made no attempt to search for, or connect to the dune .rpc
.
Looking through the source code I found this:
5d60767
https://github.com/ocaml/ocaml-lsp/blob/1.11.2/ocaml-lsp-server/src/dune.ml#L714-L719
ocaml-lsp/ocaml-lsp-server/src/import.ml
Lines 226 to 235 in 6a38d66
let inside_test = | |
match Sys.getenv_opt "OCAMLLSP_TEST" with | |
| Some "true" -> true | |
| None | Some "false" -> false | |
| Some b -> | |
Format.eprintf | |
"invalid value %S for OCAMLLSP_TEST ignored. Only true or false are \ | |
allowed@." | |
b; | |
false |
Which only enables Dune when inside test (so the 'reenable dune' commit actually does the opposite: it disables dune support because the default for inside_test
is false
).
I can test ocamllsp
like this though (after patching nvim-lsp-config
to recognize dune
as a language):
(export OCAMLLSP_TEST=true; vi lib/dune)
I think perhaps the reenable dune
commit meant to also delete the inside_test
conditional, so something like this?
diff --git a/ocaml-lsp-server/src/dune.ml b/ocaml-lsp-server/src/dune.ml
index f4f9ded23..dbfa86aa3 100644
--- a/ocaml-lsp-server/src/dune.ml
+++ b/ocaml-lsp-server/src/dune.ml
@@ -713,10 +713,8 @@ let create workspaces (client_capabilities : ClientCapabilities.t) diagnostics
let create workspaces (client_capabilities : ClientCapabilities.t) diagnostics
progress document_store ~log =
- if inside_test then
create workspaces client_capabilities diagnostics progress document_store
~log
- else ref Closed
let run_loop t =
Fiber.repeat_while ~init:() ~f:(fun () ->
And then formatting works, and if I save a dune with incorrect syntax I also see the errors. Also creating a new file and saving it will then make the "No config found for file "new.ml" in "lib". Try calling 'dune build'" error go away, which is nice.
Not everything works though, trying to ask for hover info I get this error (although the LSP server does seem to advertise the capability):
[TRACE][2022-04-22 11:11:59] ...lsp/handlers.lua:437 "default_handler" "textDocument/hover" { config = { border = "rounded" }, ctx = '{\n bufnr = 1,\n client_id = 1,\n method = "textDocument/hover",\n params = {\n position = {\n character = 2,\n line = 0\n },\n textDocument = {\n uri = "file:///home/edwin/o/foo/lib/dune"\n }\n }\n}', err = { code = -32603, data = { backtrace = 'Raised at Stdune__Code_error.raise in file "otherlibs/stdune/code_error.ml", line 11, characters 30-62\nCalled from Ocaml_lsp_server__Document.with_pipeline_exn in file "ocaml-lsp-server/src/document.ml", line 151, characters 13-32\nCalled from Ocaml_lsp_server__Hover_req.handle.(fun) in file "ocaml-lsp-server/src/hover_req.ml", line 38, characters 28-59\nCalled from Fiber__Scheduler.exec in file "src/fiber/scheduler.ml", line 69, characters 8-11\n', exn = '("Document.dune", {})' }, message = "uncaught exception", <metatable> = { __tostring = <function 1> } }}
cc @rgrinberg