Skip to content

Commit 3c2364b

Browse files
Solve crash with module name plugin under certain circumstances (#2518)
* use foldl' instead of foldl1 since there is monoid anyway * avoid unsafe minimumBy Co-authored-by: Anton Latukha <[email protected]>
1 parent 82b91ac commit 3c2364b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Data.Aeson (Value (Null), toJSON)
2222
import Data.Char (isLower)
2323
import qualified Data.HashMap.Strict as HashMap
2424
import Data.List (intercalate, isPrefixOf, minimumBy)
25+
import qualified Data.List.NonEmpty as NE
2526
import Data.Maybe (maybeToList)
2627
import Data.Ord (comparing)
2728
import Data.String (IsString)
@@ -99,7 +100,7 @@ action state uri =
99100
let emptyModule = maybe True (T.null . T.strip . virtualFileText) contents
100101

101102
correctNames <- liftIO $ traceAs "correctNames" <$> pathModuleNames state nfp fp
102-
let bestName = minimumBy (comparing T.length) correctNames
103+
bestName <- minimumBy (comparing T.length) <$> (MaybeT . pure $ NE.nonEmpty correctNames)
103104

104105
statedNameMaybe <- liftIO $ traceAs "statedName" <$> codeModuleName state nfp
105106
case statedNameMaybe of

plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ renameProvider state pluginId (RenameParams (TextDocumentIdentifier uri) pos _pr
4848
getFileEdits = ap (getSrcEdits state . renameModRefs newNameText) (locToUri . head)
4949

5050
fileEdits <- mapM getFileEdits filesRefs
51-
pure $ foldl1 (<>) fileEdits
51+
pure $ foldl' (<>) mempty fileEdits
5252

5353
-------------------------------------------------------------------------------
5454
-- Source renaming

0 commit comments

Comments
 (0)