Skip to content

Commit 5245e94

Browse files
authored
Merge branch 'master' into tests
2 parents b1b11e6 + 2b94f85 commit 5245e94

File tree

20 files changed

+360
-196
lines changed

20 files changed

+360
-196
lines changed

.github/workflows/nix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
extra_nix_config: |
6363
experimental-features = nix-command flakes
6464
nix_path: nixpkgs=channel:nixos-unstable
65-
- uses: cachix/cachix-action@v11
65+
- uses: cachix/cachix-action@v12
6666
with:
6767
name: haskell-language-server
6868
# Disable pushing, we will do that in job `build`
@@ -96,7 +96,7 @@ jobs:
9696
extra_nix_config: |
9797
experimental-features = nix-command flakes
9898
nix_path: nixpkgs=channel:nixos-unstable
99-
- uses: cachix/cachix-action@v11
99+
- uses: cachix/cachix-action@v12
100100
with:
101101
name: haskell-language-server
102102
authToken: ${{ secrets.HLS_CACHIX_AUTH_TOKEN }}

.hlint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
- Development.IDE.Graph.Internal.Database
6060
- Development.IDE.Graph.Internal.Paths
6161
- Development.IDE.Graph.Internal.Profile
62+
- Development.IDE.Graph.Internal.Types
6263
- Ide.Types
6364
- Test.Hls
6465
- Test.Hls.Command

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ library
6262
focus,
6363
ghc-trace-events,
6464
Glob,
65-
haddock-library >= 1.8 && < 1.11,
65+
haddock-library >= 1.8 && < 1.12,
6666
hashable,
6767
hie-compat ^>= 0.3.0.0,
6868
hls-plugin-api ^>= 1.5,

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import qualified Development.IDE.Types.Logger as L
5555

5656
import qualified Data.Binary as B
5757
import qualified Data.ByteString.Lazy as LBS
58-
import qualified Data.HashSet as HSet
5958
import Data.List (foldl')
6059
import qualified Data.Text as Text
6160
import Development.IDE.Core.IdeConfiguration (isWorkspaceFile)
@@ -256,7 +255,7 @@ setSomethingModified vfs state keys reason = do
256255
atomically $ do
257256
writeTQueue (indexQueue $ hiedbWriter $ shakeExtras state) (\withHieDb -> withHieDb deleteMissingRealFiles)
258257
modifyTVar' (dirtyKeys $ shakeExtras state) $ \x ->
259-
foldl' (flip HSet.insert) x keys
258+
foldl' (flip insertKeySet) x keys
260259
void $ restartShakeSession (shakeExtras state) vfs reason []
261260

262261
registerFileWatches :: [String] -> LSP.LspT Config IO Bool

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ import System.Time.Extra
178178
data Log
179179
= LogCreateHieDbExportsMapStart
180180
| LogCreateHieDbExportsMapFinish !Int
181-
| LogBuildSessionRestart !String ![DelayedActionInternal] !(HashSet Key) !Seconds !(Maybe FilePath)
181+
| LogBuildSessionRestart !String ![DelayedActionInternal] !(KeySet) !Seconds !(Maybe FilePath)
182182
| LogBuildSessionRestartTakingTooLong !Seconds
183183
| LogDelayedAction !(DelayedAction ()) !Seconds
184184
| LogBuildSessionFinish !(Maybe SomeException)
@@ -197,7 +197,7 @@ instance Pretty Log where
197197
vcat
198198
[ "Restarting build session due to" <+> pretty reason
199199
, "Action Queue:" <+> pretty (map actionName actionQueue)
200-
, "Keys:" <+> pretty (map show $ HSet.toList keyBackLog)
200+
, "Keys:" <+> pretty (map show $ toListKeySet keyBackLog)
201201
, "Aborting previous build session took" <+> pretty (showDuration abortDuration) <+> pretty shakeProfilePath ]
202202
LogBuildSessionRestartTakingTooLong seconds ->
203203
"Build restart is taking too long (" <> pretty seconds <> " seconds)"
@@ -279,7 +279,7 @@ data ShakeExtras = ShakeExtras
279279
,clientCapabilities :: ClientCapabilities
280280
, withHieDb :: WithHieDb -- ^ Use only to read.
281281
, hiedbWriter :: HieDbWriter -- ^ use to write
282-
, persistentKeys :: TVar (HMap.HashMap Key GetStalePersistent)
282+
, persistentKeys :: TVar (KeyMap GetStalePersistent)
283283
-- ^ Registery for functions that compute/get "stale" results for the rule
284284
-- (possibly from disk)
285285
, vfsVar :: TVar VFS
@@ -290,7 +290,7 @@ data ShakeExtras = ShakeExtras
290290
-- We don't need a STM.Map because we never update individual keys ourselves.
291291
, defaultConfig :: Config
292292
-- ^ Default HLS config, only relevant if the client does not provide any Config
293-
, dirtyKeys :: TVar (HashSet Key)
293+
, dirtyKeys :: TVar KeySet
294294
-- ^ Set of dirty rule keys since the last Shake run
295295
}
296296

