Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
Fix ambiguous plugin handler use
  • Loading branch information
Jana Chadt committed Jun 13, 2022
1 parent e95a904 commit f514d2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/LSP/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Development.IDE.LSP.Server
import Control.Monad.Reader
import Development.IDE.Core.Shake
import Development.IDE.Core.Tracing
import Ide.Types (HasTracing, traceWithSpan, PluginRequestMethod, PluginNotificationMethod)
import Ide.Types (HasTracing, traceWithSpan)
import Language.LSP.Server (Handlers, LspM)
import qualified Language.LSP.Server as LSP
import Language.LSP.Types
Expand Down
17 changes: 15 additions & 2 deletions hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ data PluginDescriptor (ideState :: *) =
, pluginNotificationHandlers :: PluginNotificationHandlers ideState
, pluginModifyDynflags :: DynFlagsModifications
, pluginCli :: Maybe (ParserInfo (IdeCommand ideState))
, pluginFileType :: [T.Text]
, pluginFileType :: [T.Text]
-- ^ 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.
-- The file extension must have a leading '.'.
}

-- | An existential wrapper of 'Properties'
Expand Down Expand Up @@ -165,7 +169,13 @@ defaultConfigDescriptor = ConfigDescriptor True False (mkCustomConfig emptyPrope
class HasTracing (MessageParams m) => PluginMethod (k :: MethodType) (m :: Method FromClient k) where

-- | Parse the configuration to check if this plugin is enabled
pluginEnabled :: SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
pluginEnabled
:: SMethod m
-> MessageParams m
-- ^
-> PluginDescriptor c
-> Config
-> Bool

default pluginEnabled :: (HasTextDocument (MessageParams m) doc, HasUri doc Uri)
=> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
Expand Down Expand Up @@ -220,6 +230,9 @@ instance PluginRequestMethod TextDocumentCodeAction where
, Just caKind <- ca ^. kind = any (\k -> k `codeActionKindSubsumes` caKind) allowed
| otherwise = False

-- | Check whether the given plugin descriptor is responsible for the file with the given path.
-- Compares the file extension of the file at the given path with the file extension
-- the plugin is responsible for.
pluginResponsible :: Uri -> PluginDescriptor c -> Bool
pluginResponsible uri pluginDesc
| Just fp <- mfp
Expand Down
5 changes: 2 additions & 3 deletions plugins/default/src/Ide/Plugin/ExampleCabal.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
Expand All @@ -15,7 +14,7 @@ module Ide.Plugin.ExampleCabal where
import Control.Monad.IO.Class
import Data.Aeson
import qualified Data.Text as T
import Development.IDE as D
import Development.IDE as D hiding (pluginHandlers)
import GHC.Generics
import Ide.PluginUtils
import Ide.Types
Expand All @@ -29,7 +28,7 @@ instance Pretty Log where
LogText log -> pretty log

descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor recorder plId = (defaultCabalPluginDescriptor plId)
descriptor recorder plId = (defaultCabalPluginDescriptor plId :: PluginDescriptor IdeState)
{ pluginHandlers = mkPluginHandler STextDocumentCodeLens (codeLens recorder)
}

Expand Down

0 comments on commit f514d2e

Please sign in to comment.