@@ -159,7 +159,6 @@ import qualified Ide.PluginUtils as HLS
159
159
import Ide.Types (IdePlugins (IdePlugins ),
160
160
PluginDescriptor (pluginId ),
161
161
PluginId )
162
- import Language.LSP.Diagnostics
163
162
import qualified Language.LSP.Protocol.Lens as L
164
163
import Language.LSP.Protocol.Message
165
164
import Language.LSP.Protocol.Types
@@ -290,7 +289,7 @@ data ShakeExtras = ShakeExtras
290
289
,state :: Values
291
290
,diagnostics :: STMDiagnosticStore
292
291
,hiddenDiagnostics :: STMDiagnosticStore
293
- ,publishedDiagnostics :: STM. Map NormalizedUri [Diagnostic ]
292
+ ,publishedDiagnostics :: STM. Map NormalizedUri [FileDiagnostic ]
294
293
-- ^ This represents the set of diagnostics that we have published.
295
294
-- Due to debouncing not every change might get published.
296
295
@@ -1349,14 +1348,14 @@ updateFileDiagnostics :: MonadIO m
1349
1348
-> ShakeExtras
1350
1349
-> [FileDiagnostic ] -- ^ current results
1351
1350
-> m ()
1352
- updateFileDiagnostics recorder fp ver k ShakeExtras {diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 =
1351
+ updateFileDiagnostics recorder fp ver k ShakeExtras {diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 = do
1353
1352
liftIO $ withTrace (" update diagnostics " <> fromString(fromNormalizedFilePath fp)) $ \ addTag -> do
1354
1353
addTag " key" (show k)
1355
1354
let (currentShown, currentHidden) = partition ((== ShowDiag ) . fdShouldShowDiagnostic) current
1356
1355
uri = filePathToUri' fp
1357
1356
addTagUnsafe :: String -> String -> String -> a -> a
1358
1357
addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v
1359
- update :: (forall a . String -> String -> a -> a ) -> [Diagnostic ] -> STMDiagnosticStore -> STM [Diagnostic ]
1358
+ update :: (forall a . String -> String -> a -> a ) -> [FileDiagnostic ] -> STMDiagnosticStore -> STM [FileDiagnostic ]
1360
1359
update addTagUnsafeMethod new store = addTagUnsafeMethod " count" (show $ Prelude. length new) $ setStageDiagnostics addTagUnsafeMethod uri ver (renderKey k) new store
1361
1360
current = map (modifyFdLspDiagnostic diagsFromRule) current0
1362
1361
addTag " version" (show ver)
@@ -1365,21 +1364,21 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
1365
1364
-- published. Otherwise, we might never publish certain diagnostics if
1366
1365
-- an exception strikes between modifyVar but before
1367
1366
-- publishDiagnosticsNotification.
1368
- newDiags <- liftIO $ atomicallyNamed " diagnostics - update" $ update (addTagUnsafe " shown " ) ( map fdLspDiagnostic currentShown) diagnostics
1369
- _ <- liftIO $ atomicallyNamed " diagnostics - hidden" $ update (addTagUnsafe " hidden " ) ( map fdLspDiagnostic currentHidden) hiddenDiagnostics
1367
+ newDiags <- liftIO $ atomicallyNamed " diagnostics - update" $ update (addTagUnsafe " shown " ) currentShown diagnostics
1368
+ _ <- liftIO $ atomicallyNamed " diagnostics - hidden" $ update (addTagUnsafe " hidden " ) currentHidden hiddenDiagnostics
1370
1369
let uri' = filePathToUri' fp
1371
1370
let delay = if null newDiags then 0.1 else 0
1372
1371
registerEvent debouncer delay uri' $ withTrace (" report diagnostics " <> fromString (fromNormalizedFilePath fp)) $ \ tag -> do
1373
1372
join $ mask_ $ do
1374
1373
lastPublish <- atomicallyNamed " diagnostics - publish" $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri' publishedDiagnostics
1375
1374
let action = when (lastPublish /= newDiags) $ case lspEnv of
1376
1375
Nothing -> -- Print an LSP event.
1377
- logWith recorder Info $ LogDiagsDiffButNoLspEnv ( map ( \ lspDiag -> ideErrorFromLspDiag lspDiag fp Nothing ) newDiags) -- TODO: Should try to get structured diagnostics plumbed here if possible
1376
+ logWith recorder Info $ LogDiagsDiffButNoLspEnv newDiags
1378
1377
Just env -> LSP. runLspT env $ do
1379
1378
liftIO $ tag " count" (show $ Prelude. length newDiags)
1380
1379
liftIO $ tag " key" (show k)
1381
1380
LSP. sendNotification SMethod_TextDocumentPublishDiagnostics $
1382
- LSP. PublishDiagnosticsParams (fromNormalizedUri uri') (fmap fromIntegral ver) newDiags
1381
+ LSP. PublishDiagnosticsParams (fromNormalizedUri uri') (fmap fromIntegral ver) ( map fdLspDiagnostic newDiags)
1383
1382
return action
1384
1383
where
1385
1384
diagsFromRule :: Diagnostic -> Diagnostic
@@ -1403,26 +1402,28 @@ actionLogger :: Action (Recorder (WithPriority Log))
1403
1402
actionLogger = shakeRecorder <$> getShakeExtras
1404
1403
1405
1404
--------------------------------------------------------------------------------
1406
- type STMDiagnosticStore = STM. Map NormalizedUri StoreItem
1405
+ type STMDiagnosticStore = STM. Map NormalizedUri StoreItem'
1406
+ data StoreItem' = StoreItem' (Maybe Int32 ) FileDiagnosticsBySource
1407
+ type FileDiagnosticsBySource = Map. Map (Maybe T. Text ) (SL. SortedList FileDiagnostic )
1407
1408
1408
- getDiagnosticsFromStore :: StoreItem -> [Diagnostic ]
1409
- getDiagnosticsFromStore (StoreItem _ diags) = concatMap SL. fromSortedList $ Map. elems diags
1409
+ getDiagnosticsFromStore :: StoreItem' -> [FileDiagnostic ]
1410
+ getDiagnosticsFromStore (StoreItem' _ diags) = concatMap SL. fromSortedList $ Map. elems diags
1410
1411
1411
1412
updateSTMDiagnostics ::
1412
1413
(forall a . String -> String -> a -> a ) ->
1413
1414
STMDiagnosticStore ->
1414
1415
NormalizedUri ->
1415
1416
Maybe Int32 ->
1416
- DiagnosticsBySource ->
1417
- STM [LSP. Diagnostic ]
1417
+ FileDiagnosticsBySource ->
1418
+ STM [FileDiagnostic ]
1418
1419
updateSTMDiagnostics addTag store uri mv newDiagsBySource =
1419
1420
getDiagnosticsFromStore . fromJust <$> STM. focus (Focus. alter update *> Focus. lookup ) uri store
1420
1421
where
1421
- update (Just (StoreItem mvs dbs))
1422
+ update (Just (StoreItem' mvs dbs))
1422
1423
| addTag " previous version" (show mvs) $
1423
1424
addTag " previous count" (show $ Prelude. length $ filter (not . null ) $ Map. elems dbs) False = undefined
1424
- | mvs == mv = Just (StoreItem mv (newDiagsBySource <> dbs))
1425
- update _ = Just (StoreItem mv newDiagsBySource)
1425
+ | mvs == mv = Just (StoreItem' mv (newDiagsBySource <> dbs))
1426
+ update _ = Just (StoreItem' mv newDiagsBySource)
1426
1427
1427
1428
-- | Sets the diagnostics for a file and compilation step
1428
1429
-- if you want to clear the diagnostics call this with an empty list
@@ -1431,9 +1432,9 @@ setStageDiagnostics
1431
1432
-> NormalizedUri
1432
1433
-> Maybe Int32 -- ^ the time that the file these diagnostics originate from was last edited
1433
1434
-> T. Text
1434
- -> [LSP. Diagnostic ]
1435
+ -> [FileDiagnostic ]
1435
1436
-> STMDiagnosticStore
1436
- -> STM [LSP. Diagnostic ]
1437
+ -> STM [FileDiagnostic ]
1437
1438
setStageDiagnostics addTag uri ver stage diags ds = updateSTMDiagnostics addTag ds uri ver updatedDiags
1438
1439
where
1439
1440
! updatedDiags = Map. singleton (Just stage) $! SL. toSortedList diags
@@ -1442,7 +1443,7 @@ getAllDiagnostics ::
1442
1443
STMDiagnosticStore ->
1443
1444
STM [FileDiagnostic ]
1444
1445
getAllDiagnostics =
1445
- fmap (concatMap (\ (k ,v) -> map ( \ diag -> ideErrorFromLspDiag diag (fromUri k) Nothing ) $ getDiagnosticsFromStore v)) . ListT. toList . STM. listT -- TODO: Do we need the structured message here?
1446
+ fmap (concatMap (\ (_ ,v) -> getDiagnosticsFromStore v)) . ListT. toList . STM. listT
1446
1447
1447
1448
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> [TextDocumentContentChangeEvent ] -> STM ()
1448
1449
updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } changes =
0 commit comments