Skip to content

Enable Code Lens / Inlay-Hints in neovim? #1521

@rabiescow

Description

@rabiescow

Hello,

I can't find any documentation nor information on how to enable code-lens or inlay-hints with ocaml-lsp for neovim. I understand that the ocaml-lsp has those features from testing it in VSCode (I have a recollection of them being there in the past as well, so I assume the default values were changed at some point?). The feature I especially want is the inlay-hints of the type definition of functions.

The lsp specific settings at the bottom of my ocamllsp config doesn't seem to have any effect. What is the correct way to communicate with the lsp here?

Image

This is my language server setup:

    lsp.ocamllsp.setup({
      capabilities = capabilities,
      on_attach = on_attach,
      cmd = { "ocamllsp" },
      filetypes = {
        "ocaml",
        "ocaml.menhir",
        "ocaml.interface",
        "ocaml.ocamllex",
        "dune"
      },
      root_dir = lsp.util.root_pattern(
        "*.opam",
        "esy.json",
        "package.json",
        ".git",
        "dune-project",
        "dune-workspace"
      ),
      -- grabbed from https://github.com/ocaml/ocaml-lsp/blob/3dc1a6633bfe2ebd34d7aa38f008c8c28300ee55/ocaml-lsp-server/docs/ocamllsp/config.md
      -- these settings don't seem to have any effect.
      settings = {
        ocamllsp = { 
          extendedHover = true,
          codelens = true,
          duneDiagnostics = true,
          inlayHints = true,
          syntaxDocumentation = true,
          merlinJumpCodeActions = true,
        },
      },
    })

My config for the inlay hints and code lensing (works for golang and lua):

-- Inlay Hint provider config
-- Only turn on inlay hints when not in Insert mode
if client.server_capabilities.inlayHintProvider then
  local inlayhint = vim.api.nvim_create_augroup(
    "LspInlayHint", { clear = true })
  vim.api.nvim_create_autocmd({ "InsertLeave", "BufEnter" }, {
    buffer = bufnr,
    group = inlayhint,
    callback = function()
      vim.g.inlay_hints_visible = true
      vim.lsp.inlay_hint.enable(true, { bufnr })
    end
  })
  vim.api.nvim_create_autocmd({ "InsertEnter" }, {
    buffer = bufnr,
    group = inlayhint,
    callback = function()
      vim.g.inlay_hints_visible = false
      vim.lsp.inlay_hint.enable(false, { bufnr })
    end
    })
  else
    print("no inlay_hints available")
  end

-- Code Lens provider config
-- Only turn on code lens when not in Insert mode
if client.server_capabilities.codeLensProvider then
  local codelens = vim.api.nvim_create_augroup(
    "LSPCodeLens", { clear = true })
  vim.api.nvim_create_autocmd({ "InsertLeave", "BufEnter" }, {
    buffer = bufnr,
    group = codelens,
    callback = function()
      vim.lsp.codelens.refresh()
      local lenses = vim.lsp.codelens.get(bufnr)
      vim.lsp.codelens.display(lenses, bufnr, client.id)
    end,
  })
  vim.api.nvim_create_autocmd({ "InsertEnter" }, {
    buffer = bufnr,
    group = codelens,
    callback = function()
      vim.lsp.codelens.clear(client.id, bufnr)
    end,
  })
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions