@@ -17,7 +17,7 @@ import Control.Monad.IO.Class
17
17
import qualified Data.ByteString as BS
18
18
import Data.Hashable
19
19
import qualified Data.List.NonEmpty as NE
20
- import Data.Maybe (catMaybes )
20
+ import Data.Maybe (mapMaybe )
21
21
import qualified Data.Text.Encoding as Encoding
22
22
import Data.Typeable
23
23
import Development.IDE as D
@@ -69,33 +69,25 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
69
69
\ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
70
70
whenUriFile _uri $ \ file -> do
71
71
log' Debug $ LogDocOpened _uri
72
- join $ atomically $ Shake. recordDirtyKeys (shakeExtras ide) GetModificationTime [file]
73
- restartShakeSession (shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " (opened)" ) []
74
- join $ Shake. shakeEnqueue (shakeExtras ide) $ Shake. mkDelayedAction " cabal parse modified" Info $ void $ use ParseCabal file
72
+ restartCabalShakeSession ide vfs file " (opened)"
75
73
76
74
, mkPluginNotificationHandler LSP. STextDocumentDidChange $
77
75
\ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
78
76
whenUriFile _uri $ \ file -> do
79
77
log' Debug $ LogDocModified _uri
80
- join $ atomically $ Shake. recordDirtyKeys (shakeExtras ide) GetModificationTime [file]
81
- restartShakeSession (shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " (modified)" ) []
82
- join $ Shake. shakeEnqueue (shakeExtras ide) $ Shake. mkDelayedAction " cabal parse modified" Info $ void $ use ParseCabal file
78
+ restartCabalShakeSession ide vfs file " (changed)"
83
79
84
80
, mkPluginNotificationHandler LSP. STextDocumentDidSave $
85
81
\ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
86
82
whenUriFile _uri $ \ file -> do
87
83
log' Debug $ LogDocSaved _uri
88
- join $ atomically $ Shake. recordDirtyKeys (shakeExtras ide) GetModificationTime [file]
89
- restartShakeSession (shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " (saved)" ) []
90
- join $ Shake. shakeEnqueue (shakeExtras ide) $ Shake. mkDelayedAction " cabal parse modified" Info $ void $ use ParseCabal file
84
+ restartCabalShakeSession ide vfs file " (saved)"
91
85
92
86
, mkPluginNotificationHandler LSP. STextDocumentDidClose $
93
87
\ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
94
88
whenUriFile _uri $ \ file -> do
95
89
log' Debug $ LogDocClosed _uri
96
- join $ atomically $ Shake. recordDirtyKeys (shakeExtras ide) GetModificationTime [file]
97
- restartShakeSession (shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " (closed)" ) []
98
- join $ Shake. shakeEnqueue (shakeExtras ide) $ Shake. mkDelayedAction " cabal parse modified" Info $ void $ use ParseCabal file
90
+ restartCabalShakeSession ide vfs file " (closed)"
99
91
]
100
92
}
101
93
where
@@ -104,6 +96,15 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
104
96
whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
105
97
whenUriFile uri act = whenJust (LSP. uriToFilePath uri) $ act . toNormalizedFilePath'
106
98
99
+ -- | Helper function to restart the shake session, specifically for modifying .cabal files.
100
+ -- No special logic, just group up a bunch of functions you need for the base
101
+ -- Notification Handlers.
102
+ restartCabalShakeSession :: IdeState -> VFS. VFS -> NormalizedFilePath -> String -> IO ()
103
+ restartCabalShakeSession ide vfs file actionMsg = do
104
+ join $ atomically $ Shake. recordDirtyKeys (shakeExtras ide) GetModificationTime [file]
105
+ restartShakeSession (shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " " ++ actionMsg) []
106
+ join $ Shake. shakeEnqueue (shakeExtras ide) $ Shake. mkDelayedAction " cabal parse modified" Info $ void $ use ParseCabal file
107
+
107
108
-- ----------------------------------------------------------------
108
109
-- Plugin Rules
109
110
-- ----------------------------------------------------------------
@@ -150,4 +151,4 @@ licenseSuggestCodeAction
150
151
-> CodeActionParams
151
152
-> LspM Config (Either ResponseError (ResponseResult 'TextDocumentCodeAction))
152
153
licenseSuggestCodeAction _ _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range CodeActionContext {_diagnostics= List diags}) =
153
- pure $ Right $ List $ catMaybes $ map (fmap InR . LicenseSuggest. licenseErrorAction uri) diags
154
+ pure $ Right $ List $ mapMaybe (fmap InR . LicenseSuggest. licenseErrorAction uri) diags
0 commit comments