@@ -94,6 +94,7 @@ 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
@@ -323,7 +324,7 @@ data PluginDescriptor (ideState :: Type) =
323
324
, pluginNotificationHandlers :: PluginNotificationHandlers ideState
324
325
, pluginModifyDynflags :: DynFlagsModifications
325
326
, pluginCli :: Maybe (ParserInfo (IdeCommand ideState ))
326
- , pluginFileType :: [T. Text ]
327
+ , pluginLanguageIds :: [J. LanguageKind ]
327
328
-- ^ File extension of the files the plugin is responsible for.
328
329
-- The plugin is only allowed to handle files with these extensions.
329
330
-- When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.
@@ -416,14 +417,14 @@ pluginResolverResponsible _ _ = DoesNotHandleRequest $ NotResolveOwner "(unable
416
417
-- We are passing the msgParams here even though we only need the URI URI here.
417
418
-- If in the future we need to be able to provide only an URI it can be
418
419
-- 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 )
420
+ pluginSupportsFileType :: (L. HasTextDocument m doc , L. HasUri doc Uri ) => VFS -> m -> PluginDescriptor c -> HandleRequestResult
421
+ pluginSupportsFileType ( VFS vfs) msgParams pluginDesc =
422
+ case _language_id =<< mVFS of
423
+ Just languageKind | languageKind `elem` pluginLanguageIds pluginDesc -> HandlesRequest
424
+ _ -> DoesNotHandleRequest $ DoesNotSupportFileType (maybe " (unable to determine file type)" (T. pack . show ) $ _language_id =<< mVFS )
424
425
where
425
- mfp = uriToFilePath uri
426
- uri = msgParams ^. L. textDocument . L. uri
426
+ mVFS = Map. lookup uri vfs
427
+ uri = toNormalizedUri $ msgParams ^. L. textDocument . L. uri
427
428
428
429
-- | Methods that can be handled by plugins.
429
430
-- 'ExtraParams' captures any extra data the IDE passes to the handlers for this method
@@ -452,7 +453,9 @@ class HasTracing (MessageParams m) => PluginMethod (k :: MessageKind) (m :: Meth
452
453
--
453
454
-- But there is no use to split it up into two different methods for now.
454
455
handlesRequest
455
- :: SMethod m
456
+ :: VFS
457
+ -- ^ The virtual file system, contains the language kind of the file.
458
+ -> SMethod m
456
459
-- ^ Method type.
457
460
-> MessageParams m
458
461
-- ^ Whether a plugin is enabled might depend on the message parameters
@@ -468,24 +471,24 @@ class HasTracing (MessageParams m) => PluginMethod (k :: MessageKind) (m :: Meth
468
471
-- with the given parameters?
469
472
470
473
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
474
+ => VFS -> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
475
+ handlesRequest vfs _ params desc conf =
476
+ pluginEnabledGlobally desc conf <> pluginSupportsFileType vfs params desc
474
477
475
478
-- | Check if a plugin is enabled, if one of it's specific config's is enabled,
476
479
-- and if it supports the file
477
480
pluginEnabledWithFeature :: (L. HasTextDocument (MessageParams m ) doc , L. HasUri doc Uri )
478
- => (PluginConfig -> Bool ) -> SMethod m -> MessageParams m
481
+ => (PluginConfig -> Bool ) -> VFS -> SMethod m -> MessageParams m
479
482
-> PluginDescriptor c -> Config -> HandleRequestResult
480
- pluginEnabledWithFeature feature _ msgParams pluginDesc config =
483
+ pluginEnabledWithFeature feature vfs _ msgParams pluginDesc config =
481
484
pluginEnabledGlobally pluginDesc config
482
485
<> pluginFeatureEnabled feature pluginDesc config
483
- <> pluginSupportsFileType msgParams pluginDesc
486
+ <> pluginSupportsFileType vfs msgParams pluginDesc
484
487
485
488
-- | Check if a plugin is enabled, if one of it's specific configs is enabled,
486
489
-- 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 =
490
+ pluginEnabledResolve :: L. HasData_ s (Maybe Value ) => (PluginConfig -> Bool ) -> VFS -> p -> s -> PluginDescriptor c -> Config -> HandleRequestResult
491
+ pluginEnabledResolve feature _ _ msgParams pluginDesc config =
489
492
pluginEnabledGlobally pluginDesc config
490
493
<> pluginFeatureEnabled feature pluginDesc config
491
494
<> pluginResolverResponsible msgParams pluginDesc
@@ -498,23 +501,23 @@ instance PluginMethod Request Method_CodeActionResolve where
498
501
handlesRequest = pluginEnabledResolve plcCodeActionsOn
499
502
500
503
instance PluginMethod Request Method_TextDocumentDefinition where
501
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
504
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
502
505
503
506
instance PluginMethod Request Method_TextDocumentTypeDefinition where
504
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
507
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
505
508
506
509
instance PluginMethod Request Method_TextDocumentImplementation where
507
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
510
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
508
511
509
512
instance PluginMethod Request Method_TextDocumentDocumentHighlight where
510
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
513
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
511
514
512
515
instance PluginMethod Request Method_TextDocumentReferences where
513
- handlesRequest _ msgParams pluginDesc _ = pluginSupportsFileType msgParams pluginDesc
516
+ handlesRequest vfs _ msgParams pluginDesc _ = pluginSupportsFileType vfs msgParams pluginDesc
514
517
515
518
instance PluginMethod Request Method_WorkspaceSymbol where
516
519
-- Unconditionally enabled, but should it really be?
517
- handlesRequest _ _ _ _ = HandlesRequest
520
+ handlesRequest _ _ _ _ _ = HandlesRequest
518
521
519
522
instance PluginMethod Request Method_TextDocumentInlayHint where
520
523
handlesRequest = pluginEnabledWithFeature plcInlayHintsOn
@@ -549,22 +552,22 @@ instance PluginMethod Request Method_TextDocumentCompletion where
549
552
handlesRequest = pluginEnabledWithFeature plcCompletionOn
550
553
551
554
instance PluginMethod Request Method_TextDocumentFormatting where
552
- handlesRequest _ msgParams pluginDesc conf =
555
+ handlesRequest vfs _ msgParams pluginDesc conf =
553
556
(if PluginId (formattingProvider conf) == pid
554
557
|| PluginId (cabalFormattingProvider conf) == pid
555
558
then HandlesRequest
556
559
else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)) )
557
- <> pluginSupportsFileType msgParams pluginDesc
560
+ <> pluginSupportsFileType vfs msgParams pluginDesc
558
561
where
559
562
pid = pluginId pluginDesc
560
563
561
564
instance PluginMethod Request Method_TextDocumentRangeFormatting where
562
- handlesRequest _ msgParams pluginDesc conf =
565
+ handlesRequest vfs _ msgParams pluginDesc conf =
563
566
(if PluginId (formattingProvider conf) == pid
564
567
|| PluginId (cabalFormattingProvider conf) == pid
565
568
then HandlesRequest
566
569
else DoesNotHandleRequest (NotFormattingProvider (formattingProvider conf)))
567
- <> pluginSupportsFileType msgParams pluginDesc
570
+ <> pluginSupportsFileType vfs msgParams pluginDesc
568
571
where
569
572
pid = pluginId pluginDesc
570
573
@@ -585,21 +588,21 @@ instance PluginMethod Request Method_TextDocumentFoldingRange where
585
588
586
589
instance PluginMethod Request Method_CallHierarchyIncomingCalls where
587
590
-- This method has no URI parameter, thus no call to 'pluginResponsible'
588
- handlesRequest _ _ pluginDesc conf =
591
+ handlesRequest _ _ _ pluginDesc conf =
589
592
pluginEnabledGlobally pluginDesc conf
590
593
<> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
591
594
592
595
instance PluginMethod Request Method_CallHierarchyOutgoingCalls where
593
596
-- This method has no URI parameter, thus no call to 'pluginResponsible'
594
- handlesRequest _ _ pluginDesc conf =
597
+ handlesRequest _ _ _ pluginDesc conf =
595
598
pluginEnabledGlobally pluginDesc conf
596
599
<> pluginFeatureEnabled plcCallHierarchyOn pluginDesc conf
597
600
598
601
instance PluginMethod Request Method_WorkspaceExecuteCommand where
599
- handlesRequest _ _ _ _= HandlesRequest
602
+ handlesRequest _ _ _ _ _ = HandlesRequest
600
603
601
604
instance PluginMethod Request (Method_CustomMethod m ) where
602
- handlesRequest _ _ _ _ = HandlesRequest
605
+ handlesRequest _ _ _ _ _ = HandlesRequest
603
606
604
607
-- Plugin Notifications
605
608
@@ -613,19 +616,19 @@ instance PluginMethod Notification Method_TextDocumentDidClose where
613
616
614
617
instance PluginMethod Notification Method_WorkspaceDidChangeWatchedFiles where
615
618
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
616
- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
619
+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
617
620
618
621
instance PluginMethod Notification Method_WorkspaceDidChangeWorkspaceFolders where
619
622
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
620
- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
623
+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
621
624
622
625
instance PluginMethod Notification Method_WorkspaceDidChangeConfiguration where
623
626
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
624
- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
627
+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
625
628
626
629
instance PluginMethod Notification Method_Initialized where
627
630
-- This method has no URI parameter, thus no call to 'pluginResponsible'.
628
- handlesRequest _ _ desc conf = pluginEnabledGlobally desc conf
631
+ handlesRequest _ _ _ desc conf = pluginEnabledGlobally desc conf
629
632
630
633
631
634
-- ---------------------------------------------------------------------
@@ -1054,7 +1057,7 @@ defaultPluginDescriptor plId desc =
1054
1057
mempty
1055
1058
mempty
1056
1059
Nothing
1057
- [" .hs " , " .lhs " , " .hs-boot " ]
1060
+ [J. LanguageKind_Haskell , J. LanguageKind_Custom " literate haskell " ]
1058
1061
1059
1062
-- | Set up a plugin descriptor, initialized with default values.
1060
1063
-- This plugin descriptor is prepared for @.cabal@ files and as such,
@@ -1075,7 +1078,7 @@ defaultCabalPluginDescriptor plId desc =
1075
1078
mempty
1076
1079
mempty
1077
1080
Nothing
1078
- [" . cabal" ]
1081
+ [J. LanguageKind_Custom " cabal" ]
1079
1082
1080
1083
newtype CommandId = CommandId T. Text
1081
1084
deriving (Show , Read , Eq , Ord )
0 commit comments