Hello!
Has anyone been able to set up inlay hints for the ocamllsp within neovim? It’s about the only thing I miss from vscode compared to neovim.
This is my config.
ocamllsp = {
cmd = { "ocamllsp" },
filetypes = { "ocaml", "menhir", "ocamlinterface", "ocamlocamllex",
"reason", "dune" },
root_dir = require("lspconfig").util.root_pattern("*.opam", "esy.json",
"package.json", ".git", "dune-project", "dune-workspace"),
settings = {
ocamllsp = {
extendedHover = true,
codelens = true,
duneDiagnostics = true,
inlayHints = true,
syntaxDocumentation = true,
merlinJumpCodeActions = true,
},
},
},
I tried working with simrat39/inlay-hints.nvim but wasn’t able to get it working. Has anyone else been lucky with inlay hints? It’s really nice to see the function definition above the function. I had it working in the past but not sure when it disappeared.
Yeah I got inlay hints working with the following config:
settings = {
codelens = { enable = true },
inlayHints = { hintPatternVariables = true, hintLetBindings = true },
extendedHover = { enable = true },
syntaxDocumentation = { enable = true },
merlinJumpCodeActions = { enable = true },
}
I do also use a patched version of ocamllsp, that sets the -avoid-ghost-location flag to false when it makes the request to merlin. It’s probably completely unnecessary, but I prefer it.
The patch I use:
diff --git a/ocaml-lsp-server/src/inlay_hints.ml b/ocaml-lsp-server/src/inlay_hints.ml
index 8e87a309..82d1a427 100644
--- a/ocaml-lsp-server/src/inlay_hints.ml
+++ b/ocaml-lsp-server/src/inlay_hints.ml
@@ -34,7 +34,7 @@ let compute (state : State.t) { InlayHintParams.range; textDocument = { uri }; _
and stop = range.end_ |> Position.logical in
let command =
Query_protocol.Inlay_hints
- (start, stop, hint_let_bindings, hint_pattern_variables, not inside_test)
+ (start, stop, hint_let_bindings, hint_pattern_variables, false)
in
let hints = Query_commands.dispatch pipeline command in
List.filter_map
I hope that helps!
1 Like
Oh yes, also make sure inlay hints are enabled, I have it on an lspAttach autocommand that enables them.
Something along these lines:
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
if client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(true)
end
end,
})
1 Like