Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Set.member instead of Foldable.elem #4128

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,14 @@
-- 'TargetFile Foo.hs' in the 'knownTargetsVar', thus not find 'TargetFile Foo.hs-boot'
-- and also not find 'TargetModule Foo'.
fs <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
pure $ map (\fp -> (TargetFile fp, [fp])) (nubOrd (f:fs))
pure $ map (\fp -> (TargetFile fp, Set.singleton fp)) (nubOrd (f:fs))
TargetModule _ -> do
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
return [(targetTarget, found)]
return [(targetTarget, Set.fromList found)]
hasUpdate <- join $ atomically $ do
known <- readTVar knownTargetsVar
let known' = flip mapHashed known $ \k ->
HM.unionWith (<>) k $ HM.fromList $ map (second Set.fromList) knownTargets
HM.unionWith (<>) k $ HM.fromList knownTargets
hasUpdate = if known /= known' then Just (unhashed known') else Nothing
writeTVar knownTargetsVar known'
logDirtyKeys <- recordDirtyKeys extras GetKnownTargets [emptyFilePath]
Expand Down Expand Up @@ -655,7 +655,7 @@
InstallationMismatch{..} ->
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
InstallationChecked _compileTime _ghcLibCheck -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))

Check warning on line 658 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef' cradle_files (\\ xs -> (cfp : xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ cradle_files ((:) cfp)"
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
-- Failure case, either a cradle error or the none cradle
Left err -> do
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ setupLSP recorder getHieDbLoc userHandlers getIdeState clientMsgVar = do
-- We want to avoid that the list of cancelled requests
-- keeps growing if we receive cancellations for requests
-- that do not exist or have already been processed.
when (reqId `elem` queued) $
when (reqId `Set.member` queued) $
modifyTVar cancelledRequests (Set.insert reqId)
let clearReqId reqId = atomically $ do
modifyTVar pendingRequests (Set.delete reqId)
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Types/Exports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ identInfoToKeyVal identInfo =

buildModuleExportMap:: [(ModuleName, HashSet IdentInfo)] -> ModuleNameEnv (HashSet IdentInfo)
buildModuleExportMap exportsMap = do
let lst = concatMap (Set.toList. snd) exportsMap
let lst = concatMap (Set.toList . snd) exportsMap
let lstThree = map identInfoToKeyVal lst
sortAndGroup lstThree

Expand All @@ -223,4 +223,4 @@ extractModuleExports modIFace = do
(modName, functionSet)

sortAndGroup :: [(ModuleName, IdentInfo)] -> ModuleNameEnv (HashSet IdentInfo)
sortAndGroup assocs = listToUFM_C (<>) [(k, Set.fromList [v]) | (k, v) <- assocs]
sortAndGroup assocs = listToUFM_C (<>) [(k, Set.singleton v) | (k, v) <- assocs]
2 changes: 1 addition & 1 deletion ghcide/test/src/Development/IDE/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ expectCurrentDiagnostics doc expected = do

checkDiagnosticsForDoc :: HasCallStack => TextDocumentIdentifier -> [(DiagnosticSeverity, Cursor, T.Text)] -> [Diagnostic] -> Session ()
checkDiagnosticsForDoc TextDocumentIdentifier {_uri} expected obtained = do
let expected' = Map.fromList [(nuri, map (\(ds, c, t) -> (ds, c, t, Nothing)) expected)]
let expected' = Map.singleton nuri (map (\(ds, c, t) -> (ds, c, t, Nothing)) expected)
nuri = toNormalizedUri _uri
expectDiagnosticsWithTags' (return (_uri, obtained)) expected'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ codeActionHandler state pId (CodeActionParams _ _ docId currRange _) = do
mkWorkspaceEdit :: NormalizedFilePath -> [TextEdit] -> WorkspaceEdit
mkWorkspaceEdit nfp edits = WorkspaceEdit changes Nothing Nothing
where
changes = Just $ Map.fromList [(filePathToUri $ fromNormalizedFilePath nfp, edits)]
changes = Just $ Map.singleton (filePathToUri $ fromNormalizedFilePath nfp) edits

mkCodeActionTitle :: Literal -> AlternateFormat -> [GhcExtension] -> Text
mkCodeActionTitle lit (alt, ext) ghcExts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ isIdentADef outerSpan (span, detail) =
&& isDef
where
isDef :: Bool
isDef = any isContextInfoDef . toList . identInfo $ detail
isDef = any isContextInfoDef $ identInfo detail

-- Determines if the 'ContextInfo' represents a variable/function definition
isContextInfoDef :: ContextInfo -> Bool
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ runEvalCmd plId st mtoken EvalParams{..} =
evalGhcEnv final_hscEnv $ do
runTests evalCfg (st, fp) tests

let workspaceEditsMap = Map.fromList [(_uri, addFinalReturn mdlText edits)]
let workspaceEditsMap = Map.singleton _uri (addFinalReturn mdlText edits)
let workspaceEdits = WorkspaceEdit (Just workspaceEditsMap) Nothing Nothing

return workspaceEdits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ resolveWTextEdit ideState (RefineAll uri) = do
pure $ mkWorkspaceEdit uri edits pm
mkWorkspaceEdit :: Uri -> [ImportEdit] -> PositionMapping -> WorkspaceEdit
mkWorkspaceEdit uri edits pm =
WorkspaceEdit {_changes = Just $ Map.fromList [(uri, mapMaybe toWEdit edits)]
WorkspaceEdit {_changes = Just $ Map.singleton uri (mapMaybe toWEdit edits)
, _documentChanges = Nothing
, _changeAnnotations = Nothing}
where toWEdit ImportEdit{ieRange, ieText} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Data.List (sortOn)
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe, isJust, mapMaybe)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import Development.IDE (spanContainsRange)
Expand Down Expand Up @@ -164,7 +165,7 @@ refMapToUsedIdentifiers = DList.toList . Map.foldlWithKey' folder DList.empty
getUsedIdentifier identifier span IdentifierDetails {..}
| Just identifierSpan <- realSrcSpanToIdentifierSpan span
, Right name <- identifier
, Use `elem` identInfo = Just $ UsedIdentifier name identifierSpan
, Use `Set.member` identInfo = Just $ UsedIdentifier name identifierSpan
| otherwise = Nothing

updateColOffset :: Int -> Int -> Int -> Int
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-retrie-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ codeActionTitle _ = Nothing

goldenWithRetrie :: TestName -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
goldenWithRetrie title path act =
goldenWithHaskellDoc (def { plugins = M.fromList [("retrie", def)] }) testPlugins title testDataDir path "expected" "hs" act
goldenWithHaskellDoc (def { plugins = M.singleton "retrie" def }) testPlugins title testDataDir path "expected" "hs" act

runWithRetrie :: Session a -> IO a
runWithRetrie = runSessionWithServer def testPlugins testDataDir
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ rules recorder plId = do
FiascoL es -> do
logWith recorder Development.IDE.Warning (LogWarnConf es)
-- If we can't read the config file, default to using all inspections:
let allInspections = HM.fromList [(relativeHsFilePath, inspectionsIds)]
let allInspections = HM.singleton relativeHsFilePath inspectionsIds
pure (allInspections, [])
ResultL _warnings stanConfig -> do
-- HashMap of *relative* file paths to info about enabled checks for those file paths.
Expand Down
Loading