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.
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
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,
})
It’s probably not applicable to most but I use a nix development shell, created from a flake, which handles the patch.
devShells = {
default = mkShell {
inputsFrom = [self'.packages.default];
buildInputs = with ocamlPackages; [
utop
ocamlformat
# patch ocaml-lsp so that inlay hints dont hide ghost values
(ocamlPackages.ocaml-lsp.overrideAttrs (oldAttrs: {
patches = [
./inlay-hints.patch
];
}))
];
};
};
If I wasn’t using nix, the easiest would probably be to make a fork and set up an action to automatically stay up to date.
However, in the newest version of the LSP it seems like the issue I was patching for seems not existent, so I won’t be patching in the latest versions.