@@ -72,7 +72,7 @@ import qualified Language.LSP.Server as LSP
72
72
import Language.LSP.Types (ApplyWorkspaceEditParams (.. ),
73
73
CodeAction (.. ),
74
74
CodeActionContext (CodeActionContext , _diagnostics ),
75
- CodeActionKind (CodeActionQuickFix , CodeActionUnknown ),
75
+ CodeActionKind (CodeActionQuickFix ),
76
76
CodeActionParams (CodeActionParams ),
77
77
Command ,
78
78
Diagnostic (.. ),
@@ -102,6 +102,7 @@ import GHC (AddEpAnn (Ad
102
102
EpaLocation (.. ),
103
103
LEpaComment ,
104
104
LocatedA )
105
+ import Development.IDE.Plugin.Plugins.ImportUtils
105
106
#else
106
107
import Language.Haskell.GHC.ExactPrint.Types (Annotation (annsDP ),
107
108
DeltaPos ,
@@ -2054,71 +2055,3 @@ matchRegExMultipleImports message = do
2054
2055
imps <- regExImports imports
2055
2056
return (binding, imps)
2056
2057
2057
- -- | Possible import styles for an 'IdentInfo'.
2058
- --
2059
- -- The first 'Text' parameter corresponds to the 'rendered' field of the
2060
- -- 'IdentInfo'.
2061
- data ImportStyle
2062
- = ImportTopLevel T. Text
2063
- -- ^ Import a top-level export from a module, e.g., a function, a type, a
2064
- -- class.
2065
- --
2066
- -- > import M (?)
2067
- --
2068
- -- Some exports that have a parent, like a type-class method or an
2069
- -- associated type/data family, can still be imported as a top-level
2070
- -- import.
2071
- --
2072
- -- Note that this is not the case for constructors, they must always be
2073
- -- imported as part of their parent data type.
2074
-
2075
- | ImportViaParent T. Text T. Text
2076
- -- ^ Import an export (first parameter) through its parent (second
2077
- -- parameter).
2078
- --
2079
- -- import M (P(?))
2080
- --
2081
- -- @P@ and @?@ can be a data type and a constructor, a class and a method,
2082
- -- a class and an associated type/data family, etc.
2083
-
2084
- | ImportAllConstructors T. Text
2085
- -- ^ Import all constructors for a specific data type.
2086
- --
2087
- -- import M (P(..))
2088
- --
2089
- -- @P@ can be a data type or a class.
2090
- deriving Show
2091
-
2092
- importStyles :: IdentInfo -> NonEmpty ImportStyle
2093
- importStyles IdentInfo {parent, rendered, isDatacon}
2094
- | Just p <- parent
2095
- -- Constructors always have to be imported via their parent data type, but
2096
- -- methods and associated type/data families can also be imported as
2097
- -- top-level exports.
2098
- = ImportViaParent rendered p
2099
- :| [ImportTopLevel rendered | not isDatacon]
2100
- <> [ImportAllConstructors p]
2101
- | otherwise
2102
- = ImportTopLevel rendered :| []
2103
-
2104
- -- | Used for adding new imports
2105
- renderImportStyle :: ImportStyle -> T. Text
2106
- renderImportStyle (ImportTopLevel x) = x
2107
- renderImportStyle (ImportViaParent x p@ (T. uncons -> Just (' (' , _))) = " type " <> p <> " (" <> x <> " )"
2108
- renderImportStyle (ImportViaParent x p) = p <> " (" <> x <> " )"
2109
- renderImportStyle (ImportAllConstructors p) = p <> " (..)"
2110
-
2111
- -- | Used for extending import lists
2112
- unImportStyle :: ImportStyle -> (Maybe String , String )
2113
- unImportStyle (ImportTopLevel x) = (Nothing , T. unpack x)
2114
- unImportStyle (ImportViaParent x y) = (Just $ T. unpack y, T. unpack x)
2115
- unImportStyle (ImportAllConstructors x) = (Just $ T. unpack x, wildCardSymbol)
2116
-
2117
-
2118
- quickFixImportKind' :: T. Text -> ImportStyle -> CodeActionKind
2119
- quickFixImportKind' x (ImportTopLevel _) = CodeActionUnknown $ " quickfix.import." <> x <> " .list.topLevel"
2120
- quickFixImportKind' x (ImportViaParent _ _) = CodeActionUnknown $ " quickfix.import." <> x <> " .list.withParent"
2121
- quickFixImportKind' x (ImportAllConstructors _) = CodeActionUnknown $ " quickfix.import." <> x <> " .list.allConstructors"
2122
-
2123
- quickFixImportKind :: T. Text -> CodeActionKind
2124
- quickFixImportKind x = CodeActionUnknown $ " quickfix.import." <> x
0 commit comments