Skip to content

Commit 3e357f2

Browse files
authored
Add support for extra LSP options (#4955)
Add support for new LSP file modification options that plugins can register for. These options are: * SMethod_WorkspaceDidRenameFiles, * SMethod_WorkspaceWillRenameFiles, * SMethod_WorkspaceDidDeleteFiles, * SMethod_WorkspaceWillDeleteFiles, * SMethod_WorkspaceDidCreateFiles
1 parent 9e2e931 commit 3e357f2

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

ghcide/src/Development/IDE/Main.hs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ import Ide.Types (IdeCommand (IdeComman
111111
PluginDescriptor (PluginDescriptor, pluginCli),
112112
PluginId (PluginId),
113113
ipMap, pluginId)
114+
import qualified Language.LSP.Protocol.Types as LSP
114115
import qualified Language.LSP.Server as LSP
115116
import Numeric.Natural (Natural)
116117
import Options.Applicative hiding (action)
@@ -300,7 +301,29 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
300301
let hlsPlugin = asGhcIdePlugin (cmapWithPrio LogPluginHLS recorder) argsHlsPlugins
301302
hlsCommands = allLspCmdIds' pid argsHlsPlugins
302303
plugins = hlsPlugin <> argsGhcidePlugin
303-
options = argsLspOptions { LSP.optExecuteCommandCommands = LSP.optExecuteCommandCommands argsLspOptions <> Just hlsCommands }
304+
options =
305+
argsLspOptions
306+
{ LSP.optExecuteCommandCommands = LSP.optExecuteCommandCommands argsLspOptions <> Just hlsCommands
307+
, LSP.optWorkspaceWillRenameFileOperationRegistrationOptions = fileModificationOptions
308+
, LSP.optWorkspaceDidRenameFileOperationRegistrationOptions = fileModificationOptions
309+
, LSP.optWorkspaceWillDeleteFileOperationRegistrationOptions = fileModificationOptions
310+
, LSP.optWorkspaceDidDeleteFileOperationRegistrationOptions = fileModificationOptions
311+
, LSP.optWorkspaceWillCreateFileOperationRegistrationOptions = fileModificationOptions
312+
, LSP.optWorkspaceDidCreateFileOperationRegistrationOptions = fileModificationOptions
313+
}
314+
fileModificationOptions =
315+
Just $
316+
LSP.FileOperationRegistrationOptions
317+
[ LSP.FileOperationFilter
318+
{ _scheme = Just "file"
319+
, _pattern =
320+
LSP.FileOperationPattern
321+
{ _glob = "**/*.hs"
322+
, _matches = Just LSP.FileOperationPatternKind_File
323+
, _options = Nothing
324+
}
325+
}
326+
]
304327
argsParseConfig = getConfigFromNotification argsHlsPlugins
305328
rules = do
306329
argsRules

hls-plugin-api/src/Ide/Types.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ instance PluginMethod Request Method_WorkspaceExecuteCommand where
625625
instance PluginMethod Request (Method_CustomMethod m) where
626626
handlesRequest _ _ _ _ _ = HandlesRequest
627627

628+
instance PluginMethod Request Method_WorkspaceWillRenameFiles where
629+
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
630+
628631
-- Plugin Notifications
629632

630633
instance PluginMethod Notification Method_TextDocumentDidOpen where
@@ -647,6 +650,15 @@ instance PluginMethod Notification Method_WorkspaceDidChangeConfiguration where
647650
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
648651
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
649652

653+
instance PluginMethod Notification Method_WorkspaceDidDeleteFiles where
654+
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
655+
656+
instance PluginMethod Notification Method_WorkspaceDidRenameFiles where
657+
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
658+
659+
instance PluginMethod Notification Method_WorkspaceDidCreateFiles where
660+
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
661+
650662
instance PluginMethod Notification Method_Initialized where
651663
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
652664
handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
@@ -856,6 +868,8 @@ instance PluginRequestMethod Method_TextDocumentSemanticTokensFullDelta where
856868
instance PluginRequestMethod Method_TextDocumentInlayHint where
857869
combineResponses _ _ _ _ x = sconcat x
858870

871+
instance PluginRequestMethod Method_WorkspaceWillRenameFiles where
872+
859873
takeLefts :: [a |? b] -> [a]
860874
takeLefts = mapMaybe (\x -> [res | (InL res) <- Just x])
861875

@@ -927,6 +941,12 @@ instance PluginNotificationMethod Method_WorkspaceDidChangeConfiguration where
927941

928942
instance PluginNotificationMethod Method_Initialized where
929943

944+
instance PluginNotificationMethod Method_WorkspaceDidDeleteFiles where
945+
946+
instance PluginNotificationMethod Method_WorkspaceDidCreateFiles where
947+
948+
instance PluginNotificationMethod Method_WorkspaceDidRenameFiles where
949+
930950
-- ---------------------------------------------------------------------
931951

932952
-- | Methods which have a PluginMethod instance
@@ -1257,6 +1277,9 @@ instance HasTracing CompletionItem
12571277
instance HasTracing DocumentLink
12581278
instance HasTracing InlayHint
12591279
instance HasTracing WorkspaceSymbol
1280+
instance HasTracing RenameFilesParams
1281+
instance HasTracing DeleteFilesParams
1282+
instance HasTracing CreateFilesParams
12601283
-- ---------------------------------------------------------------------
12611284
--Experimental resolve refactoring
12621285
{-# NOINLINE pROCESS_ID #-}

0 commit comments

Comments
 (0)