@@ -324,7 +324,7 @@ getPluginConfig plugin = do
324324
addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v,PositionDelta,TextDocumentVersion))) -> Rules ()
325325
addPersistentRule k getVal = do
326326
ShakeExtras{persistentKeys} <- getShakeExtrasRules
327-
void $ liftIO $ atomically $ modifyTVar' persistentKeys $ HMap.insert (Key k) (fmap (fmap (first3 toDyn)) . getVal)
327+
void $ liftIO $ atomically $ modifyTVar' persistentKeys $ insertKeyMap (newKey k) (fmap (fmap (first3 toDyn)) . getVal)
328328

329329
class Typeable a => IsIdeGlobal a where
330330

@@ -399,7 +399,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
399399
pmap <- readTVarIO persistentKeys
400400
mv <- runMaybeT $ do
401401
liftIO $ Logger.logDebug (logger s) $ T.pack $ "LOOKUP PERSISTENT FOR: " ++ show k
402-
f <- MaybeT $ pure $ HMap.lookup (Key k) pmap
402+
f <- MaybeT $ pure $ lookupKeyMap (newKey k) pmap
403403
(dv,del,ver) <- MaybeT $ runIdeAction "lastValueIO" s $ f file
404404
MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
405405
case mv of
@@ -509,7 +509,7 @@ deleteValue
509509
-> STM ()
510510
deleteValue ShakeExtras{dirtyKeys, state} key file = do
511511
STM.delete (toKey key file) state
512-
modifyTVar' dirtyKeys $ HSet.insert (toKey key file)
512+
modifyTVar' dirtyKeys $ insertKeySet (toKey key file)
513513

514514
recordDirtyKeys
515515
:: Shake.ShakeValue k
@@ -518,7 +518,7 @@ recordDirtyKeys
518518
-> [NormalizedFilePath]
519519
-> STM (IO ())
520520
recordDirtyKeys ShakeExtras{dirtyKeys} key file = do
521-
modifyTVar' dirtyKeys $ \x -> foldl' (flip HSet.insert) x (toKey key <$> file)
521+
modifyTVar' dirtyKeys $ \x -> foldl' (flip insertKeySet) x (toKey key <$> file)
522522
return $ withEventTrace "recordDirtyKeys" $ \addEvent -> do
523523
addEvent (fromString $ unlines $ "dirty " <> show key : map fromNormalizedFilePath file)
524524

@@ -594,7 +594,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
594594
positionMapping <- STM.newIO
595595
knownTargetsVar <- newTVarIO $ hashed HMap.empty
596596
let restartShakeSession = shakeRestart recorder ideState
597-
persistentKeys <- newTVarIO HMap.empty
597+
persistentKeys <- newTVarIO mempty
598598
indexPending <- newTVarIO HMap.empty
599599
indexCompleted <- newTVarIO 0
600600
indexProgressToken <- newVar Nothing
@@ -637,7 +637,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
637637

