Skip to content

Commit 91419bb

Browse files
committed
no head in module name plugin
1 parent bcaaf8b commit 91419bb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

.hlint.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
- Ide.Plugin.CallHierarchy.Internal
103103
- Ide.Plugin.Eval.Code
104104
- Ide.Plugin.Eval.Util
105-
- Ide.Plugin.ModuleName
106105
- Ide.Plugin.Class.ExactPrint
107106
- TExpectedActual
108107
- TRigidType

plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Control.Monad.Trans.Maybe
2525
import Data.Aeson (toJSON)
2626
import Data.Char (isLower, isUpper)
2727
import Data.List (intercalate, minimumBy,
28-
stripPrefix, uncons)
28+
stripPrefix)
2929
import qualified Data.List.NonEmpty as NE
3030
import qualified Data.Map as Map
3131
import Data.Maybe (mapMaybe)
@@ -138,7 +138,7 @@ action recorder state uri = do
138138
-- directories are nested inside each other.
139139
pathModuleNames :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> FilePath -> ExceptT PluginError IO [T.Text]
140140
pathModuleNames recorder state normFilePath filePath
141-
| isLower . head $ takeFileName filePath = return ["Main"]
141+
| firstLetter isLower $ takeFileName filePath = return ["Main"]
142142
| otherwise = do
143143
(session, _) <- runActionE "ModuleName.ghcSession" state $ useWithStaleE GhcSession normFilePath
144144
srcPaths <- liftIO $ evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags
@@ -156,12 +156,16 @@ pathModuleNames recorder state normFilePath filePath
156156
let suffixes = mapMaybe (`stripPrefix` mdlPath) paths
157157
pure (map moduleNameFrom suffixes)
158158
where
159+
firstLetter :: (Char -> Bool) -> FilePath -> Bool
160+
firstLetter _ [] = False
161+
firstLetter pred (c:_) = pred c
162+
159163
moduleNameFrom =
160164
T.pack
161165
. intercalate "."
162166
-- Do not suggest names whose components start from a lower-case char,
163167
-- they are guaranteed to be malformed.
164-
. filter (maybe False (isUpper . fst) . uncons)
168+
. filter (firstLetter isUpper)
165169
. splitDirectories
166170
. dropExtension
167171

0 commit comments

Comments
 (0)