Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
expipiplus1 opened this issue Sep 20, 2024 · 4 comments

Comments

@expipiplus1
Copy link

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
@expipiplus1 expipiplus1 added the bug Something isn't working label Sep 20, 2024
@mrcjkb
Copy link
Owner

mrcjkb commented Sep 20, 2024

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.

@mrcjkb mrcjkb closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2024
@mrcjkb mrcjkb added upstream (hls) and removed bug Something isn't working labels Sep 20, 2024
@expipiplus1
Copy link
Author

Looks like this: haskell/haskell-language-server#3062 thanks

@expipiplus1
Copy link
Author

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
Copy link
Owner

mrcjkb commented Sep 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants