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

Hover docs including links for dependencies #208

Open
georgefst opened this issue Jul 19, 2020 · 22 comments
Open

Hover docs including links for dependencies #208

georgefst opened this issue Jul 19, 2020 · 22 comments

Comments

@georgefst
Copy link
Collaborator

As it stands, it seems that Haddock docs show up for boot libraries, and the project being developed, but not for third party libraries from Hackage.

I would guess (without really knowing anything about the current implementation) that if the dependencies have been installed with documentation (e.g. documentation: True in the global cabal config file), then the logic wouldn't be that different to the way it currently works for boot libraries - i.e. HLS just needs some way to know the path to the .haddock files.

I'd be keen to take a look into this if no one currently is. But I would need some pointers.

@jneira
Copy link
Member

jneira commented Jul 19, 2020

A possible workaround is to active documentation generation for all dependant packages adding in the cabal.project:

package * 
  documentation: true

(tip credits for @fendor)
It will make the build really slow but it can be done ocasionally.

The hoogle plugin would add docs for dependent packages included in its default set. In the practice they are quite used so you would cover docs for many deps.

@pepeiborra
Copy link
Collaborator

Ignoring the hoogle plugin, currently hls/ghcide glean Haddocks from interface files. For interface files to contain Haddocks, ghc must be called with the -haddock flag.

Unfortunately, I don't believe Cabal currently knows about this ghc flag, regardless of the documentation:True setting [1]. You could work around this yourself by telling cabal to use this flag when compiling dependencies in the cabal.project file, or if using stack, in the stack.yaml file.

For Nix, I have sent a PR [2] to add a setting for this, although it will not be the default until 8.12

[1] - haskell/cabal#6825
[2] - NixOS/nixpkgs#91557

@jneira
Copy link
Member

jneira commented Jul 19, 2020

Ignoring the hoogle plugin, currently hls/ghcide glean Haddocks from interface files. For interface files to contain Haddocks, ghc must be called with the -haddock flag.

There is a open issue about implementing the plugin, maybe we should closing it with a note.

@georgefst
Copy link
Collaborator Author

georgefst commented Jul 19, 2020

Thanks @pepeiborra, I didn't know about that flag!

Not sure what the long-term solution is here then, but for now it seems like it might be worth mentioning in the README that this can be worked around with something like cabal configure --ghc-options=-haddock. Of course, that does cause everything to be rebuilt, and I suspect the build takes a lot longer than without it...

@pepeiborra
Copy link
Collaborator

pepeiborra commented Jul 19, 2020

@georgefst better documentation would help, but at the moment my setup is Nix based and I don't use either stack or cabal.project style builds, so I'm not in a good position to give advice about this. If you could send a PR documenting the approach that works for you, it would be a fantastic contribution.

@jneira
Copy link
Member

jneira commented Jul 20, 2020

@pepeiborra thanks for the clarification about how hls/ghcide hover works.

I think we should update hls itself cabal.project and stack.yaml dropping the documentation flags and adding the -haddock ghc options cause afaik the main goal for adding them was precisely get docs on hover.

I've tested locally that using -haddock show docs but no using documentation: true, did it work for you @fendor?

@jneira
Copy link
Member

jneira commented Nov 9, 2020

As hie-bios can use a specific stack.yaml (and there is a request to be able to set a specific cabal.project), the -haddockoption could be in those specific config files as workaround if the option interferes with normal building (making it slower or fail).
Beyond that the unique way to make some progress (avoid the need to generate haddock docs for all dependencies) would be port the hoogle plugin.

