Dune build -w, neovim, lsp, jump to next error

My current setup is:

  • window 1 = dune build -w
  • window 2 = neovim with OCaml lsp server support working

Now, when I see an error in the dune build -w window, I manually navigate to it in the nvim window and fix it there.

Is there a way in nvim window to auto get list of errors? (i.e. something that works with quick fix, cnext/cprev, or …). The current setup shows all errors/warnings in CURRENT buffer. However, if there are no errors in current buffer & an error elsewhere, I need to manually navigate. I would like to be able to just hit a key and “jump to next dune build error”


I don’t have a map that can jump to diagnostics across buffer, I use Telescope for that. So :Telescope diagnostics (or a map to that command) will bring up a window with the list of diagnostics and a code preview panel, and you can use that to jump to the error.
Fzf lua has a similar functionality ( diagnostics_document
vs diagnostics_workspace) but again it’s a picker, not a single quick jump command.

By looking at these 2 plugins and how they use the diagnostics and other related APIs, it should be possible to achieve what you are looking for.


Exactly what I needed. Thanks!

As a followup question:

  1. we are in nvim
  2. our project builds successfully with dune build
  3. merlin is not (directly)running (but may be running as part of lsp), but ocaml-lsp is running

In this situation, is there a way to have some statusline display the type signature of the variable under the cursor ?


I don’t think we would need to reach out to merlin, the lsp integration should have all we need.
Personally I have vim.lsp.buf.hover() mapped to K but that brings a floating window, I don’t have that in my status line.
The exact solution would probably depend of the status line plugin you are using, and (I’m guessing) would involve implementing a lsp-handler (unless of course, your status line plugin already offer something like that.)

I’m not sure I would go that way. To avoid hammering the with type information requests, you will probably put the refresh of the type under the cursor in an autocmd attached to an event like CursorHold. At that point, isn’t a very simple mapping like K with a floating window quicker than waiting for the updatetime to lapse?

An other advantage of the window: to successive call to the hover() function will give focus to the window, so it become easy to read long type declaration like a full module.

1 Like

Is your nvim/OCaml config public? I feel like there’s alot I can learn by plagerizing from that.

It’s probably not worth it anymore, I’m still in the testing phase, but I’ve migrated to https://astronvim.com/
I used to have a highly currated set-up, but it turns out:

  • Other people are better than me at creating advance neovim set-up, and I’d be much better tweaking theirs than maintaining mine.
  • Thanks to ocaml-lsp :sparkling_heart:, ocaml support in neovim has nothing special. You’ll get a first class experience by following any advance config tutorial or using one of the preconfigured configurations.

Astro, Lunar, and NvChad are all solid options I’ve considered. (I haven’t tested, or even open the GH pages of everything on that list, so the quality of the rest may vary)

I’ve tried LunarVim. I thing I did not like about these setups (not picking on Lunar in particular) is that they often pull in so many things that I can no longer understand what does what. It’s like this big ball of string that I can’t untangle into individual threads.

I understand the feeling, I’d be happy to help if you have more neovim questions.

FWIW I use doom-nvim, here is my fork (I’ve been upstreaming most of my changes slowly though): GitHub - edwintorok/doom-nvim: A Neovim configuration for the advanced martian hacker.
One thing that doesn’t work perfectly is support for ‘.mli’ files: I can either get tree-sitter to recognize .mli files as separate syntax, or have a working LSP in .mli files, but not both. (changing the filetype of to ocaml.interface breaks ocaml-lsp for me: it says “can’t find document with uri”, I didn’t dig deeper into why).
Here is the particular piece of code that maps K to lsp hover: doom-nvim/init.lua at main · edwintorok/doom-nvim · GitHub

Before ‘doom-nvim’ I had a hand written configuration that was a lot smaller in size (based on the Neovim-from-scratch and kickstart.nvim guides: GitHub - LunarVim/Neovim-from-scratch: 📚 A Neovim config designed from scratch to be understandable and GitHub - nvim-lua/kickstart.nvim: A launch point for your personal nvim configuration) but it was difficult keeping up with new features (especially LSP configuration): vim/.config/nvim · 0f04b6fa3af696fa5ae13860b613b3292349048b · Török Edwin / dotfiles · GitLab
And before that it was hand-written .vimrc (using ‘ALE’, before ocaml-lsp existed): vim · 23fa052c0ba64c6e6df6f127c58495da84da813a · Török Edwin / dotfiles · GitLab