638638
-- monitoring
639639
let readValuesCounter = fromIntegral . countRelevantKeys checkParents <$> getStateKeys shakeExtras
640-
readDirtyKeys = fromIntegral . countRelevantKeys checkParents . HSet.toList <$> readTVarIO(dirtyKeys shakeExtras)
640+
readDirtyKeys = fromIntegral . countRelevantKeys checkParents . toListKeySet <$> readTVarIO(dirtyKeys shakeExtras)
641641
readIndexPending = fromIntegral . HMap.size <$> readTVarIO (indexPending $ hiedbWriter shakeExtras)
642642
readExportsMap = fromIntegral . HMap.size . getExportsMap <$> readTVarIO (exportsMap shakeExtras)
643643
readDatabaseCount = fromIntegral . countRelevantKeys checkParents . map fst <$> shakeGetDatabaseKeys shakeDb
@@ -797,10 +797,10 @@ newSession recorder extras@ShakeExtras{..} vfsMod shakeDb acts reason = do
797797
workRun restore = withSpan "Shake session" $ \otSpan -> do
798798
setTag otSpan "reason" (fromString reason)
799799
setTag otSpan "queue" (fromString $ unlines $ map actionName reenqueued)
800-
whenJust allPendingKeys $ \kk -> setTag otSpan "keys" (BS8.pack $ unlines $ map show $ toList kk)
800+
whenJust allPendingKeys $ \kk -> setTag otSpan "keys" (BS8.pack $ unlines $ map show $ toListKeySet kk)
801801
let keysActs = pumpActionThread otSpan : map (run otSpan) (reenqueued ++ acts)
802802
res <- try @SomeException $
803-
restore $ shakeRunDatabaseForKeys (HSet.toList <$> allPendingKeys) shakeDb keysActs
803+
restore $ shakeRunDatabaseForKeys (toListKeySet <$> allPendingKeys) shakeDb keysActs
804804
return $ do
805805
let exception =
806806
case res of
@@ -890,7 +890,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
890890
= atomicallyNamed "GC" $ do
891891
gotIt <- STM.focus (Focus.member <* Focus.delete) k values
892892
when gotIt $
893-
modifyTVar' dk (HSet.insert k)
893+
modifyTVar' dk (insertKeySet k)
894894
return $ if gotIt then (counter+1, k:keys) else st
895895
| otherwise = pure st
896896

@@ -1068,7 +1068,7 @@ defineEarlyCutoff recorder (Rule op) = addRule $ \(Q (key, file)) (old :: Maybe
10681068
extras <- getShakeExtras
10691069
let diagnostics ver diags = do
10701070
traceDiagnostics diags
1071-
updateFileDiagnostics recorder file ver (Key key) extras . map (\(_,y,z) -> (y,z)) $ diags
1071+
updateFileDiagnostics recorder file ver (newKey key) extras . map (\(_,y,z) -> (y,z)) $ diags
10721072
defineEarlyCutoff' diagnostics (==) key file old mode $ const $ op key file
10731073
defineEarlyCutoff recorder (RuleNoDiagnostics op) = addRule $ \(Q (key, file)) (old :: Maybe BS.ByteString) mode -> otTracedAction key file mode traceA $ \traceDiagnostics -> do
10741074
let diagnostics _ver diags = do
@@ -1087,7 +1087,7 @@ defineEarlyCutoff recorder (RuleWithOldValue op) = addRule $ \(Q (key, file)) (o
10871087
extras <- getShakeExtras
10881088
let diagnostics ver diags = do
10891089
traceDiagnostics diags
1090-
updateFileDiagnostics recorder file ver (Key key) extras . map (\(_,y,z) -> (y,z)) $ diags
1090+
updateFileDiagnostics recorder file ver (newKey key) extras . map (\(_,y,z) -> (y,z)) $ diags
10911091
defineEarlyCutoff' diagnostics (==) key file old mode $ op key file
10921092

10931093
defineNoFile :: IdeRule k v => Recorder (WithPriority Log) -> (k -> Action v) -> Rules ()
@@ -1160,7 +1160,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
11601160
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff)
11611161
(encodeShakeValue bs) $
11621162
A res
1163-
liftIO $ atomicallyNamed "define - dirtyKeys" $ modifyTVar' dirtyKeys (HSet.delete $ toKey key file)
1163+
liftIO $ atomicallyNamed "define - dirtyKeys" $ modifyTVar' dirtyKeys (deleteKeySet $ toKey key file)
11641164
return res
11651165
where
11661166
-- Highly unsafe helper to compute the version of a file
@@ -1199,15 +1199,16 @@ updateFileDiagnostics :: MonadIO m
11991199
-> ShakeExtras
12001200
-> [(ShowDiagnostic,Diagnostic)] -- ^ current results
12011201
-> m ()
1202-
updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv} current =
1202+
updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 =
12031203
liftIO $ withTrace ("update diagnostics " <> fromString(fromNormalizedFilePath fp)) $ \ addTag -> do
12041204
addTag "key" (show k)
12051205
let (currentShown, currentHidden) = partition ((== ShowDiag) . fst) current
12061206
uri = filePathToUri' fp
12071207
addTagUnsafe :: String -> String -> String -> a -> a
12081208
addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v
12091209
update :: (forall a. String -> String -> a -> a) -> [Diagnostic] -> STMDiagnosticStore -> STM [Diagnostic]
1210-
update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (T.pack $ show k) new store
1210+
update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (renderKey k) new store
1211+
current = second diagsFromRule <$> current0
12111212
addTag "version" (show ver)
12121213
mask_ $ do
12131214
-- Mask async exceptions to ensure that updated diagnostics are always
@@ -1230,6 +1231,22 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
12301231
LSP.sendNotification LSP.STextDocumentPublishDiagnostics $
12311232
LSP.PublishDiagnosticsParams (fromNormalizedUri uri) (fmap fromIntegral ver) (List newDiags)
12321233
return action
1234+
where
1235+
diagsFromRule :: Diagnostic -> Diagnostic
1236+
diagsFromRule c@Diagnostic{_range}
1237+
| coerce ideTesting = c
1238+
{_relatedInformation =
1239+
Just $ List [
1240+
DiagnosticRelatedInformation
1241+
(Location
1242+
(filePathToUri $ fromNormalizedFilePath fp)
1243+
_range
1244+
)
1245+
(T.pack $ show k)
1246+
]
1247+
}
1248+
| otherwise = c
1249+
12331250

