@@ -34,6 +34,7 @@ import qualified Ide.Plugin.Cabal.Completions as Completions
34
34
import qualified Ide.Plugin.Cabal.Diagnostics as Diagnostics
35
35
import qualified Ide.Plugin.Cabal.LicenseSuggest as LicenseSuggest
36
36
import qualified Ide.Plugin.Cabal.Parse as Parse
37
+ import qualified Ide.Plugin.Cabal.Types as Types
37
38
import Ide.Types
38
39
import qualified Language.LSP.Protocol.Lens as JL
39
40
import qualified Language.LSP.Protocol.Message as LSP
@@ -49,8 +50,8 @@ data Log
49
50
| LogDocSaved Uri
50
51
| LogDocClosed Uri
51
52
| LogFOI (HashMap NormalizedFilePath FileOfInterestStatus )
52
- | LogCompletionContext Completions . Context Position
53
- | LogCompletions Completions . Log
53
+ | LogCompletionContext Types . Context Position
54
+ | LogCompletions Types . Log
54
55
deriving (Show )
55
56
56
57
instance Pretty Log where
@@ -68,62 +69,65 @@ instance Pretty Log where
68
69
" Closed text document:" <+> pretty (getUri uri)
69
70
LogFOI files ->
70
71
" Set files of interest to:" <+> viaShow files
71
- LogCompletionContext context position->
72
- " Determined completion context:" <+> viaShow context
73
- <+> " for cursor position:" <+> viaShow position
72
+ LogCompletionContext context position ->
73
+ " Determined completion context:"
74
+ <+> viaShow context
75
+ <+> " for cursor position:"
76
+ <+> viaShow position
74
77
LogCompletions logs -> pretty logs
75
78
76
79
descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
77
- descriptor recorder plId = (defaultCabalPluginDescriptor plId)
78
- { pluginRules = cabalRules recorder
79
- , pluginHandlers = mconcat
80
- [ mkPluginHandler LSP. SMethod_TextDocumentCodeAction licenseSuggestCodeAction
81
- , mkPluginHandler LSP. SMethod_TextDocumentCompletion $ completion recorder
82
- ]
83
- , pluginNotificationHandlers = mconcat
84
- [ mkPluginNotificationHandler LSP. SMethod_TextDocumentDidOpen $
85
- \ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
86
- whenUriFile _uri $ \ file -> do
87
- log' Debug $ LogDocOpened _uri
88
- addFileOfInterest recorder ide file Modified {firstOpen= True }
89
- restartCabalShakeSession (shakeExtras ide) vfs file " (opened)"
90
-
91
- , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidChange $
92
- \ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
93
- whenUriFile _uri $ \ file -> do
94
- log' Debug $ LogDocModified _uri
95
- addFileOfInterest recorder ide file Modified {firstOpen= False }
96
- restartCabalShakeSession (shakeExtras ide) vfs file " (changed)"
97
-
98
- , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidSave $
99
- \ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
100
- whenUriFile _uri $ \ file -> do
101
- log' Debug $ LogDocSaved _uri
102
- addFileOfInterest recorder ide file OnDisk
103
- restartCabalShakeSession (shakeExtras ide) vfs file " (saved)"
104
-
105
- , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidClose $
106
- \ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
107
- whenUriFile _uri $ \ file -> do
108
- log' Debug $ LogDocClosed _uri
109
- deleteFileOfInterest recorder ide file
110
- restartCabalShakeSession (shakeExtras ide) vfs file " (closed)"
111
- ]
112
- }
113
- where
114
- log' = logWith recorder
115
-
116
- whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
117
- whenUriFile uri act = whenJust (uriToFilePath uri) $ act . toNormalizedFilePath'
118
-
119
- -- | Helper function to restart the shake session, specifically for modifying .cabal files.
120
- -- No special logic, just group up a bunch of functions you need for the base
121
- -- Notification Handlers.
122
- --
123
- -- To make sure diagnostics are up to date, we need to tell shake that the file was touched and
124
- -- needs to be re-parsed. That's what we do when we record the dirty key that our parsing
125
- -- rule depends on.
126
- -- Then we restart the shake session, so that changes to our virtual files are actually picked up.
80
+ descriptor recorder plId =
81
+ (defaultCabalPluginDescriptor plId)
82
+ { pluginRules = cabalRules recorder
83
+ , pluginHandlers =
84
+ mconcat
85
+ [ mkPluginHandler LSP. SMethod_TextDocumentCodeAction licenseSuggestCodeAction
86
+ , mkPluginHandler LSP. SMethod_TextDocumentCompletion $ completion recorder
87
+ ]
88
+ , pluginNotificationHandlers =
89
+ mconcat
90
+ [ mkPluginNotificationHandler LSP. SMethod_TextDocumentDidOpen $
91
+ \ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri, _version}) -> liftIO $ do
92
+ whenUriFile _uri $ \ file -> do
93
+ log' Debug $ LogDocOpened _uri
94
+ addFileOfInterest recorder ide file Modified {firstOpen = True }
95
+ restartCabalShakeSession (shakeExtras ide) vfs file " (opened)"
96
+ , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidChange $
97
+ \ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
98
+ whenUriFile _uri $ \ file -> do
99
+ log' Debug $ LogDocModified _uri
100
+ addFileOfInterest recorder ide file Modified {firstOpen = False }
101
+ restartCabalShakeSession (shakeExtras ide) vfs file " (changed)"
102
+ , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidSave $
103
+ \ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
104
+ whenUriFile _uri $ \ file -> do
105
+ log' Debug $ LogDocSaved _uri
106
+ addFileOfInterest recorder ide file OnDisk
107
+ restartCabalShakeSession (shakeExtras ide) vfs file " (saved)"
108
+ , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidClose $
109
+ \ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
110
+ whenUriFile _uri $ \ file -> do
111
+ log' Debug $ LogDocClosed _uri
112
+ deleteFileOfInterest recorder ide file
113
+ restartCabalShakeSession (shakeExtras ide) vfs file " (closed)"
114
+ ]
115
+ }
116
+ where
117
+ log' = logWith recorder
118
+
119
+ whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
120
+ whenUriFile uri act = whenJust (uriToFilePath uri) $ act . toNormalizedFilePath'
121
+
122
+ {- | Helper function to restart the shake session, specifically for modifying .cabal files.
123
+ No special logic, just group up a bunch of functions you need for the base
124
+ Notification Handlers.
125
+
126
+ To make sure diagnostics are up to date, we need to tell shake that the file was touched and
127
+ needs to be re-parsed. That's what we do when we record the dirty key that our parsing
128
+ rule depends on.
129
+ Then we restart the shake session, so that changes to our virtual files are actually picked up.
130
+ -}
127
131
restartCabalShakeSession :: ShakeExtras -> VFS. VFS -> NormalizedFilePath -> String -> IO ()
128
132
restartCabalShakeSession shakeExtras vfs file actionMsg = do
129
133
join $ atomically $ Shake. recordDirtyKeys shakeExtras GetModificationTime [file]
@@ -190,12 +194,12 @@ kick = do
190
194
-- Code Actions
191
195
-- ----------------------------------------------------------------
192
196
193
- licenseSuggestCodeAction
194
- :: IdeState
195
- -> PluginId
196
- -> CodeActionParams
197
- -> LspM Config (Either LSP. ResponseError (LSP. MessageResult 'LSP.Method_TextDocumentCodeAction ))
198
- licenseSuggestCodeAction _ _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range CodeActionContext {_diagnostics= diags}) =
197
+ licenseSuggestCodeAction ::
198
+ IdeState ->
199
+ PluginId ->
200
+ CodeActionParams ->
201
+ LspM Config (Either LSP. ResponseError (LSP. MessageResult 'LSP.Method_TextDocumentCodeAction ))
202
+ licenseSuggestCodeAction _ _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range CodeActionContext {_diagnostics = diags}) =
199
203
pure $ Right $ InL $ diags >>= (fmap InR . LicenseSuggest. licenseErrorAction uri)
200
204
201
205
-- ----------------------------------------------------------------
0 commit comments