Skip to content

Use structured diagnostics in pragmas plugin #4620

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dyniec
Copy link
Contributor

@dyniec dyniec commented Jun 7, 2025

Changes suggestion provider in pragmas plugin to
use structured diagnostics and ghc machinery to
generate hints

@dyniec dyniec requested a review from eddiemundo as a code owner June 7, 2025 16:24
@dyniec dyniec force-pushed the structured-diagnostics branch 2 times, most recently from 079ed08 to 01648e0 Compare June 8, 2025 08:40
@dyniec dyniec changed the title WIP: Use structured diagnostics in pragmas plugin Use structured diagnostics in pragmas plugin Jun 8, 2025
@dyniec
Copy link
Contributor Author

dyniec commented Jun 8, 2025

Removed all temporary changes, and made it work on all types of errors (first version was working only on suggestions for type errors). Tested it on small repository and it seems to be working on example with LambdaCase and RecordWildCards missing.
As for provider suggestDisableWarning, I haven't looked deeply to find if there's good way to get data it needs from structured diagnostics, so it uses old diagnostics for now

@dyniec dyniec force-pushed the structured-diagnostics branch from 01648e0 to 305eaab Compare June 8, 2025 13:01
@dyniec
Copy link
Contributor Author

dyniec commented Jun 8, 2025

It seems that in ghc 9.6 GhcHints don't return TypeApplications and TypeSynonymInstances - see ghc9.6 vs current. I will test it further

@dyniec
Copy link
Contributor Author

dyniec commented Jun 8, 2025

Found the source for old messages ghc9.6 and it's indeed not structured but it was working fine enough with text search.

What remains to be verified is that ghc versions from 9.8 converted all error messages suggesting extensions to structured diagnostics. Hopefully that's the case as I'm implementing workaround that checks ghc versions and based on that uses either old approach or new.

@dyniec dyniec force-pushed the structured-diagnostics branch from 305eaab to 0ecb2ad Compare June 8, 2025 15:07
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Just a couple of nitpicks.

Changes suggestion provider in pragmas plugin to
use structured diagnostics and ghc machinery to
generate hints
@dyniec dyniec force-pushed the structured-diagnostics branch from 0ecb2ad to 90eb271 Compare June 8, 2025 15:55
@dyniec
Copy link
Contributor Author

dyniec commented Jun 8, 2025

Part of #4605

Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM!

@fendor fendor added the merge me Label to trigger pull request merge label Jun 26, 2025
Copy link
Collaborator

@soulomoon soulomoon left a comment

Choose a reason for hiding this comment

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

Good work, @dyniec!
Just a small convention tweak: for consistency, it would be better to import from Development.IDE.GHC.Compat.Error.
Also, please add the following to the export list of Development.IDE.GHC.Compat.Error:

GhcHint (SuggestExtension),
LanguageExtensionHint (..),

@@ -910,6 +910,7 @@ library hls-pragmas-plugin
, text
, transformers
, containers
, ghc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
, ghc
, ghc
Suggested change
, ghc

Comment on lines +39 to +41
import GHC.Types.Error (GhcHint (SuggestExtension),
LanguageExtensionHint (..),
diagnosticHints)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import GHC.Types.Error (GhcHint (SuggestExtension),
LanguageExtensionHint (..),
diagnosticHints)
import GHC.Types.Error (GhcHint (SuggestExtension),
LanguageExtensionHint (..),
diagnosticHints)
Suggested change
import GHC.Types.Error (GhcHint (SuggestExtension),
LanguageExtensionHint (..),
diagnosticHints)

import Development.IDE.Core.PluginUtils
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.Error (msgEnvelopeErrorL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import Development.IDE.GHC.Compat.Error (msgEnvelopeErrorL)
import Development.IDE.GHC.Compat.Error (msgEnvelopeErrorL)
Suggested change
import Development.IDE.GHC.Compat.Error (msgEnvelopeErrorL)
import Development.IDE.GHC.Compat.Error (GhcHint (SuggestExtension),
LanguageExtensionHint (..),
diagnosticHints,
msgEnvelopeErrorL)

@fendor fendor removed the merge me Label to trigger pull request merge label Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants