packages feed

hls-plugin-api 2.13.0.0 → 2.14.0.0

raw patch · 2 files changed

+62/−42 lines, 2 filesdep ~hls-graphdep ~lspPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hls-graph, lsp

API changes (from Hackage documentation)

- Ide.Types: [pluginFileType] :: PluginDescriptor ideState -> [Text]
+ Ide.Types: [pluginLanguageIds] :: PluginDescriptor ideState -> [LanguageKind]
+ Ide.Types: getVirtualFileFromVFS :: VFS -> NormalizedUri -> Maybe VirtualFile
- Ide.PluginUtils: handlesRequest :: PluginMethod k m => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
+ Ide.PluginUtils: handlesRequest :: PluginMethod k m => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
- Ide.Types: ($dmhandlesRequest) :: (PluginMethod k m, HasTextDocument (MessageParams m) doc, HasUri doc Uri) => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
+ Ide.Types: ($dmhandlesRequest) :: (PluginMethod k m, HasTextDocument (MessageParams m) doc, HasUri doc Uri) => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
- Ide.Types: PluginDescriptor :: !PluginId -> !Text -> Natural -> !Rules () -> ![PluginCommand ideState] -> PluginHandlers ideState -> ConfigDescriptor -> PluginNotificationHandlers ideState -> DynFlagsModifications -> Maybe (ParserInfo (IdeCommand ideState)) -> [Text] -> PluginDescriptor ideState
+ Ide.Types: PluginDescriptor :: !PluginId -> !Text -> Natural -> !Rules () -> ![PluginCommand ideState] -> PluginHandlers ideState -> ConfigDescriptor -> PluginNotificationHandlers ideState -> DynFlagsModifications -> Maybe (ParserInfo (IdeCommand ideState)) -> [LanguageKind] -> PluginDescriptor ideState
- Ide.Types: handlesRequest :: PluginMethod k m => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
+ Ide.Types: handlesRequest :: PluginMethod k m => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult

Files

hls-plugin-api.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name:          hls-plugin-api-version:       2.13.0.0+version:       2.14.0.0 synopsis:      Haskell Language Server API for plugin communication description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -66,10 +66,10 @@     , filepath     , ghc     , hashable-    , hls-graph             == 2.13.0.0+    , hls-graph             == 2.14.0.0     , lens     , lens-aeson-    , lsp                   ^>=2.7+    , lsp                   ^>=2.8     , megaparsec            >=9.0     , mtl     , opentelemetry         >=0.4
src/Ide/Types.hs view
@@ -39,6 +39,7 @@ , PluginNotificationHandlers(..) , PluginRequestMethod(..) , getProcessID, getPid+, getVirtualFileFromVFS , installSigUsr1Handler , lookupCommandProvider , ResolveFunction@@ -94,13 +95,13 @@ import qualified Language.LSP.Protocol.Lens    as L import           Language.LSP.Protocol.Message import           Language.LSP.Protocol.Types+import qualified Language.LSP.Protocol.Types   as J import           Language.LSP.Server import           Language.LSP.VFS import           Numeric.Natural import           OpenTelemetry.Eventlog import           Options.Applicative           (ParserInfo) import           Prettyprinter                 as PP-import           System.FilePath import           System.IO.Unsafe import           Text.Regex.TDFA.Text          () import           UnliftIO                      (MonadUnliftIO)@@ -197,7 +198,6 @@     { checkParents                = CheckOnSave     , checkProject                = True     , formattingProvider          = "ormolu"-    -- , formattingProvider          = "floskell"     -- , formattingProvider          = "stylish-haskell"     , cabalFormattingProvider     = "cabal-gild"     -- , cabalFormattingProvider     = "cabal-fmt"@@ -326,7 +326,7 @@                    , pluginNotificationHandlers :: PluginNotificationHandlers ideState                    , pluginModifyDynflags :: DynFlagsModifications                    , pluginCli            :: Maybe (ParserInfo (IdeCommand ideState))-                   , pluginFileType       :: [T.Text]+                   , pluginLanguageIds    :: [J.LanguageKind]                    -- ^ File extension of the files the plugin is responsible for.                    --   The plugin is only allowed to handle files with these extensions.                    --   When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.@@ -419,14 +419,18 @@ -- We are passing the msgParams here even though we only need the URI URI here. -- If in the future we need to be able to provide only an URI it can be -- separated again.-pluginSupportsFileType :: (L.HasTextDocument m doc, L.HasUri doc Uri) => m -> PluginDescriptor c -> HandleRequestResult-pluginSupportsFileType msgParams pluginDesc =-  case mfp of-    Just fp | T.pack (takeExtension fp) `elem` pluginFileType pluginDesc -> HandlesRequest-    _ -> DoesNotHandleRequest $ DoesNotSupportFileType (maybe "(unable to determine file type)" (T.pack . takeExtension) mfp)+pluginSupportsFileType :: (L.HasTextDocument m doc, L.HasUri doc Uri) => VFS -> m -> PluginDescriptor c -> HandleRequestResult+pluginSupportsFileType (VFS vfs) msgParams pluginDesc =+  case languageKindM of+    Just languageKind | languageKind `elem` pluginLanguageIds pluginDesc -> HandlesRequest+    _ -> DoesNotHandleRequest $ DoesNotSupportFileType (maybe "(unable to determine file type)" (T.pack . show) languageKindM)     where-      mfp = uriToFilePath uri-      uri = msgParams ^. L.textDocument . L.uri+      mVFE = getVirtualFileFromVFSIncludingClosed (VFS vfs) uri+      uri = toNormalizedUri $ msgParams ^. L.textDocument . L.uri+      languageKindM =+        case mVFE of+          Just x -> virtualFileEntryLanguageKind x+          _      -> Nothing  -- | Methods that can be handled by plugins. -- 'ExtraParams' captures any extra data the IDE passes to the handlers for this method@@ -455,7 +459,9 @@   --   -- But there is no use to split it up into two different methods for now.   handlesRequest-    :: SMethod m+    :: VFS+    -- ^ The virtual file system, contains the language kind of the file.+    -> SMethod m     -- ^ Method type.     -> MessageParams m     -- ^ Whether a plugin is enabled might depend on the message parameters@@ -471,24 +477,24 @@     -- with the given parameters?    default handlesRequest :: (L.HasTextDocument (MessageParams m) doc, L.HasUri doc Uri)-                              => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult-  handlesRequest _ params desc conf =-    pluginEnabledGlobally desc conf <> pluginSupportsFileType params desc+                              => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult+  handlesRequest vfs _ params desc conf =+    pluginEnabledGlobally desc conf <> pluginSupportsFileType vfs params desc  -- | Check if a plugin is enabled, if one of it's specific config's is enabled, -- and if it supports the file pluginEnabledWithFeature :: (L.HasTextDocument (MessageParams m) doc, L.HasUri doc Uri)-                              => (PluginConfig -> Bool) -> SMethod m -> MessageParams m+                              => (PluginConfig -> Bool) -> VFS -> SMethod m -> MessageParams m                               -> PluginDescriptor c -> Config -> HandleRequestResult-pluginEnabledWithFeature feature _ msgParams pluginDesc config =+pluginEnabledWithFeature feature vfs _ msgParams pluginDesc config =   pluginEnabledGlobally pluginDesc config   <> pluginFeatureEnabled feature pluginDesc config-  <> pluginSupportsFileType msgParams pluginDesc+  <> pluginSupportsFileType vfs msgParams pluginDesc  -- | Check if a plugin is enabled, if one of it's specific configs is enabled, -- and if it's the plugin responsible for a resolve request.-pluginEnabledResolve :: L.HasData_ s (Maybe Value) => (PluginConfig -> Bool) -> p -> s -> PluginDescriptor c -> Config -> HandleRequestResult-pluginEnabledResolve feature _ msgParams pluginDesc config =+pluginEnabledResolve :: L.HasData_ s (Maybe Value) => (PluginConfig -> Bool) -> VFS -> p -> s -> PluginDescriptor c -> Config -> HandleRequestResult+pluginEnabledResolve feature _ _ msgParams pluginDesc config =     pluginEnabledGlobally pluginDesc config     <> pluginFeatureEnabled feature pluginDesc config     <> pluginResolverResponsible msgParams pluginDesc@@ -501,23 +507,23 @@   handlesRequest = pluginEnabledResolve plcCodeActionsOn  instance PluginMethod Request Method_TextDocumentDefinition where-  handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc+  handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc  instance PluginMethod Request Method_TextDocumentTypeDefinition where-  handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc+  handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc  instance PluginMethod Request Method_TextDocumentImplementation where-  handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc+  handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc  instance PluginMethod Request Method_TextDocumentDocumentHighlight where-  handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc+  handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc  instance PluginMethod Request Method_TextDocumentReferences where-  handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc+  handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc  instance PluginMethod Request Method_WorkspaceSymbol where   -- Unconditionally enabled, but should it really be?-  handlesRequest _ _ _ _ = HandlesRequest+  handlesRequest _ _ _ _ _ = HandlesRequest  instance PluginMethod Request Method_TextDocumentInlayHint where   handlesRequest = pluginEnabledWithFeature plcInlayHintsOn@@ -555,22 +561,22 @@   handlesRequest = pluginEnabledWithFeature plcCompletionOn  instance PluginMethod Request Method_TextDocumentFormatting where-  handlesRequest _ msgParams pluginDesc conf =+  handlesRequest vfs _ msgParams pluginDesc conf =     (if PluginId (formattingProvider conf) == pid           || PluginId (cabalFormattingProvider conf) == pid         then HandlesRequest         else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)) )-    <> pluginSupportsFileType msgParams pluginDesc+    <> pluginSupportsFileType vfs msgParams pluginDesc     where       pid = pluginId pluginDesc  instance PluginMethod Request Method_TextDocumentRangeFormatting where-  handlesRequest _ msgParams pluginDesc conf =+  handlesRequest vfs _ msgParams pluginDesc conf =     (if PluginId (formattingProvider conf) == pid           || PluginId (cabalFormattingProvider conf) == pid         then HandlesRequest         else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)))-    <> pluginSupportsFileType msgParams pluginDesc+    <> pluginSupportsFileType vfs msgParams pluginDesc     where       pid = pluginId pluginDesc @@ -591,21 +597,21 @@  instance PluginMethod Request Method_CallHierarchyIncomingCalls where   -- This method has no URI parameter, thus no call to 'pluginResponsible'-  handlesRequest _ _ pluginDesc conf =+  handlesRequest _ _ _ pluginDesc conf =       pluginEnabledGlobally pluginDesc conf     <> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf  instance PluginMethod Request Method_CallHierarchyOutgoingCalls where   -- This method has no URI parameter, thus no call to 'pluginResponsible'-  handlesRequest _ _ pluginDesc conf =+  handlesRequest _ _ _ pluginDesc conf =       pluginEnabledGlobally pluginDesc conf     <> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf  instance PluginMethod Request Method_WorkspaceExecuteCommand where-  handlesRequest _ _ _ _= HandlesRequest+  handlesRequest _ _ _ _ _ = HandlesRequest  instance PluginMethod Request (Method_CustomMethod m) where-  handlesRequest _ _ _ _ = HandlesRequest+  handlesRequest _ _ _ _ _ = HandlesRequest  -- Plugin Notifications @@ -619,19 +625,19 @@  instance PluginMethod Notification Method_WorkspaceDidChangeWatchedFiles where   -- This method has no URI parameter, thus no call to 'pluginResponsible'.-  handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf+  handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf  instance PluginMethod Notification Method_WorkspaceDidChangeWorkspaceFolders where   -- This method has no URI parameter, thus no call to 'pluginResponsible'.-  handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf+  handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf  instance PluginMethod Notification Method_WorkspaceDidChangeConfiguration where   -- This method has no URI parameter, thus no call to 'pluginResponsible'.-  handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf+  handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf  instance PluginMethod Notification Method_Initialized where   -- This method has no URI parameter, thus no call to 'pluginResponsible'.-  handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf+  handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf   -- ---------------------------------------------------------------------@@ -1063,7 +1069,7 @@     mempty     mempty     Nothing-    [".hs", ".lhs", ".hs-boot"]+    [J.LanguageKind_Haskell, J.LanguageKind_Custom "literate haskell"]  -- | Set up a plugin descriptor, initialized with default values. -- This plugin descriptor is prepared for @.cabal@ files and as such,@@ -1084,7 +1090,7 @@     mempty     mempty     Nothing-    [".cabal"]+    [J.LanguageKind_Custom "cabal"]  newtype CommandId = CommandId T.Text   deriving (Show, Read, Eq, Ord)@@ -1259,6 +1265,20 @@ -- and different from that of any other currently running instance. getPid :: IO T.Text getPid = T.pack . show <$> getProcessID++getVirtualFileFromVFS :: VFS -> NormalizedUri -> Maybe VirtualFile+getVirtualFileFromVFS (VFS vfs) uri =+  case Map.lookup uri vfs of+    Just (Open x)   -> Just x+    Just (Closed _) -> Nothing+    Nothing         -> Nothing++getVirtualFileFromVFSIncludingClosed :: VFS -> NormalizedUri -> Maybe VirtualFileEntry+getVirtualFileFromVFSIncludingClosed (VFS vfs) uri =+  case Map.lookup uri vfs of+    Just x  -> Just x+    Nothing -> Nothing+  getProcessID :: IO Int installSigUsr1Handler :: IO () -> IO ()