@@ -25,7 +25,7 @@ import Control.Monad.Trans.Maybe
25
25
import Data.Aeson (toJSON )
26
26
import Data.Char (isLower , isUpper )
27
27
import Data.List (intercalate , minimumBy ,
28
- stripPrefix , uncons )
28
+ stripPrefix )
29
29
import qualified Data.List.NonEmpty as NE
30
30
import qualified Data.Map as Map
31
31
import Data.Maybe (mapMaybe )
@@ -138,7 +138,7 @@ action recorder state uri = do
138
138
-- directories are nested inside each other.
139
139
pathModuleNames :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> FilePath -> ExceptT PluginError IO [T. Text ]
140
140
pathModuleNames recorder state normFilePath filePath
141
- | isLower . head $ takeFileName filePath = return [" Main" ]
141
+ | firstLetter isLower $ takeFileName filePath = return [" Main" ]
142
142
| otherwise = do
143
143
(session, _) <- runActionE " ModuleName.ghcSession" state $ useWithStaleE GhcSession normFilePath
144
144
srcPaths <- liftIO $ evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags
@@ -156,12 +156,16 @@ pathModuleNames recorder state normFilePath filePath
156
156
let suffixes = mapMaybe (`stripPrefix` mdlPath) paths
157
157
pure (map moduleNameFrom suffixes)
158
158
where
159
+ firstLetter :: (Char -> Bool ) -> FilePath -> Bool
160
+ firstLetter _ [] = False
161
+ firstLetter pred (c: _) = pred c
162
+
159
163
moduleNameFrom =
160
164
T. pack
161
165
. intercalate " ."
162
166
-- Do not suggest names whose components start from a lower-case char,
163
167
-- they are guaranteed to be malformed.
164
- . filter (maybe False ( isUpper . fst ) . uncons )
168
+ . filter (firstLetter isUpper)
165
169
. splitDirectories
166
170
. dropExtension
167
171
0 commit comments