@@ -52,7 +52,8 @@ import Development.IDE.GHC.Error
52
52
import Development.IDE.GHC.ExactPrint
53
53
import qualified Development.IDE.GHC.ExactPrint as E
54
54
import Development.IDE.GHC.Util (printOutputable ,
55
- printRdrName )
55
+ printRdrName ,
56
+ textInRange )
56
57
import Development.IDE.Plugin.CodeAction.Args
57
58
import Development.IDE.Plugin.CodeAction.ExactPrint
58
59
import Development.IDE.Plugin.CodeAction.PositionIndexed
@@ -330,8 +331,8 @@ findSigOfBinds range = go
330
331
findSigOfBind range (unLoc lHsBindLR)
331
332
go _ = Nothing
332
333
333
- findInstanceHead :: (Outputable ( HsType p ), p ~ GhcPass p0 ) => DynFlags - > Range -> [LHsDecl p ] -> Maybe (LHsType p )
334
- findInstanceHead df diagnosticLocation decls =
334
+ findInstanceHead :: (p ~ GhcPass p0 ) => Range -> [LHsDecl p ] -> Maybe (LHsType p )
335
+ findInstanceHead diagnosticLocation decls =
335
336
listToMaybe
336
337
[ hsib_body
337
338
| L (locA -> instanceLocation) (InstD _ (ClsInstD _ ClsInstDecl {cid_poly_ty = (unLoc -> HsSig {sig_body = hsib_body})})) <- decls
@@ -1215,7 +1216,7 @@ suggestConstraint df (makeDeltaAst -> parsedModule) diag@Diagnostic {..}
1215
1216
| Just missingConstraint <- findMissingConstraint _message
1216
1217
= let codeAction = if _message =~ (" the type signature for:" :: String )
1217
1218
then suggestFunctionConstraint df parsedModule
1218
- else suggestInstanceConstraint df parsedModule
1219
+ else suggestInstanceConstraint parsedModule
1219
1220
in codeAction diag missingConstraint
1220
1221
| otherwise = []
1221
1222
where
@@ -1237,9 +1238,9 @@ suggestConstraint df (makeDeltaAst -> parsedModule) diag@Diagnostic {..}
1237
1238
in getCorrectGroup <$> match
1238
1239
1239
1240
-- | Suggests a constraint for an instance declaration for which a constraint is missing.
1240
- suggestInstanceConstraint :: DynFlags -> ParsedSource -> Diagnostic -> T. Text -> [(T. Text , Rewrite )]
1241
+ suggestInstanceConstraint :: ParsedSource -> Diagnostic -> T. Text -> [(T. Text , Rewrite )]
1241
1242
1242
- suggestInstanceConstraint df (L _ HsModule {hsmodDecls}) Diagnostic {.. } missingConstraint
1243
+ suggestInstanceConstraint (L _ HsModule {hsmodDecls}) Diagnostic {.. } missingConstraint
1243
1244
| Just instHead <- instanceHead
1244
1245
= [(actionTitle missingConstraint , appendConstraint (T. unpack missingConstraint) instHead)]
1245
1246
| otherwise = []
@@ -1251,7 +1252,7 @@ suggestInstanceConstraint df (L _ HsModule {hsmodDecls}) Diagnostic {..} missing
1251
1252
-- • In the expression: x == y
1252
1253
-- In an equation for ‘==’: (Wrap x) == (Wrap y) = x == y
1253
1254
-- In the instance declaration for ‘Eq (Wrap a)’
1254
- | Just instHead <- findInstanceHead df _range hsmodDecls
1255
+ | Just instHead <- findInstanceHead _range hsmodDecls
1255
1256
= Just instHead
1256
1257
-- Suggests a constraint for an instance declaration with one or more existing constraints.
1257
1258
-- • Could not deduce (Eq b) arising from a use of ‘==’
@@ -1884,24 +1885,6 @@ splitTextAtPosition (Position (fromIntegral -> row) (fromIntegral -> col)) x
1884
1885
= (T. intercalate " \n " $ preRow ++ [preCol], T. intercalate " \n " $ postCol : postRow)
1885
1886
| otherwise = (x, T. empty)
1886
1887
1887
- -- | Returns [start .. end[
1888
- textInRange :: Range -> T. Text -> T. Text
1889
- textInRange (Range (Position (fromIntegral -> startRow) (fromIntegral -> startCol)) (Position (fromIntegral -> endRow) (fromIntegral -> endCol))) text =
1890
- case compare startRow endRow of
1891
- LT ->
1892
- let (linesInRangeBeforeEndLine, endLineAndFurtherLines) = splitAt (endRow - startRow) linesBeginningWithStartLine
1893
- (textInRangeInFirstLine, linesBetween) = case linesInRangeBeforeEndLine of
1894
- [] -> (" " , [] )
1895
- firstLine: linesInBetween -> (T. drop startCol firstLine, linesInBetween)
1896
- maybeTextInRangeInEndLine = T. take endCol <$> listToMaybe endLineAndFurtherLines
1897
- in T. intercalate " \n " (textInRangeInFirstLine : linesBetween ++ maybeToList maybeTextInRangeInEndLine)
1898
- EQ ->
1899
- let line = fromMaybe " " (listToMaybe linesBeginningWithStartLine)
1900
- in T. take (endCol - startCol) (T. drop startCol line)
1901
- GT -> " "
1902
- where
1903
- linesBeginningWithStartLine = drop startRow (T. splitOn " \n " text)
1904
-
1905
1888
-- | Returns the ranges for a binding in an import declaration
1906
1889
rangesForBindingImport :: ImportDecl GhcPs -> String -> [Range ]
1907
1890
#if MIN_VERSION_ghc(9,5,0)
0 commit comments