@@ -94,13 +94,13 @@ import Ide.Plugin.Properties
9494import qualified Language.LSP.Protocol.Lens as L
9595import Language.LSP.Protocol.Message
9696import Language.LSP.Protocol.Types
97+ import qualified Language.LSP.Protocol.Types as J
9798import Language.LSP.Server
9899import Language.LSP.VFS
99100import Numeric.Natural
100101import OpenTelemetry.Eventlog
101102import Options.Applicative (ParserInfo )
102103import Prettyprinter as PP
103- import System.FilePath
104104import System.IO.Unsafe
105105import Text.Regex.TDFA.Text ()
106106import UnliftIO (MonadUnliftIO )
@@ -323,7 +323,7 @@ data PluginDescriptor (ideState :: Type) =
323323 , pluginNotificationHandlers :: PluginNotificationHandlers ideState
324324 , pluginModifyDynflags :: DynFlagsModifications
325325 , pluginCli :: Maybe (ParserInfo (IdeCommand ideState ))
326- , pluginFileType :: [T. Text ]
326+ , pluginLanguageIds :: [J. LanguageKind ]
327327 -- ^ File extension of the files the plugin is responsible for.
328328 -- The plugin is only allowed to handle files with these extensions.
329329 -- When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.
@@ -416,14 +416,14 @@ pluginResolverResponsible _ _ = DoesNotHandleRequest $ NotResolveOwner "(unable
416416-- We are passing the msgParams here even though we only need the URI URI here.
417417-- If in the future we need to be able to provide only an URI it can be
418418-- separated again.
419- pluginSupportsFileType :: (L. HasTextDocument m doc , L. HasUri doc Uri ) => m -> PluginDescriptor c -> HandleRequestResult
420- pluginSupportsFileType msgParams pluginDesc =
421- case mfp of
422- Just fp | T. pack (takeExtension fp) `elem` pluginFileType pluginDesc -> HandlesRequest
423- _ -> DoesNotHandleRequest $ DoesNotSupportFileType (maybe " (unable to determine file type)" (T. pack . takeExtension) mfp )
419+ pluginSupportsFileType :: (L. HasTextDocument m doc , L. HasUri doc Uri ) => VFS -> m -> PluginDescriptor c -> HandleRequestResult
420+ pluginSupportsFileType ( VFS vfs) msgParams pluginDesc =
421+ case _language_id =<< mVFS of
422+ Just languageKind | languageKind `elem` pluginLanguageIds pluginDesc -> HandlesRequest
423+ _ -> DoesNotHandleRequest $ DoesNotSupportFileType (maybe " (unable to determine file type)" (T. pack . show ) $ _language_id =<< mVFS )
424424 where
425- mfp = uriToFilePath uri
426- uri = msgParams ^. L. textDocument . L. uri
425+ mVFS = Map. lookup uri vfs
426+ uri = toNormalizedUri $ msgParams ^. L. textDocument . L. uri
427427
428428-- | Methods that can be handled by plugins.
429429-- 'ExtraParams' captures any extra data the IDE passes to the handlers for this method
@@ -452,7 +452,9 @@ class HasTracing (MessageParams m) => PluginMethod (k :: MessageKind) (m :: Meth
452452 --
453453 -- But there is no use to split it up into two different methods for now.
454454 handlesRequest
455- :: SMethod m
455+ :: VFS
456+ -- ^ The virtual file system, contains the language kind of the file.
457+ -> SMethod m
456458 -- ^ Method type.
457459 -> MessageParams m
458460 -- ^ Whether a plugin is enabled might depend on the message parameters
@@ -468,24 +470,24 @@ class HasTracing (MessageParams m) => PluginMethod (k :: MessageKind) (m :: Meth
468470 -- with the given parameters?
469471
470472 default handlesRequest :: (L. HasTextDocument (MessageParams m ) doc , L. HasUri doc Uri )
471- => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
472- handlesRequest _ params desc conf =
473- pluginEnabledGlobally desc conf <> pluginSupportsFileType params desc
473+ => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
474+ handlesRequest vfs _ params desc conf =
475+ pluginEnabledGlobally desc conf <> pluginSupportsFileType vfs params desc
474476
475477-- | Check if a plugin is enabled, if one of it's specific config's is enabled,
476478-- and if it supports the file
477479pluginEnabledWithFeature :: (L. HasTextDocument (MessageParams m ) doc , L. HasUri doc Uri )
478- => (PluginConfig -> Bool ) -> SMethod m -> MessageParams m
480+ => (PluginConfig -> Bool ) -> VFS -> SMethod m -> MessageParams m
479481 -> PluginDescriptor c -> Config -> HandleRequestResult
480- pluginEnabledWithFeature feature _ msgParams pluginDesc config =
482+ pluginEnabledWithFeature feature vfs _ msgParams pluginDesc config =
481483 pluginEnabledGlobally pluginDesc config
482484 <> pluginFeatureEnabled feature pluginDesc config
483- <> pluginSupportsFileType msgParams pluginDesc
485+ <> pluginSupportsFileType vfs msgParams pluginDesc
484486
485487-- | Check if a plugin is enabled, if one of it's specific configs is enabled,
486488-- and if it's the plugin responsible for a resolve request.
487- pluginEnabledResolve :: L. HasData_ s (Maybe Value ) => (PluginConfig -> Bool ) -> p -> s -> PluginDescriptor c -> Config -> HandleRequestResult
488- pluginEnabledResolve feature _ msgParams pluginDesc config =
489+ pluginEnabledResolve :: L. HasData_ s (Maybe Value ) => (PluginConfig -> Bool ) -> VFS -> p -> s -> PluginDescriptor c -> Config -> HandleRequestResult
490+ pluginEnabledResolve feature _ _ msgParams pluginDesc config =
489491 pluginEnabledGlobally pluginDesc config
490492 <> pluginFeatureEnabled feature pluginDesc config
491493 <> pluginResolverResponsible msgParams pluginDesc
@@ -498,23 +500,23 @@ instance PluginMethod Request Method_CodeActionResolve where
498500 handlesRequest = pluginEnabledResolve plcCodeActionsOn
499501
500502instance PluginMethod Request Method_TextDocumentDefinition where
501- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
503+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
502504
503505instance PluginMethod Request Method_TextDocumentTypeDefinition where
504- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
506+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
505507
506508instance PluginMethod Request Method_TextDocumentImplementation where
507- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
509+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
508510
509511instance PluginMethod Request Method_TextDocumentDocumentHighlight where
510- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
512+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
511513
512514instance PluginMethod Request Method_TextDocumentReferences where
513- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
515+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
514516
515517instance PluginMethod Request Method_WorkspaceSymbol where
516518 -- Unconditionally enabled, but should it really be?
517- handlesRequest _ _ _ _ = HandlesRequest
519+ handlesRequest _ _ _ _ _ = HandlesRequest
518520
519521instance PluginMethod Request Method_TextDocumentInlayHint where
520522 handlesRequest = pluginEnabledWithFeature plcInlayHintsOn
@@ -549,22 +551,22 @@ instance PluginMethod Request Method_TextDocumentCompletion where
549551 handlesRequest = pluginEnabledWithFeature plcCompletionOn
550552
551553instance PluginMethod Request Method_TextDocumentFormatting where
552- handlesRequest _ msgParams pluginDesc conf =
554+ handlesRequest vfs _ msgParams pluginDesc conf =
553555 (if PluginId (formattingProvider conf) == pid
554556 || PluginId (cabalFormattingProvider conf) == pid
555557 then HandlesRequest
556558 else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)) )
557- <> pluginSupportsFileType msgParams pluginDesc
559+ <> pluginSupportsFileType vfs msgParams pluginDesc
558560 where
559561 pid = pluginId pluginDesc
560562
561563instance PluginMethod Request Method_TextDocumentRangeFormatting where
562- handlesRequest _ msgParams pluginDesc conf =
564+ handlesRequest vfs _ msgParams pluginDesc conf =
563565 (if PluginId (formattingProvider conf) == pid
564566 || PluginId (cabalFormattingProvider conf) == pid
565567 then HandlesRequest
566568 else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)))
567- <> pluginSupportsFileType msgParams pluginDesc
569+ <> pluginSupportsFileType vfs msgParams pluginDesc
568570 where
569571 pid = pluginId pluginDesc
570572
@@ -585,21 +587,21 @@ instance PluginMethod Request Method_TextDocumentFoldingRange where
585587
586588instance PluginMethod Request Method_CallHierarchyIncomingCalls where
587589 -- This method has no URI parameter, thus no call to 'pluginResponsible'
588- handlesRequest _ _ pluginDesc conf =
590+ handlesRequest _ _ _ pluginDesc conf =
589591 pluginEnabledGlobally pluginDesc conf
590592 <> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
591593
592594instance PluginMethod Request Method_CallHierarchyOutgoingCalls where
593595 -- This method has no URI parameter, thus no call to 'pluginResponsible'
594- handlesRequest _ _ pluginDesc conf =
596+ handlesRequest _ _ _ pluginDesc conf =
595597 pluginEnabledGlobally pluginDesc conf
596598 <> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
597599
598600instance PluginMethod Request Method_WorkspaceExecuteCommand where
599- handlesRequest _ _ _ _= HandlesRequest
601+ handlesRequest _ _ _ _ _ = HandlesRequest
600602
601603instance PluginMethod Request (Method_CustomMethod m ) where
602- handlesRequest _ _ _ _ = HandlesRequest
604+ handlesRequest _ _ _ _ _ = HandlesRequest
603605
604606-- Plugin Notifications
605607
@@ -613,19 +615,19 @@ instance PluginMethod Notification Method_TextDocumentDidClose where
613615
614616instance PluginMethod Notification Method_WorkspaceDidChangeWatchedFiles where
615617 -- This method has no URI parameter, thus no call to 'pluginResponsible'.
616- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
618+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
617619
618620instance PluginMethod Notification Method_WorkspaceDidChangeWorkspaceFolders where
619621 -- This method has no URI parameter, thus no call to 'pluginResponsible'.
620- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
622+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
621623
622624instance PluginMethod Notification Method_WorkspaceDidChangeConfiguration where
623625 -- This method has no URI parameter, thus no call to 'pluginResponsible'.
624- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
626+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
625627
626628instance PluginMethod Notification Method_Initialized where
627629 -- This method has no URI parameter, thus no call to 'pluginResponsible'.
628- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
630+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
629631
630632
631633-- ---------------------------------------------------------------------
@@ -1054,7 +1056,7 @@ defaultPluginDescriptor plId desc =
10541056 mempty
10551057 mempty
10561058 Nothing
1057- [" .hs " , " .lhs " , " .hs-boot " ]
1059+ [J. LanguageKind_Haskell , J. LanguageKind_Custom " literate haskell " ]
10581060
10591061-- | Set up a plugin descriptor, initialized with default values.
10601062-- This plugin descriptor is prepared for @.cabal@ files and as such,
@@ -1075,7 +1077,7 @@ defaultCabalPluginDescriptor plId desc =
10751077 mempty
10761078 mempty
10771079 Nothing
1078- [" . cabal" ]
1080+ [J. LanguageKind_Custom " cabal" ]
10791081
10801082newtype CommandId = CommandId T. Text
10811083 deriving (Show , Read , Eq , Ord )
0 commit comments