77{-# LANGUAGE RankNTypes #-}
88
99module Development.IDE.LSP.Notifications
10- ( setHandlersNotifications
10+ ( whenUriFile
11+ , descriptor
1112 ) where
1213
1314import qualified Language.LSP.Server as LSP
@@ -37,15 +38,15 @@ import Development.IDE.Core.FileStore (resetFileStore,
3738 typecheckParents )
3839import Development.IDE.Core.OfInterest
3940import Ide.Plugin.Config (CheckParents (CheckOnClose ))
40-
41+ import Ide.Types
4142
4243whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
4344whenUriFile uri act = whenJust (LSP. uriToFilePath uri) $ act . toNormalizedFilePath'
4445
45- setHandlersNotifications :: LSP. Handlers ( ServerM c )
46- setHandlersNotifications = mconcat
47- [ notificationHandler LSP. STextDocumentDidOpen $
48- \ ide (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
46+ descriptor :: PluginId -> PluginDescriptor IdeState
47+ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers = mconcat
48+ [ mkPluginNotificationHandler LSP. STextDocumentDidOpen $
49+ \ ide _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
4950 updatePositionMapping ide (VersionedTextDocumentIdentifier _uri (Just _version)) (List [] )
5051 whenUriFile _uri $ \ file -> do
5152 -- We don't know if the file actually exists, or if the contents match those on disk
@@ -54,32 +55,32 @@ setHandlersNotifications = mconcat
5455 setFileModified ide False file
5556 logDebug (ideLogger ide) $ " Opened text document: " <> getUri _uri
5657
57- , notificationHandler LSP. STextDocumentDidChange $
58- \ ide (DidChangeTextDocumentParams identifier@ VersionedTextDocumentIdentifier {_uri} changes) -> liftIO $ do
58+ , mkPluginNotificationHandler LSP. STextDocumentDidChange $
59+ \ ide _ (DidChangeTextDocumentParams identifier@ VersionedTextDocumentIdentifier {_uri} changes) -> liftIO $ do
5960 updatePositionMapping ide identifier changes
6061 whenUriFile _uri $ \ file -> do
6162 modifyFilesOfInterest ide (M. insert file Modified {firstOpen= False })
6263 setFileModified ide False file
6364 logDebug (ideLogger ide) $ " Modified text document: " <> getUri _uri
6465
65- , notificationHandler LSP. STextDocumentDidSave $
66- \ ide (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
66+ , mkPluginNotificationHandler LSP. STextDocumentDidSave $
67+ \ ide _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
6768 whenUriFile _uri $ \ file -> do
6869 modifyFilesOfInterest ide (M. insert file OnDisk )
6970 setFileModified ide True file
7071 logDebug (ideLogger ide) $ " Saved text document: " <> getUri _uri
7172
72- , notificationHandler LSP. STextDocumentDidClose $
73- \ ide (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
73+ , mkPluginNotificationHandler LSP. STextDocumentDidClose $
74+ \ ide _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
7475 whenUriFile _uri $ \ file -> do
7576 modifyFilesOfInterest ide (M. delete file)
7677 -- Refresh all the files that depended on this
7778 checkParents <- optCheckParents =<< getIdeOptionsIO (shakeExtras ide)
7879 when (checkParents >= CheckOnClose ) $ typecheckParents ide file
7980 logDebug (ideLogger ide) $ " Closed text document: " <> getUri _uri
8081
81- , notificationHandler LSP. SWorkspaceDidChangeWatchedFiles $
82- \ ide (DidChangeWatchedFilesParams (List fileEvents)) -> liftIO $ do
82+ , mkPluginNotificationHandler LSP. SWorkspaceDidChangeWatchedFiles $
83+ \ ide _ (DidChangeWatchedFilesParams (List fileEvents)) -> liftIO $ do
8384 -- See Note [File existence cache and LSP file watchers] which explains why we get these notifications and
8485 -- what we do with them
8586 let msg = Text. pack $ show fileEvents
@@ -88,22 +89,22 @@ setHandlersNotifications = mconcat
8889 resetFileStore ide fileEvents
8990 setSomethingModified ide
9091
91- , notificationHandler LSP. SWorkspaceDidChangeWorkspaceFolders $
92- \ ide (DidChangeWorkspaceFoldersParams events) -> liftIO $ do
92+ , mkPluginNotificationHandler LSP. SWorkspaceDidChangeWorkspaceFolders $
93+ \ ide _ (DidChangeWorkspaceFoldersParams events) -> liftIO $ do
9394 let add = S. union
9495 substract = flip S. difference
9596 modifyWorkspaceFolders ide
9697 $ add (foldMap (S. singleton . parseWorkspaceFolder) (_added events))
9798 . substract (foldMap (S. singleton . parseWorkspaceFolder) (_removed events))
9899
99- , notificationHandler LSP. SWorkspaceDidChangeConfiguration $
100- \ ide (DidChangeConfigurationParams cfg) -> liftIO $ do
100+ , mkPluginNotificationHandler LSP. SWorkspaceDidChangeConfiguration $
101+ \ ide _ (DidChangeConfigurationParams cfg) -> liftIO $ do
101102 let msg = Text. pack $ show cfg
102103 logDebug (ideLogger ide) $ " Configuration changed: " <> msg
103104 modifyClientSettings ide (const $ Just cfg)
104105 setSomethingModified ide
105106
106- , notificationHandler LSP. SInitialized $ \ ide _ -> do
107+ , mkPluginNotificationHandler LSP. SInitialized $ \ ide _ _ -> do
107108 clientCapabilities <- LSP. getClientCapabilities
108109 let watchSupported = case () of
109110 _ | LSP. ClientCapabilities {_workspace} <- clientCapabilities
@@ -138,3 +139,4 @@ setHandlersNotifications = mconcat
138139 void $ LSP. sendRequest SClientRegisterCapability regParams (const $ pure () ) -- TODO handle response
139140 else liftIO $ logDebug (ideLogger ide) " Warning: Client does not support watched files. Falling back to OS polling"
140141 ]
142+ }
0 commit comments