12341251
newtype Priority = Priority Double
12351252

ghcide/src/Development/IDE/Spans/Common.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import GHC.Generics
2323

2424
import GHC
2525

26+
import Data.Bifunctor (second)
2627
import Development.IDE.GHC.Compat
2728
import Development.IDE.GHC.Orphans ()
2829
import Development.IDE.GHC.Util
@@ -179,8 +180,12 @@ haddockToMarkdown (H.DocHeader (H.Header level title))
179180

180181
haddockToMarkdown (H.DocUnorderedList things)
181182
= '\n' : (unlines $ map (("+ " ++) . trimStart . splitForList . haddockToMarkdown) things)
182-
haddockToMarkdown (H.DocOrderedList things)
183-
= '\n' : (unlines $ map (("1. " ++) . trimStart . splitForList . haddockToMarkdown) things)
183+
haddockToMarkdown (H.DocOrderedList things) =
184+
#if MIN_VERSION_haddock_library(1,11,0)
185+
'\n' : (unlines $ map ((\(num, str) -> show num ++ ". " ++ str) . second (trimStart . splitForList . haddockToMarkdown)) things)
186+
#else
187+
'\n' : (unlines $ map (("1. " ++) . trimStart . splitForList . haddockToMarkdown) things)
188+
#endif
184189
haddockToMarkdown (H.DocDefList things)
185190
= '\n' : (unlines $ map (\(term, defn) -> "+ **" ++ haddockToMarkdown term ++ "**: " ++ haddockToMarkdown defn) things)
186191

ghcide/src/Development/IDE/Types/Shake.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Data.Typeable (cast)
2626
import Data.Vector (Vector)
2727
import Development.IDE.Core.PositionMapping
2828
import Development.IDE.Core.RuleTypes (FileVersion)
29-
import Development.IDE.Graph (Key (..), RuleResult)
29+
import Development.IDE.Graph (Key (..), RuleResult, newKey)
3030
import qualified Development.IDE.Graph as Shake
3131
import Development.IDE.Types.Diagnostics
3232
import Development.IDE.Types.Location
@@ -75,7 +75,7 @@ isBadDependency x
7575
| otherwise = False
7676

7777
toKey :: Shake.ShakeValue k => k -> NormalizedFilePath -> Key
78-
toKey = (Key.) . curry Q
78+
toKey = (newKey.) . curry Q
7979

8080
fromKey :: Typeable k => Key -> Maybe (k, NormalizedFilePath)
8181
fromKey (Key k)
@@ -91,7 +91,7 @@ fromKeyType (Key k) = case typeOf k of
9191
_ -> Nothing
9292

9393
toNoFileKey :: (Show k, Typeable k, Eq k, Hashable k) => k -> Key
94-
toNoFileKey k = Key $ Q (k, emptyFilePath)
94+
toNoFileKey k = newKey $ Q (k, emptyFilePath)
9595

9696
newtype Q k = Q (k, NormalizedFilePath)
9797
deriving newtype (Eq, Hashable, NFData)

