ocaml / ocaml-lsp

OCaml Language Server Protocol implementation
Other
772 stars 121 forks source link

Cannot disable short-paths #1395

Open Sakarah opened 1 week ago

Sakarah commented 1 week ago

As stated in issue #1227, short-paths usually gives weird behaviors for code using type aliases.

In the OCaml compiler, this issue can sometimes be mitigated by not using the -short-paths option to force displaying full paths in error messages. Such types are usually longer but at least they are similar to the declared function signature.

With OCaml LSP, such a mitigation seems inaccessible with the current implementation. The -short-path option is always enabled by default. If I understand correctly, passing the real_path option to the underlying Merlin should disable this path shortening and give a behavior that is similar to the compiler without the -short-paths option.

Ideally, I would like to be able to use OCaml LSP with Merlin in real_paths mode for some projects, and in the current short_paths mode for others.

voodoos commented 1 week ago

If you use Dune then it passes the build flags to Merlin / LSP. This means that removing short paths from the standard ocaml flags set might allow you to disable the feature. It can be done in dune and dune-workspace files:

(env
 (_
  (flags ((:standard \ -short-paths)))))

It remains to be checked that short-paths is the issue here.

Sakarah commented 1 week ago

For the specific flag -short-paths it seems that its absence is completely ignored by OCaml LSP.

With the dune file:

(library
  (name test)
  (modes byte native))

(env
 (_
  (flags ((:standard \ -short-paths)))))

and ML file:

type nat = int

let incr : int -> int = (+) 1

let () =
  ignore (incr true)

dune build gives the intended Error: This expression has type bool but an expression was expected of type int. However, OCaml LSP writes This expression has type bool but an expression was expected of type nat in the error list.

voodoos commented 1 week ago

Right, it looks like short-path is forced to be true in a few places indeed.