Skip to content

Migrate HLS-refactor-plugin to use Structured Diagnostic#4849

Open
vidit-od wants to merge 3 commits intohaskell:masterfrom
vidit-od:Structural-Diagnostics-Refactor-Plugin
Open

Migrate HLS-refactor-plugin to use Structured Diagnostic#4849
vidit-od wants to merge 3 commits intohaskell:masterfrom
vidit-od:Structural-Diagnostics-Refactor-Plugin

Conversation

@vidit-od
Copy link
Collaborator

A contributing to #4605

This PR aims at Partially Migrating Hls-refactor-plugin to use Structured Diagnostics.

Below is a file wise list of functions that have been successfully migrated by this PR. A complete migration was attempted but could not be achieved due to lack of some information from GHC Api .

FillHole.hs

  • suggestFillHole

Diagnostic.hs

  • matchFoundHole
  • matchFoundHoleIncludeUnderscore
  • matchVariableNotInScope

CodeAction.hs

  • suggestHideShadow
  • suggestRemoveRedundantImport
  • suggestDeleteUnusedBinding
  • suggestExportUnusedTopBinding
  • suggestNewDefinition
  • removeRedundantConstraints

Inspiration tax :
Some of the content in this PR was inspired / stolen (👀) from PR #4695 :)

@vidit-od vidit-od force-pushed the Structural-Diagnostics-Refactor-Plugin branch 5 times, most recently from c1e333e to 2c98040 Compare February 25, 2026 09:42
@vidit-od vidit-od force-pushed the Structural-Diagnostics-Refactor-Plugin branch from 2c98040 to b89cbb6 Compare February 25, 2026 09:52
@fendor fendor requested a review from VeryMilkyJoe March 5, 2026 09:45
(rdrName, _) <- diagReportNotInScope fd
Just (printOutputable rdrName, Nothing)

-- | Extract the 'Hole' out of a 'FileDiagnostic'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could use a bit more explanation in the documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i am not 100% sure if i fixed this,

by adding documentation did you mean :
a ) for why we are directly converting to string ? if so we have removed this behavior
b) for the hole extract function ? if so this was before this PR, this function already existed ( in fillwildcard.hs )
This PR just moved the exact function from fillwildcard to dignostics.hs ( it better suits in this file )

i did expand the comment a little to address this review, but just wanted to clear if i understood the assignment or not :)

Comment on lines 177 to 186
-- Add a typed hole to a type signature in the given argument position:
-- 0 `foo :: ()` => foo :: _ -> ()
-- 2 `foo :: FunctionTySyn` => foo :: FunctionTySyn
-- 1 `foo :: () -> () -> Int` => foo :: () -> _ -> () -> Int
addTyHoleToTySigArg :: Int -> LHsSigType GhcPs -> LHsSigType GhcPs
addTyHoleToTySigArg loc (L annHsSig (HsSig xHsSig tyVarBndrs lsigTy)) =
let (args, res) = hsTypeToFunTypeAsList lsigTy
#if MIN_VERSION_ghc(9,13,0)
wildCardAnn = noAnnSrcSpanDP1
newArg =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since we get the Types from GHC now,
we can try and improve this from add type hole to signature
to add type to signature maybe ?

i am not sure tho, i cannot replicate the current expected behavior locally ( examples in comment ).

@vidit-od vidit-od force-pushed the Structural-Diagnostics-Refactor-Plugin branch from ee5fa07 to 6be6a67 Compare March 12, 2026 08:05
@vidit-od vidit-od requested a review from VeryMilkyJoe March 12, 2026 08:08
Fix a lot of spacing and indentation inconsistences, also propagate structured info further to better use it instead of direct conversion to string.
@vidit-od vidit-od force-pushed the Structural-Diagnostics-Refactor-Plugin branch from 6be6a67 to 585a255 Compare March 12, 2026 08:17
Comment on lines +35 to +36
import Language.LSP.Protocol.Lens (HasRange (..),
message)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These imports are breaking circleci build tests.
Need some help/direction on how to tackle these failures ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we can't CPP in this situation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, could not find any way to remove this redundant import error :(

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