@@ -17,7 +17,7 @@ import Control.Monad.IO.Class
1717import qualified Data.ByteString as BS
1818import Data.Hashable
1919import qualified Data.List.NonEmpty as NE
20- import Data.Maybe (catMaybes )
20+ import Data.Maybe (mapMaybe )
2121import qualified Data.Text.Encoding as Encoding
2222import Data.Typeable
2323import Development.IDE as D
@@ -69,33 +69,25 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
6969 \ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
7070 whenUriFile _uri $ \ file -> do
7171 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)"
7573
7674 , mkPluginNotificationHandler LSP. STextDocumentDidChange $
7775 \ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
7876 whenUriFile _uri $ \ file -> do
7977 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)"
8379
8480 , mkPluginNotificationHandler LSP. STextDocumentDidSave $
8581 \ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
8682 whenUriFile _uri $ \ file -> do
8783 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)"
9185
9286 , mkPluginNotificationHandler LSP. STextDocumentDidClose $
9387 \ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
9488 whenUriFile _uri $ \ file -> do
9589 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)"
9991 ]
10092 }
10193 where
@@ -104,6 +96,15 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
10496 whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
10597 whenUriFile uri act = whenJust (LSP. uriToFilePath uri) $ act . toNormalizedFilePath'
10698
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+
107108-- ----------------------------------------------------------------
108109-- Plugin Rules
109110-- ----------------------------------------------------------------
@@ -150,4 +151,4 @@ licenseSuggestCodeAction
150151 -> CodeActionParams
151152 -> LspM Config (Either ResponseError (ResponseResult 'TextDocumentCodeAction))
152153licenseSuggestCodeAction _ _ (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