77{-# LANGUAGE RankNTypes #-}
88
99module Development.IDE.LSP.Notifications
10- ( whenUriFile
10+ ( whenUriHaskellFile
1111 , descriptor
1212 ) where
1313
@@ -38,16 +38,21 @@ import Development.IDE.Core.RuleTypes (GetClientSettings (..))
3838import Development.IDE.Types.Shake (toKey )
3939import Ide.Plugin.Config (CheckParents (CheckOnClose ))
4040import Ide.Types
41+ import System.FilePath (takeExtension )
4142
42- whenUriFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
43- whenUriFile uri act = whenJust (LSP. uriToFilePath uri) $ act . toNormalizedFilePath'
43+ whenUriHaskellFile :: Uri -> (NormalizedFilePath -> IO () ) -> IO ()
44+ whenUriHaskellFile uri act = whenJust maybeHaskellFile $ act . toNormalizedFilePath'
45+ where
46+ maybeHaskellFile = do
47+ fp <- LSP. uriToFilePath uri
48+ if takeExtension fp `elem` [" .hs" , " .lhs" ] then Just fp else Nothing
4449
4550descriptor :: PluginId -> PluginDescriptor IdeState
4651descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers = mconcat
4752 [ mkPluginNotificationHandler LSP. STextDocumentDidOpen $
4853 \ ide _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
4954 updatePositionMapping ide (VersionedTextDocumentIdentifier _uri (Just _version)) (List [] )
50- whenUriFile _uri $ \ file -> do
55+ whenUriHaskellFile _uri $ \ file -> do
5156 -- We don't know if the file actually exists, or if the contents match those on disk
5257 -- For example, vscode restores previously unsaved contents on open
5358 addFileOfInterest ide file Modified {firstOpen= True }
@@ -57,21 +62,21 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
5762 , mkPluginNotificationHandler LSP. STextDocumentDidChange $
5863 \ ide _ (DidChangeTextDocumentParams identifier@ VersionedTextDocumentIdentifier {_uri} changes) -> liftIO $ do
5964 updatePositionMapping ide identifier changes
60- whenUriFile _uri $ \ file -> do
65+ whenUriHaskellFile _uri $ \ file -> do
6166 addFileOfInterest ide file Modified {firstOpen= False }
6267 setFileModified ide False file
6368 logDebug (ideLogger ide) $ " Modified text document: " <> getUri _uri
6469
6570 , mkPluginNotificationHandler LSP. STextDocumentDidSave $
6671 \ ide _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
67- whenUriFile _uri $ \ file -> do
72+ whenUriHaskellFile _uri $ \ file -> do
6873 addFileOfInterest ide file OnDisk
6974 setFileModified ide True file
7075 logDebug (ideLogger ide) $ " Saved text document: " <> getUri _uri
7176
7277 , mkPluginNotificationHandler LSP. STextDocumentDidClose $
7378 \ ide _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
74- whenUriFile _uri $ \ file -> do
79+ whenUriHaskellFile _uri $ \ file -> do
7580 deleteFileOfInterest ide file
7681 -- Refresh all the files that depended on this
7782 checkParents <- optCheckParents =<< getIdeOptionsIO (shakeExtras ide)
@@ -120,3 +125,4 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
120125 liftIO $ logDebug (ideLogger ide) " Warning: Client does not support watched files. Falling back to OS polling"
121126 ]
122127 }
128+
0 commit comments