@@ -89,7 +89,8 @@ instance Pretty Log where
89
89
LogCabalAdd logs -> pretty logs
90
90
91
91
-- | Some actions with cabal files originate from haskell files.
92
- -- This descriptor is needed to handle these cases.
92
+ -- This descriptor allows to hook into the diagnostics of haskell source files, and
93
+ -- allows us to provide code actions and commands that interact with `.cabal` files.
93
94
haskellInteractionDescriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
94
95
haskellInteractionDescriptor recorder plId =
95
96
(defaultPluginDescriptor plId " Provides the cabal-add code action in haskell files" )
@@ -98,7 +99,7 @@ haskellInteractionDescriptor recorder plId =
98
99
[ mkPluginHandler LSP. SMethod_TextDocumentCodeAction $ cabalAddCodeAction recorder
99
100
]
100
101
, pluginCommands = [PluginCommand CabalAdd. cabalAddCommand " add a dependency to a cabal file" (CabalAdd. command cabalAddRecorder)]
101
- , pluginRules = pure () -- TODO: change to haskell files only (?)
102
+ , pluginRules = pure ()
102
103
, pluginNotificationHandlers = mempty
103
104
}
104
105
where
@@ -302,13 +303,12 @@ fieldSuggestCodeAction recorder ide _ (CodeActionParams _ _ (TextDocumentIdentif
302
303
cabalAddCodeAction :: Recorder (WithPriority Log ) -> PluginMethodHandler IdeState 'LSP.Method_TextDocumentCodeAction
303
304
cabalAddCodeAction recorder state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) _ CodeActionContext {_diagnostics= diags}) = do
304
305
maxCompls <- fmap maxCompletions . liftIO $ runAction " cabal.cabal-add" state getClientConfigAction
305
- let mbHaskellFilePath = uriToFilePath uri
306
- case mbHaskellFilePath of
306
+ case uriToFilePath uri of
307
307
Nothing -> pure $ InL []
308
308
Just haskellFilePath -> do
309
309
mbCabalFile <- liftIO $ CabalAdd. findResponsibleCabalFile haskellFilePath
310
310
case mbCabalFile of
311
- Nothing -> pure $ InL $ fmap InR [ noCabalFileAction]
311
+ Nothing -> pure $ InL [ InR noCabalFileAction]
312
312
Just cabalFilePath -> do
313
313
verTxtDocId <- lift $ pluginGetVersionedTextDoc $ TextDocumentIdentifier (filePathToUri cabalFilePath)
314
314
mbGPD <- liftIO $ runAction " cabal.cabal-add" state $ useWithStale ParseCabalFile $ toNormalizedFilePath cabalFilePath
0 commit comments