@@ -73,7 +73,8 @@ module Development.IDE.Core.Shake(
73
73
garbageCollectDirtyKeysOlderThan ,
74
74
Log (.. ),
75
75
VFSModified (.. ), getClientConfigAction ,
76
- ThreadQueue (.. )
76
+ ThreadQueue (.. ),
77
+ runWithSignal
77
78
) where
78
79
79
80
import Control.Concurrent.Async
@@ -123,6 +124,10 @@ import Development.IDE.Core.FileUtils (getModTime)
123
124
import Development.IDE.Core.PositionMapping
124
125
import Development.IDE.Core.ProgressReporting
125
126
import Development.IDE.Core.RuleTypes
127
+ import Development.IDE.Types.Options as Options
128
+ import qualified Language.LSP.Protocol.Message as LSP
129
+ import qualified Language.LSP.Server as LSP
130
+
126
131
import Development.IDE.Core.Tracing
127
132
import Development.IDE.Core.WorkerThread
128
133
import Development.IDE.GHC.Compat (NameCache ,
@@ -147,11 +152,11 @@ import qualified Development.IDE.Types.Exports as ExportsMap
147
152
import Development.IDE.Types.KnownTargets
148
153
import Development.IDE.Types.Location
149
154
import Development.IDE.Types.Monitoring (Monitoring (.. ))
150
- import Development.IDE.Types.Options
151
155
import Development.IDE.Types.Shake
152
156
import qualified Focus
153
157
import GHC.Fingerprint
154
158
import GHC.Stack (HasCallStack )
159
+ import GHC.TypeLits (KnownSymbol )
155
160
import HieDb.Types
156
161
import Ide.Logger hiding (Priority )
157
162
import qualified Ide.Logger as Logger
@@ -165,7 +170,6 @@ import qualified Language.LSP.Protocol.Lens as L
165
170
import Language.LSP.Protocol.Message
166
171
import Language.LSP.Protocol.Types
167
172
import qualified Language.LSP.Protocol.Types as LSP
168
- import qualified Language.LSP.Server as LSP
169
173
import Language.LSP.VFS hiding (start )
170
174
import qualified "list-t" ListT
171
175
import OpenTelemetry.Eventlog hiding (addEvent )
@@ -1350,29 +1354,28 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
1350
1354
let uri' = filePathToUri' fp
1351
1355
let delay = if null newDiags then 0.1 else 0
1352
1356
registerEvent debouncer delay uri' $ withTrace (" report diagnostics " <> fromString (fromNormalizedFilePath fp)) $ \ tag -> do
1353
- join $ mask_ $ do
1354
- lastPublish <- atomicallyNamed " diagnostics - publish" $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri' publishedDiagnostics
1355
- let action = when (lastPublish /= newDiags) $ case lspEnv of
1357
+ join $ mask_ $ do
1358
+ lastPublish <- atomicallyNamed " diagnostics - publish" $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri' publishedDiagnostics
1359
+ let action = when (lastPublish /= newDiags) $ case lspEnv of
1356
1360
Nothing -> -- Print an LSP event.
1357
1361
logWith recorder Info $ LogDiagsDiffButNoLspEnv (map (fp, ShowDiag ,) newDiags)
1358
1362
Just env -> LSP. runLspT env $ do
1359
1363
liftIO $ tag " count" (show $ Prelude. length newDiags)
1360
1364
liftIO $ tag " key" (show k)
1361
1365
LSP. sendNotification SMethod_TextDocumentPublishDiagnostics $
1362
1366
LSP. PublishDiagnosticsParams (fromNormalizedUri uri') (fmap fromIntegral ver) newDiags
1363
- return action
1367
+ return action
1364
1368
where
1365
1369
diagsFromRule :: Diagnostic -> Diagnostic
1366
1370
diagsFromRule c@ Diagnostic {_range}
1367
1371
| coerce ideTesting = c & L. relatedInformation ?~
1368
- [
1369
- DiagnosticRelatedInformation
1372
+ [ DiagnosticRelatedInformation
1370
1373
(Location
1371
1374
(filePathToUri $ fromNormalizedFilePath fp)
1372
1375
_range
1373
1376
)
1374
1377
(T. pack $ show k)
1375
- ]
1378
+ ]
1376
1379
| otherwise = c
1377
1380
1378
1381
@@ -1444,3 +1447,19 @@ updatePositionMappingHelper ver changes mappingForUri = snd $
1444
1447
EM. mapAccumRWithKey (\ acc _k (delta, _) -> let new = addOldDelta delta acc in (new, (delta, acc)))
1445
1448
zeroMapping
1446
1449
(EM. insert ver (mkDelta changes, zeroMapping) mappingForUri)
1450
+
1451
+ -- | sends a signal whenever shake session is run/restarted
1452
+ -- being used in cabal and hlint plugin tests to know when its time
1453
+ -- to look for file diagnostics
1454
+ kickSignal :: KnownSymbol s => Bool -> Maybe (LSP. LanguageContextEnv c ) -> [NormalizedFilePath ] -> Proxy s -> Action ()
1455
+ kickSignal testing lspEnv files msg = when testing $ liftIO $ mRunLspT lspEnv $
1456
+ LSP. sendNotification (LSP. SMethod_CustomMethod msg) $
1457
+ toJSON $ map fromNormalizedFilePath files
1458
+
1459
+ -- | Add kick start/done signal to rule
1460
+ runWithSignal :: (KnownSymbol s0 , KnownSymbol s1 , IdeRule k v ) => Proxy s0 -> Proxy s1 -> [NormalizedFilePath ] -> k -> Action ()
1461
+ runWithSignal msgStart msgEnd files rule = do
1462
+ ShakeExtras {ideTesting = Options. IdeTesting testing, lspEnv} <- getShakeExtras
1463
+ kickSignal testing lspEnv files msgStart
1464
+ void $ uses rule files
1465
+ kickSignal testing lspEnv files msgEnd
0 commit comments