Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Enable -haddock at parsing time #350

Closed
wants to merge 1 commit into from

Conversation

serras
Copy link
Contributor

@serras serras commented Jan 24, 2020

Fixes #7

@serras
Copy link
Contributor Author

serras commented Jan 24, 2020

This means that we also get documentation for the modules the user is editing, not only for its dependencies.

@@ -69,9 +69,10 @@ parseModule
-> Maybe SB.StringBuffer
-> IO ([FileDiagnostic], Maybe ParsedModule)
parseModule IdeOptions{..} env file =
let env' = env { hsc_dflags = hsc_dflags env `gopt_set` Opt_Haddock } in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GHC has both Opt_KeepRawTokenStream and Opt_Haddock which are mutually incompatible. We need Opt_KeepRawTokenStream in DAML since HLint will otherwise miss some hints and we’ll need the same in ghcide if we start integrating HLint.

So hardcoding this to Opt_Haddock isn’t really an option. Sadly, I don’t have a great answer for what the right option would be. I guess for now, we could add a ForceHadock field to IdeOptions and then set this to True for ghcide and if we do integrate HLint we accept that we miss some hints since docs are probably more useful. Long-term this should really get fixed in GHC so that the two are not exclusive (iirc the long-term plan is to build haddock on top of Opt_KeepRawTokenStream).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seemed too easy to not have been tried earlier.

@serras serras closed this Jan 24, 2020
@pepeiborra
Copy link
Collaborator

Parse twice, once for docs and another for hlint? Want Haddocks please.

@serras
Copy link
Contributor Author

serras commented Jan 25, 2020

The problem is that you would essentially double the memory consumption :(

One simple solution is to add ghc-options: -haddock to your Cabal file, or {-# OPTIONS_GHC -haddock #-} to your files, because then the option is set for your project/file.

@pepeiborra
Copy link
Collaborator

No, you would double the amount of memory used to store the parsed AST. Even if it is inefficient, the cost would only be paid once/if hlint is integrated.
Are there any downsides to enabling -haddock in my project file? Will that break Hlint?

@serras
Copy link
Contributor Author

serras commented Jan 25, 2020 via email

@cocreature
Copy link
Collaborator

Running HLint independently is fine, this is about integrating HLint via Shake rules that rely on GetParsedModule.

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

Successfully merging this pull request may close these issues.

get haddock working
3 participants