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

#573, make haddock errors warnings with the word Haddock in front #608

Merged
merged 3 commits into from
Jun 9, 2020

Conversation

ndmitchell
Copy link
Collaborator

Fixes #573. Downgrade Haddock errors to warnings, and prepend Haddock in front of them. Now we are manipulating Haddock warnings, its easier to dedupe them by range than trying to merge arbitrary diagnostics.

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

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

There's probably more changes needed to handle Haddock errors in dependencies, see:

https://github.com/digital-asset/ghcide/blob/master/src/Development/IDE/Core/Rules.hs#L632-L635


((fingerPrint, (diags, res)), diagsHaddock) <-
-- parse twice, with and without Haddocks, concurrently
-- we cannot ignore Haddock parse errors because files of
-- non-interest are always parsed with Haddocks
liftIO $ concurrently mainParse haddockParse

return (fingerPrint, (mergeDiagnostics diags diagsHaddock, res))
-- if you have a Haddock warning and a real warning at the same exact location, throw away the Haddock one
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this special logic? I would think that a comment can only have Haddock warnings

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We run the parser twice. If you have ( as your source file, it will be a parse error with both Haddock and without, so you'll get the same error twice. This dedupe ensures you only get the warning once.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so the comment is a bit misleading, it's only non Haddock warnings that need deduping, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment updated. Is that clearer?

@ndmitchell
Copy link
Collaborator Author

I've had much more issues with haddock warnings in files of interest because I just typed -- | ... to comment out a guard, whereas haddock issues in dependencies hasn't cropped up as much. I see that it that case we don't parse twice, but only once - does that mean a Haddock in a dependency is a fatal error?

@pepeiborra
Copy link
Collaborator

I've had much more issues with haddock warnings in files of interest because I just typed -- | ... to comment out a guard, whereas haddock issues in dependencies hasn't cropped up as much. I see that it that case we don't parse twice, but only once - does that mean a Haddock in a dependency is a fatal error?

I would think so, yes, and the solution is similar - parse again without OptHaddock.

@ndmitchell
Copy link
Collaborator Author

ndmitchell commented Jun 6, 2020

It feels odd that we have two locations where we do a parse with haddock/parse without dance, and in one we use concurrently, and in one we don't. We should probably do the same thing in both cases.

My guess is "the right thing" is to parse with Haddock, and if there are no errors, continue on. If there were errors, parse again without Haddock, and turn all errors that came from Haddock only into warnings. For files with parse errors it's slightly more latency, but the latency on a parse error is pretty low already, so that isn't a massive problem.

@pepeiborra if that makes sense to you, I'll try that.

@pepeiborra
Copy link
Collaborator

It feels odd that we have two locations where we do a parse with haddock/parse without dance, and in one we use concurrently, and in one we don't. We should probably do the same thing in both cases.

My guess is "the right thing" is to parse with Haddock, and if there are no errors, continue on. If there were errors, parse again without Haddock, and turn all errors that came from Haddock only into warnings. For files with parse errors it's slightly more latency, but the latency on a parse error is pretty low already, so that isn't a massive problem.

@pepeiborra if that makes sense to you, I'll try that.

The reason we don't parse with -haddock always-on is that it throws away annotations (ref. @cocreature ), which can be troublesome. For interface files we don't care as the parsed AST is not stored, but for files of interest we probably do care.

@ndmitchell
Copy link
Collaborator Author

OK, I'll try figuring out some sane abstractions to handle that mess.

@cocreature
Copy link
Collaborator

The reason we don't parse with -haddock always-on is that it throws away annotations (ref. @cocreature ), which can be troublesome. For interface files we don't care as the parsed AST is not stored, but for files of interest we probably do care.

Adding a bit more context here: GHC has Opt_Haddock and Opt_KeepRawTokenStream which are mutually exclusive. In theory, the latter preserves all information for haddock to work based on it afaik and there is an issue somewhere for making it work. In practice, haddock currently only works if you use Opt_Haddock which throws away information that tools like HLint rely on and which is included in Opt_KeepRawTokenStream.

@ndmitchell
Copy link
Collaborator Author

So we still have two different behaviours. For getModIface we try with Haddock, and if that fails, fall back to without. Otherwise, we do both in parallel and merge them. I centralised the "merge them" code, so they aren't too different, but the weird corner cases around Haddock are pretty frustrating!

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Thanks!

@cocreature cocreature merged commit 154e57f into haskell:master Jun 9, 2020
aherrmann-da pushed a commit to digital-asset/daml that referenced this pull request Jul 15, 2020
Version 0.2.0 was hitting issues that have since been fixed by
haskell/ghcide#608
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…k in front (haskell/ghcide#608)

* haskell/ghcide#573, make haddock errors warnings with the word Haddock in front

* Update Rules.hs

* Deal with Haddock failures in getModIfaceRule
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…k in front (haskell/ghcide#608)

* haskell/ghcide#573, make haddock errors warnings with the word Haddock in front

* Update Rules.hs

* Deal with Haddock failures in getModIfaceRule
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…k in front (haskell/ghcide#608)

* haskell/ghcide#573, make haddock errors warnings with the word Haddock in front

* Update Rules.hs

* Deal with Haddock failures in getModIfaceRule
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.

Parse error on comment that ghc accepts
3 participants