-
-
Notifications
You must be signed in to change notification settings - Fork 430
Migrate HLS-refactor-plugin to use Structured Diagnostic #4849
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,31 @@ | ||
| {-# LANGUAGE CPP #-} | ||
|
|
||
| module Development.IDE.Plugin.Plugins.Diagnostic ( | ||
| matchVariableNotInScope, | ||
| matchRegexUnifySpaces, | ||
| unifySpaces, | ||
| matchFoundHole, | ||
| matchFoundHoleIncludeUnderscore, | ||
| diagReportHoleError | ||
| ) | ||
| where | ||
|
|
||
| import Data.Bifunctor (Bifunctor (..)) | ||
| import qualified Data.Text as T | ||
| import Text.Regex.TDFA ((=~~)) | ||
| import Control.Lens | ||
| import Data.Bifunctor (Bifunctor (..)) | ||
| import qualified Data.Text as T | ||
| import Development.IDE (printOutputable) | ||
| import Development.IDE.GHC.Compat (RdrName) | ||
| import Development.IDE.GHC.Compat.Error (Hole, _ReportHoleError, | ||
| _TcRnMessage, | ||
| _TcRnNotInScope, | ||
| _TcRnSolverReport, hole_occ, | ||
| hole_ty, msgEnvelopeErrorL, | ||
| reportContentL) | ||
| import Development.IDE.Types.Diagnostics (FileDiagnostic, | ||
| _SomeStructuredMessage, | ||
| fdStructuredMessageL) | ||
| import GHC.Tc.Errors.Types (NotInScopeError) | ||
| import Text.Regex.TDFA ((=~~)) | ||
|
|
||
| unifySpaces :: T.Text -> T.Text | ||
| unifySpaces = T.unwords . T.words | ||
|
|
@@ -27,33 +43,53 @@ matchRegex message regex = case message =~~ regex of | |
| matchRegexUnifySpaces :: T.Text -> T.Text -> Maybe [T.Text] | ||
| matchRegexUnifySpaces message = matchRegex (unifySpaces message) | ||
|
|
||
| matchFoundHole :: T.Text -> Maybe (T.Text, T.Text) | ||
| matchFoundHole message | ||
| | Just [name, typ] <- matchRegexUnifySpaces message "Found hole: _([^ ]+) :: ([^*•]+) Or perhaps" = | ||
| Just (name, typ) | ||
| | otherwise = Nothing | ||
|
|
||
| matchFoundHoleIncludeUnderscore :: T.Text -> Maybe (T.Text, T.Text) | ||
| matchFoundHoleIncludeUnderscore message = first ("_" <>) <$> matchFoundHole message | ||
|
|
||
| matchVariableNotInScope :: T.Text -> Maybe (T.Text, Maybe T.Text) | ||
| matchVariableNotInScope message | ||
| -- * Variable not in scope: | ||
| -- suggestAcion :: Maybe T.Text -> Range -> Range | ||
| -- * Variable not in scope: | ||
| -- suggestAcion | ||
| | Just (name, typ) <- matchVariableNotInScopeTyped message = Just (name, Just typ) | ||
| | Just name <- matchVariableNotInScopeUntyped message = Just (name, Nothing) | ||
| | otherwise = Nothing | ||
| where | ||
| matchVariableNotInScopeTyped message | ||
| | Just [name, typ0] <- matchRegexUnifySpaces message "Variable not in scope: ([^ ]+) :: ([^*•]+)" | ||
| , -- When some name in scope is similar to not-in-scope variable, the type is followed by | ||
| -- "Suggested fix: Perhaps use ..." | ||
| typ:_ <- T.splitOn " Suggested fix:" typ0 = | ||
| Just (name, typ) | ||
| | otherwise = Nothing | ||
| matchVariableNotInScopeUntyped message | ||
| | Just [name] <- matchRegexUnifySpaces message "Variable not in scope: ([^ ]+)" = | ||
| Just name | ||
| | otherwise = Nothing | ||
| matchFoundHole :: FileDiagnostic -> Maybe (T.Text, T.Text) | ||
| matchFoundHole fd = do | ||
| hole <- diagReportHoleError fd | ||
| Just (printOutputable (hole_occ hole), printOutputable (hole_ty hole)) | ||
|
|
||
| matchFoundHoleIncludeUnderscore :: FileDiagnostic -> Maybe (T.Text, T.Text) | ||
| matchFoundHoleIncludeUnderscore fd = first ("_" <>) <$> matchFoundHole fd | ||
|
|
||
| matchVariableNotInScope :: FileDiagnostic -> Maybe (T.Text, Maybe T.Text) | ||
| matchVariableNotInScope fd = do | ||
| (rdrName, _) <- diagReportNotInScope fd | ||
| Just (printOutputable rdrName, Nothing) | ||
vidit-od marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| -- | Extract the 'Hole' out of a 'FileDiagnostic' | ||
|
||
| diagReportHoleError :: FileDiagnostic -> Maybe Hole | ||
| diagReportHoleError diag = do | ||
| solverReport <- | ||
| diag | ||
| ^? fdStructuredMessageL | ||
| . _SomeStructuredMessage | ||
| . msgEnvelopeErrorL | ||
| . _TcRnMessage | ||
| . _TcRnSolverReport | ||
| . _1 | ||
| (hole, _) <- solverReport ^? reportContentL . _ReportHoleError | ||
|
|
||
vidit-od marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Just hole | ||
|
|
||
| -- | Extract the 'NotInScopeError' and the corresponding 'RdrName' from a 'FileDiagnostic' | ||
| -- if it represents a not-in-scope error. | ||
| diagReportNotInScope :: FileDiagnostic -> Maybe (RdrName, NotInScopeError) | ||
| diagReportNotInScope diag = do | ||
| #if MIN_VERSION_ghc(9,13,0) | ||
| (err, rdrName) <- | ||
| diag | ||
| ^? fdStructuredMessageL | ||
| . _SomeStructuredMessage | ||
| . msgEnvelopeErrorL | ||
| . _TcRnMessage | ||
| . _TcRnNotInScope | ||
| #else | ||
| (err, rdrName, _, _) <- | ||
| diag | ||
| ^? fdStructuredMessageL | ||
| . _SomeStructuredMessage | ||
| . msgEnvelopeErrorL | ||
| . _TcRnMessage | ||
| . _TcRnNotInScope | ||
| #endif | ||
| Just (rdrName, err) | ||
Uh oh!
There was an error while loading. Please reload this page.