@@ -94,13 +94,13 @@ import Ide.Plugin.Properties
94
94
import qualified Language.LSP.Protocol.Lens as L
95
95
import Language.LSP.Protocol.Message
96
96
import Language.LSP.Protocol.Types
97
+ import qualified Language.LSP.Protocol.Types as J
97
98
import Language.LSP.Server
98
99
import Language.LSP.VFS
99
100
import Numeric.Natural
100
101
import OpenTelemetry.Eventlog
101
102
import Options.Applicative (ParserInfo )
102
103
import Prettyprinter as PP
103
- import System.FilePath
104
104
import System.IO.Unsafe
105
105
import Text.Regex.TDFA.Text ()
106
106
import UnliftIO (MonadUnliftIO )
@@ -323,7 +323,7 @@ data PluginDescriptor (ideState :: Type) =
323
323
, pluginNotificationHandlers :: PluginNotificationHandlers ideState
324
324
, pluginModifyDynflags :: DynFlagsModifications
325
325
, pluginCli :: Maybe (ParserInfo (IdeCommand ideState ))
326
- , pluginFileType :: [T. Text ]
326
+ , pluginLanguageIds :: [J. LanguageKind ]
327
327
-- ^ File extension of the files the plugin is responsible for.
328
328
-- The plugin is only allowed to handle files with these extensions.
329
329
-- 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
416
416
-- We are passing the msgParams here even though we only need the URI URI here.
417
417
-- If in the future we need to be able to provide only an URI it can be
418
418
-- 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 )
424
424
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
427
427
428
428
-- | Methods that can be handled by plugins.
429
429
-- '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
452
452
--
453
453
-- But there is no use to split it up into two different methods for now.
454
454
handlesRequest
455
- :: SMethod m
455
+ :: VFS
456
+ -- ^ The virtual file system, contains the language kind of the file.
457
+ -> SMethod m
456
458
-- ^ Method type.
457
459
-> MessageParams m
458
460
-- ^ Whether a plugin is enabled might depend on the message parameters
@@ -468,24 +470,24 @@ class HasTracing (MessageParams m) => PluginMethod (k :: MessageKind) (m :: Meth
468
470
-- with the given parameters?
469
471
470
472
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
474
476
475
477
-- | Check if a plugin is enabled, if one of it's specific config's is enabled,
476
478
-- and if it supports the file
477
479
pluginEnabledWithFeature :: (L. HasTextDocument (MessageParams m ) doc , L. HasUri doc Uri )
478
- => (PluginConfig -> Bool ) -> SMethod m -> MessageParams m
480
+ => (PluginConfig -> Bool ) -> VFS -> SMethod m -> MessageParams m
479
481
-> PluginDescriptor c -> Config -> HandleRequestResult
480
- pluginEnabledWithFeature feature _ msgParams pluginDesc config =
482
+ pluginEnabledWithFeature feature vfs _ msgParams pluginDesc config =
481
483
pluginEnabledGlobally pluginDesc config
482
484
<> pluginFeatureEnabled feature pluginDesc config
483
- <> pluginSupportsFileType msgParams pluginDesc
485
+ <> pluginSupportsFileType vfs msgParams pluginDesc
484
486
485
487
-- | Check if a plugin is enabled, if one of it's specific configs is enabled,
486
488
-- 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 =
489
491
pluginEnabledGlobally pluginDesc config
490
492
<> pluginFeatureEnabled feature pluginDesc config
491
493
<> pluginResolverResponsible msgParams pluginDesc
@@ -498,23 +500,23 @@ instance PluginMethod Request Method_CodeActionResolve where
498
500
handlesRequest = pluginEnabledResolve plcCodeActionsOn
499
501
500
502
instance PluginMethod Request Method_TextDocumentDefinition where
501
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
503
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
502
504
503
505
instance PluginMethod Request Method_TextDocumentTypeDefinition where
504
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
506
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
505
507
506
508
instance PluginMethod Request Method_TextDocumentImplementation where
507
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
509
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
508
510
509
511
instance PluginMethod Request Method_TextDocumentDocumentHighlight where
510
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
512
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
511
513
512
514
instance PluginMethod Request Method_TextDocumentReferences where
513
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
515
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
514
516
515
517
instance PluginMethod Request Method_WorkspaceSymbol where
516
518
-- Unconditionally enabled, but should it really be?
517
- handlesRequest _ _ _ _ = HandlesRequest
519
+ handlesRequest _ _ _ _ _ = HandlesRequest
518
520
519
521
instance PluginMethod Request Method_TextDocumentInlayHint where
520
522
handlesRequest = pluginEnabledWithFeature plcInlayHintsOn
@@ -549,22 +551,22 @@ instance PluginMethod Request Method_TextDocumentCompletion where
549
551
handlesRequest = pluginEnabledWithFeature plcCompletionOn
550
552
551
553
instance PluginMethod Request Method_TextDocumentFormatting where
552
- handlesRequest _ msgParams pluginDesc conf =
554
+ handlesRequest vfs _ msgParams pluginDesc conf =
553
555
(if PluginId (formattingProvider conf) == pid
554
556
|| PluginId (cabalFormattingProvider conf) == pid
555
557
then HandlesRequest
556
558
else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)) )
557
- <> pluginSupportsFileType msgParams pluginDesc
559
+ <> pluginSupportsFileType vfs msgParams pluginDesc
558
560
where
559
561
pid = pluginId pluginDesc
560
562
561
563
instance PluginMethod Request Method_TextDocumentRangeFormatting where
562
- handlesRequest _ msgParams pluginDesc conf =
564
+ handlesRequest vfs _ msgParams pluginDesc conf =
563
565
(if PluginId (formattingProvider conf) == pid
564
566
|| PluginId (cabalFormattingProvider conf) == pid
565
567
then HandlesRequest
566
568
else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)))
567
- <> pluginSupportsFileType msgParams pluginDesc
569
+ <> pluginSupportsFileType vfs msgParams pluginDesc
568
570
where
569
571
pid = pluginId pluginDesc
570
572
@@ -585,21 +587,21 @@ instance PluginMethod Request Method_TextDocumentFoldingRange where
585
587
586
588
instance PluginMethod Request Method_CallHierarchyIncomingCalls where
587
589
-- This method has no URI parameter, thus no call to 'pluginResponsible'
588
- handlesRequest _ _ pluginDesc conf =
590
+ handlesRequest _ _ _ pluginDesc conf =
589
591
pluginEnabledGlobally pluginDesc conf
590
592
<> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
591
593
592
594
instance PluginMethod Request Method_CallHierarchyOutgoingCalls where
593
595
-- This method has no URI parameter, thus no call to 'pluginResponsible'
594
- handlesRequest _ _ pluginDesc conf =
596
+ handlesRequest _ _ _ pluginDesc conf =
595
597
pluginEnabledGlobally pluginDesc conf
596
598
<> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
597
599
598
600
instance PluginMethod Request Method_WorkspaceExecuteCommand where
599
- handlesRequest _ _ _ _= HandlesRequest
601
+ handlesRequest _ _ _ _ _ = HandlesRequest
600
602
601
603
instance PluginMethod Request (Method_CustomMethod m ) where
602
- handlesRequest _ _ _ _ = HandlesRequest
604
+ handlesRequest _ _ _ _ _ = HandlesRequest
603
605
604
606
-- Plugin Notifications
605
607
@@ -613,19 +615,19 @@ instance PluginMethod Notification Method_TextDocumentDidClose where
613
615
614
616
instance PluginMethod Notification Method_WorkspaceDidChangeWatchedFiles where
615
617
-- 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
617
619
618
620
instance PluginMethod Notification Method_WorkspaceDidChangeWorkspaceFolders where
619
621
-- 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
621
623
622
624
instance PluginMethod Notification Method_WorkspaceDidChangeConfiguration where
623
625
-- 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
625
627
626
628
instance PluginMethod Notification Method_Initialized where
627
629
-- 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
629
631
630
632
631
633
-- ---------------------------------------------------------------------
@@ -1054,7 +1056,7 @@ defaultPluginDescriptor plId desc =
1054
1056
mempty
1055
1057
mempty
1056
1058
Nothing
1057
- [" .hs " , " .lhs " , " .hs-boot " ]
1059
+ [J. LanguageKind_Haskell , J. LanguageKind_Custom " literate haskell " ]
1058
1060
1059
1061
-- | Set up a plugin descriptor, initialized with default values.
1060
1062
-- This plugin descriptor is prepared for @.cabal@ files and as such,
@@ -1075,7 +1077,7 @@ defaultCabalPluginDescriptor plId desc =
1075
1077
mempty
1076
1078
mempty
1077
1079
Nothing
1078
- [" . cabal" ]
1080
+ [J. LanguageKind_Custom " cabal" ]
1079
1081
1080
1082
newtype CommandId = CommandId T. Text
1081
1083
deriving (Show , Read , Eq , Ord )
0 commit comments