@@ -7,8 +7,10 @@ module Ide.Plugin.SelectionRange.ASTPreProcess
7
7
) where
8
8
9
9
import Control.Monad.Reader (Reader , asks )
10
- import Data.Foldable (find , foldl' )
11
- import Data.List (foldl1' , groupBy )
10
+ import Data.Foldable (find , foldl' , foldl1 )
11
+ import Data.List (groupBy )
12
+ import Data.List.NonEmpty (NonEmpty )
13
+ import qualified Data.List.NonEmpty as NonEmpty
12
14
import qualified Data.Map.Strict as Map
13
15
import Data.Maybe (mapMaybe )
14
16
import qualified Data.Set as Set
@@ -61,19 +63,18 @@ mergeImports node = pure $ node { nodeChildren = children }
61
63
. nodeChildren $ node
62
64
63
65
merge :: [HieAST a ] -> Maybe (HieAST a )
64
- merge [] = Nothing
65
- merge [x] = Just x
66
- merge xs = createVirtualNode xs
66
+ merge [] = Nothing
67
+ merge [x] = Just x
68
+ merge (x : xs) = Just $ createVirtualNode (x NonEmpty. :| xs)
67
69
68
70
nodeIsImport :: HieAST a -> Bool
69
71
nodeIsImport = isAnnotationInAstNode (" ImportDecl" , " ImportDecl" )
70
72
71
- createVirtualNode :: [HieAST a ] -> Maybe (HieAST a )
72
- createVirtualNode [] = Nothing
73
- createVirtualNode children = Just $ mkAstNode (NodeInfo mempty mempty mempty ) span' children
73
+ createVirtualNode :: NonEmpty (HieAST a ) -> HieAST a
74
+ createVirtualNode children = mkAstNode (NodeInfo mempty mempty mempty ) span' (NonEmpty. toList children)
74
75
where
75
76
span' :: RealSrcSpan
76
- span' = foldl1' combineRealSrcSpans . fmap nodeSpan $ children
77
+ span' = foldl1 combineRealSrcSpans . fmap nodeSpan $ children
77
78
78
79
{-|
79
80
Combine type signature with variable definition under a new parent node, if the signature is placed right before the
@@ -107,7 +108,7 @@ mergeAdjacentSigDef refMap (n1, n2) = do
107
108
-- Does that identifier appear in the second AST node as a definition? If so, we combines the two nodes.
108
109
refs <- Map. lookup typeSigId refMap
109
110
if any (isIdentADef (nodeSpan n2)) refs
110
- then createVirtualNode [n1, n2]
111
+ then pure . createVirtualNode $ n1 NonEmpty. :| [ n2]
111
112
else Nothing
112
113
where
113
114
checkAnnotation :: Maybe ()
0 commit comments