seagreen added a commit to seagreen/unison that referenced this issue Feb 25, 2021
(See this issue: haskell/haskell-language-server#208)

Adding -haddock gives doc-on-hover for 3rd party libraries like megaparsec.

I tested this on a big codebase (>20k SLOC) and compile times stayed the same.
@georgefst
Copy link
Collaborator Author

As well as #209, we ought to document that --enable-documentation is required to get the Documentation link to appear with the hover text.

Should we keep things simple and just tell users to enable it globally in addition to -haddock?

@jneira
Copy link
Member

jneira commented Oct 21, 2021

As well as #209, we ought to document that --enable-documentation is required to get the Documentation link to appear with the hover text.

Should we keep things simple and just tell users to enable it globally in addition to -haddock?

I think we should add a note about --enable-documentation in the existing section suggesting add -haddock` (https://haskell-language-server.readthedocs.io/en/latest/configuration.html#how-to-show-local-documentation-on-hover)

@georgefst would you like and have time to open a pr adding it?

@jneira jneira changed the title Hover docs for dependencies Hover docs including links for dependencies Oct 21, 2021
@georgefst
Copy link
Collaborator Author

@jneira I'm sure it's a fairly quick change but I'm pretty swamped at the moment.

I also don't know the stack syntax off-hand, and there are probably caveats to mention (increased compile times? I'm not sure whether this is negligible in practice).

@jneira
Copy link
Member

jneira commented Oct 21, 2021

dont worry will try myself, thanks anyways!

@rami3l
Copy link

rami3l commented Jun 21, 2022

I don't know if it's related or not, but u/2435191 and I have encountered this strange behavior of base hover docs not working, quote:

image

[...] when hovering over a builtin function only type information comes up, not the actual docstring of the function [...] (Interestingly, the "Documentation Source" link leads me to the web docs, but I don't want to click everytime.)

Original Post

@jneira Do you happen to have any clue on this one?

@July541
Copy link
Collaborator

July541 commented Jun 21, 2022

@rami3l Looks like it's on ghc-9.0, docs is known missing, see https://gitlab.haskell.org/ghc/ghc/-/issues/20903.

@rami3l
Copy link

rami3l commented Jun 21, 2022

@July541
Thanks a lot for your reply!
This turned out to be more complicated than it seems however...

After upgrading the compiler to GHC 9.2.2 (or more precisely, after using stack snapshot nightly-2022-06-06),

VSCode on my Ubuntu box gives me this, which is expected:
telegram-cloud-photo-size-5-6163264279076254518-y

However, my Mac gives me this:
image

... and I have no idea how to fix this. If you need more info on this, please feel free to ask me!

@July541
Copy link
Collaborator

July541 commented Jun 22, 2022

@rami3l That's amazing, I always thought that only ghc-9.0 had this problem, but I found both ghc-9.2.2 and 9.2.3 are also not shipping the docs. Worth raising a ticket for ghc devs.

Update:
I compiled ghc on local and docs works fine.

@rami3l
Copy link

rami3l commented Jun 22, 2022

@July541
You mean there could be some problems with the precompiled GHC binaries?

@July541
Copy link
Collaborator

July541 commented Jun 22, 2022

You mean there could be some problems with the precompiled GHC binaries?

Yes I think.

@rami3l
Copy link

rami3l commented Jun 22, 2022

@July541
My apologies for my not having much experience interacting with the GHC team, but anyway I sent a comment in GHC/#20903.

@July541
Copy link
Collaborator

July541 commented Jun 22, 2022

@rami3l Many thanks for your timely reminder :)

@rami3l
Copy link

rami3l commented Aug 3, 2022

@July541
Just bring curious: a month later I still didn't get any reply from GHC... Is that thread the wrong place to post?

@July541
Copy link
Collaborator

July541 commented Aug 10, 2022

Just bring curious: a month later I still didn't get any reply from GHC... Is that thread the wrong place to post?

GHC devs are slow to respond to some low-priority jobs I think.

And thanks to ghcup, compiling ghc from source is much easier than before, I've turned to build ghc from source to make docs available.

@rami3l
Copy link

rami3l commented Feb 2, 2023

Update: This is indeed an issue with prebuilt GHC releases from ghcup. I don't know about newer GHC 9.2.x versions, but updating to GHC 9.4.4 works for me on macOS.

Many thanks to all of you!

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

5 participants