mrcjkb / haskell-tools.nvim

🦥 Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
477 stars 19 forks source link

Source/Documentation actions sometimes don't appear the first time a hover menu is opened #396

Closed expipiplus1 closed 1 month ago

expipiplus1 commented 1 month ago

Neovim version (nvim -v)

v0.10.1

Operating system/version

NixOS

Output of :checkhealth haskell-tools

haskell-tools: require("haskell-tools.health").check()

  Checking for Lua dependencies
  - OK [nvim-telescope/telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) installed.

  Checking external dependencies
  - OK haskell-language-server: found haskell-language-server version: 2.9.0.0 (GHC: 9.8.2) (PATH: /nix/store/wj2g4wff8lyqcwxfh2xwrxbvfisxa743-haskell-language-server-2.9.0.0/bin/haskell-language-server-wrapper)
  - OK hoogle: found Hoogle 5.0.18.4, https://hoogle.haskell.org/
  - WARNING       fast-tags: not found.
          Install [fast-tags](https://hackage.haskell.org/package/fast-tags) for extended capabilities.
          Optional, for generating tags as a tagfunc fallback.

  - OK curl: found curl 8.7.1 (x86_64-pc-linux-gnu) libcurl/8.7.1 OpenSSL/3.0.14 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.61.0
  - OK haskell-debug-adapter: found haskell-debug-adapter-0.0.40.0
  - OK ghci-dap: found The Glorious Glasgow Haskell Compilation System, version 9.8.2

  Checking config
  - OK No errors found in config.

  Checking for conflicting plugins
  - OK No conflicting plugins detected.

How to reproduce the issue

Load a haskell project and wait for hls to initialize

Open the hover menu on an identifier vim.lsp.buf.hover() or whatever keybinding exists

Observe that the Open documentation in browser and Open source in browser links are not present

Close the menu

Open it again and observe that they're present

Expected behaviour

The first time the hover menu is opened these links are present (if available)

Actual behaviour

Sometimes, to see these links the hover must be closed and reopened

Log files

No response

The minimal config used to reproduce this issue.

let me know if this is necessary
mrcjkb commented 1 month ago

hey 👋

haskell-tools just parses the response it receives from haskell-language-server, to create the hover actions. There's nothing that can be done in this plugin to solve your problem. hls might still be gathering information the first time you open the hover window, but will respond with partial hover information while doing so.

expipiplus1 commented 1 month ago

Looks like this: https://github.com/haskell/haskell-language-server/issues/3062 thanks

expipiplus1 commented 1 month ago

FWIW this is what I'm using now

        ["<Leader>lo"] = {
          function()
            local function make_hover_request(callback, retry)
              local params = vim.lsp.util.make_position_params()
              vim.lsp.buf_request(0, "textDocument/hover", params, function(err, result, _, _)
                if err or not result or not result.contents then
                  if not retry then print "No hover information available" end
                  return
                end

                local markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
                local uri

                for _, line in ipairs(markdown_lines) do
                  if vim.startswith(line, "[Documentation]") then
                    uri = string.match(line, "%[Documentation%]%((.+)%)")
                    if uri then
                      callback(uri)
                      return
                    end
                  end
                end

                if not retry then
                  -- If we didn't find the documentation link, try once more
                  vim.defer_fn(function() make_hover_request(callback, true) end, 100)
                else
                  print "Could not find documentation link"
                end
              end)
            end

            make_hover_request(function(uri)
              if uri then
                vim.fn.jobstart({ "xdg-open", uri }, { detach = true })
                print "Opening documentation in browser"
              end
            end)
          end,
          desc = "Open documentation",
          cond = function(client) return client.supports_method "textDocument/hover" end,
        },

Just in case anyone else wants this

mrcjkb commented 1 month ago

@expipiplus1 I think you meant to post that in #395 :smile: