1
1
{-# LANGUAGE GADTs #-}
2
2
module Development.IDE.Core.PluginUtils
3
- (-- Wrapped Action functions
3
+ (-- * Wrapped Action functions
4
4
runActionE
5
5
, runActionMT
6
6
, useE
@@ -9,13 +9,13 @@ module Development.IDE.Core.PluginUtils
9
9
, usesMT
10
10
, useWithStaleE
11
11
, useWithStaleMT
12
- -- Wrapped IdeAction functions
12
+ -- * Wrapped IdeAction functions
13
13
, runIdeActionE
14
14
, runIdeActionMT
15
15
, useWithStaleFastE
16
16
, useWithStaleFastMT
17
17
, uriToFilePathE
18
- -- Wrapped PositionMapping functions
18
+ -- * Wrapped PositionMapping functions
19
19
, toCurrentPositionE
20
20
, toCurrentPositionMT
21
21
, fromCurrentPositionE
@@ -24,9 +24,13 @@ module Development.IDE.Core.PluginUtils
24
24
, toCurrentRangeMT
25
25
, fromCurrentRangeE
26
26
, fromCurrentRangeMT
27
- -- Formatting handlers
27
+ -- * Diagnostics
28
+ , activeDiagnosticsInRange
29
+ , activeDiagnosticsInRangeMT
30
+ -- * Formatting handlers
28
31
, mkFormattingHandlers) where
29
32
33
+ import Control.Concurrent.STM
30
34
import Control.Lens ((^.) )
31
35
import Control.Monad.Error.Class (MonadError (throwError ))
32
36
import Control.Monad.Extra
@@ -47,14 +51,17 @@ import Development.IDE.Core.Shake (IdeAction, IdeRule,
47
51
import qualified Development.IDE.Core.Shake as Shake
48
52
import Development.IDE.GHC.Orphans ()
49
53
import Development.IDE.Graph hiding (ShakeValue )
54
+ import Development.IDE.Types.Diagnostics
50
55
import Development.IDE.Types.Location (NormalizedFilePath )
51
56
import qualified Development.IDE.Types.Location as Location
52
57
import qualified Ide.Logger as Logger
53
58
import Ide.Plugin.Error
59
+ import Ide.PluginUtils (rangesOverlap )
54
60
import Ide.Types
55
61
import qualified Language.LSP.Protocol.Lens as LSP
56
62
import Language.LSP.Protocol.Message (SMethod (.. ))
57
63
import qualified Language.LSP.Protocol.Types as LSP
64
+ import qualified StmContainers.Map as STM
58
65
59
66
-- ----------------------------------------------------------------------------
60
67
-- Action wrappers
@@ -173,6 +180,25 @@ fromCurrentRangeE mapping = maybeToExceptT (PluginInvalidUserState "fromCurrentR
173
180
fromCurrentRangeMT :: Monad m => PositionMapping -> LSP. Range -> MaybeT m LSP. Range
174
181
fromCurrentRangeMT mapping = MaybeT . pure . fromCurrentRange mapping
175
182
183
+ -- ----------------------------------------------------------------------------
184
+ -- Diagnostics
185
+ -- ----------------------------------------------------------------------------
186
+
187
+ activeDiagnosticsInRangeMT :: MonadIO m => Shake. ShakeExtras -> NormalizedFilePath -> LSP. Range -> MaybeT m [FileDiagnostic ]
188
+ activeDiagnosticsInRangeMT ide nfp range = do
189
+ MaybeT $ liftIO $ atomically $ do
190
+ mDiags <- STM. lookup (LSP. normalizedFilePathToUri nfp) (Shake. publishedDiagnostics ide)
191
+ case mDiags of
192
+ Nothing -> pure Nothing
193
+ Just fileDiags -> do
194
+ pure $ Just $ filter diagRangeOverlaps fileDiags
195
+ where
196
+ diagRangeOverlaps = \ fileDiag ->
197
+ rangesOverlap range (fileDiag ^. fdLspDiagnosticL . LSP. range)
198
+
199
+ activeDiagnosticsInRange :: MonadIO m => Shake. ShakeExtras -> NormalizedFilePath -> LSP. Range -> m (Maybe [FileDiagnostic ])
200
+ activeDiagnosticsInRange ide nfp range = runMaybeT (activeDiagnosticsInRangeMT ide nfp range)
201
+
176
202
-- ----------------------------------------------------------------------------
177
203
-- Formatting handlers
178
204
-- ----------------------------------------------------------------------------
0 commit comments