lthms' avatar, a hand drawing looking person, wearing a headset, close to a window on a raining night
Thomas Letan
lthms · he/him

Did you come across something which caught your attention? Don’t hesitate to shoot me an email in my public inbox.

 Published on  Modified on

Neovim, OCaml Interfaces, Tree-Sitter and LSP

Can we all agree that witnessing syntax highlighting being absolutely off is probably the most annoying thing that can happen to anybody?

I mean, just look at this horror.

Syntax highlighting being absolutely wrong.

What you are looking at is the result of trying to enable tree-sitter for OCaml hacking and calling it a day. In a nutshell, OCaml mli files are quickly turning into a random mess of nonsensical colors, and I didn’t know why. I tried to blame tree-sitter-ocaml , but, of course I was wrong.

The issue is subtle, and to be honest, I don’t know if I totally grasp it. But from my rough understanding, it breaks down as follows.

So, in order to have both tree-sitter and ocamllsp working at the same time, I had to tweak my configuration a little bit.

lspconfig.ocamllsp.setup({
  filetypes = vim.list_extend(
    require('lspconfig.server_configurations.ocamllsp')
      .default_config
      .filetypes,
    { 'ocamlinterface' }
  ),
})

vim.cmd([[au! BufNewFile,BufRead *.mli setfiletype ocamlinterface]])

And now, I am blessed with a consistent syntax highlighting for my mli files.

Syntax highlighting being absolutely right.