Skip to content

Commit a7ce386

Browse files
author
kokobd
committed
remove a use of partial function
1 parent bd7fcfd commit a7ce386

File tree

1 file changed

+11
-10
lines changed
  • plugins/hls-selection-range-plugin/src/Ide/Plugin/SelectionRange

1 file changed

+11
-10
lines changed

plugins/hls-selection-range-plugin/src/Ide/Plugin/SelectionRange/ASTPreProcess.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ module Ide.Plugin.SelectionRange.ASTPreProcess
77
) where
88

99
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
1214
import qualified Data.Map.Strict as Map
1315
import Data.Maybe (mapMaybe)
1416
import qualified Data.Set as Set
@@ -61,19 +63,18 @@ mergeImports node = pure $ node { nodeChildren = children }
6163
. nodeChildren $ node
6264

6365
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)
6769

6870
nodeIsImport :: HieAST a -> Bool
6971
nodeIsImport = isAnnotationInAstNode ("ImportDecl", "ImportDecl")
7072

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)
7475
where
7576
span' :: RealSrcSpan
76-
span' = foldl1' combineRealSrcSpans . fmap nodeSpan $ children
77+
span' = foldl1 combineRealSrcSpans . fmap nodeSpan $ children
7778

7879
{-|
7980
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
107108
-- Does that identifier appear in the second AST node as a definition? If so, we combines the two nodes.
108109
refs <- Map.lookup typeSigId refMap
109110
if any (isIdentADef (nodeSpan n2)) refs
110-
then createVirtualNode [n1, n2]
111+
then pure . createVirtualNode $ n1 NonEmpty.:| [n2]
111112
else Nothing
112113
where
113114
checkAnnotation :: Maybe ()

0 commit comments

Comments
 (0)