ghcide/test/exe/Main.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,34 @@ haddockTests
23932393
, ""
23942394
]
23952395
)
2396+
, testCase "ordered list" $ checkHaddock
2397+
(unlines
2398+
[ "may require"
2399+
, "different precautions:"
2400+
, ""
2401+
, " 1. Use @{\\-\\# NOINLINE foo \\#-\\}@ as a pragma on any function @foo@"
2402+
, " that calls 'unsafePerformIO'. If the call is inlined,"
2403+
, " the I\\/O may be performed more than once."
2404+
, ""
2405+
, " 2. Use the compiler flag @-fno-cse@ to prevent common sub-expression"
2406+
, " elimination being performed on the module."
2407+
, ""
2408+
]
2409+
)
2410+
(unlines
2411+
[ ""
2412+
, ""
2413+
, "may require"
2414+
, "different precautions: "
2415+
, "1. Use `{-# NOINLINE foo #-}` as a pragma on any function `foo` "
2416+
, " that calls `unsafePerformIO` . If the call is inlined,"
2417+
, " the I/O may be performed more than once."
2418+
, ""
2419+
, "2. Use the compiler flag `-fno-cse` to prevent common sub-expression"
2420+
, " elimination being performed on the module."
2421+
, ""
2422+
]
2423+
)
23962424
]
23972425
where
23982426
checkHaddock s txt = spanDocToMarkdownForTest s @?= txt

hls-graph/hls-graph.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ library
4747
Development.IDE.Graph.Classes
4848
Development.IDE.Graph.Database
4949
Development.IDE.Graph.Rule
50+
Development.IDE.Graph.KeyMap
51+
Development.IDE.Graph.KeySet
5052
Development.IDE.Graph.Internal.Action
5153
Development.IDE.Graph.Internal.Options
5254
Development.IDE.Graph.Internal.Rules
@@ -82,6 +84,7 @@ library
8284
, transformers
8385
, unliftio
8486
, unordered-containers
87+
, text
8588

8689
if flag(embed-files)
8790
cpp-options: -DFILE_EMBED

hls-graph/src/Development/IDE/Graph.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
{-# LANGUAGE PatternSynonyms #-}
12
module Development.IDE.Graph(
2-
shakeOptions,
3+
shakeOptions,
34
Rules,
45
Action, action,
5-
Key(..),
6+
Key(.., Key),
7+
newKey, renderKey,
68
actionFinally, actionBracket, actionCatch, actionFork,
79
-- * Configuration
810
ShakeOptions(shakeAllowRedefineRules, shakeExtra),
@@ -18,9 +20,13 @@ module Development.IDE.Graph(
1820
-- * Actions for inspecting the keys in the database
1921
getDirtySet,
2022
getKeysAndVisitedAge,
23+
module Development.IDE.Graph.KeyMap,
24+
module Development.IDE.Graph.KeySet,
2125
) where
2226

2327
import Development.IDE.Graph.Database
28+
import Development.IDE.Graph.KeyMap
29+
import Development.IDE.Graph.KeySet
2430
import Development.IDE.Graph.Internal.Action
2531
import Development.IDE.Graph.Internal.Options
2632
import Development.IDE.Graph.Internal.Rules

hls-graph/src/Development/IDE/Graph/Database.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ shakeGetBuildEdges :: ShakeDatabase -> IO Int
7979
shakeGetBuildEdges (ShakeDatabase _ _ db) = do
8080
keys <- getDatabaseValues db
8181
let ress = mapMaybe (getResult . snd) keys
82-
return $ sum $ map (length . getResultDepsDefault [] . resultDeps) ress
82+
return $ sum $ map (lengthKeySet . getResultDepsDefault mempty . resultDeps) ress
8383

8484
-- | Returns an approximation of the database keys,
8585
-- annotated with how long ago (in # builds) they were visited

hls-graph/src/Development/IDE/Graph/Internal/Action.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ShakeValue a = (Show a, Typeable a, Eq a, Hashable a, NFData a)
3939
alwaysRerun :: Action ()
4040
alwaysRerun = do
4141
ref <- Action $ asks actionDeps
42-
liftIO $ modifyIORef ref (AlwaysRerunDeps [] <>)
42+
liftIO $ modifyIORef ref (AlwaysRerunDeps mempty <>)
4343

4444
-- No-op for now
4545
reschedule :: Double -> Action ()
@@ -121,7 +121,7 @@ apply ks = do
121121
stack <- Action $ asks actionStack
122122
(is, vs) <- liftIO $ build db stack ks
123123
ref <- Action $ asks actionDeps
124-
liftIO $ modifyIORef ref (ResultDeps (toList is) <>)
124+
liftIO $ modifyIORef ref (ResultDeps (fromListKeySet $ toList is) <>)
125125
pure vs
126126

127127
-- | Evaluate a list of keys without recording any dependencies.

0 commit comments

Comments
 (0)