Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
Add more documenation and remove unused records
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Apr 13, 2019
1 parent e5713e0 commit 70baa51
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
22 changes: 9 additions & 13 deletions hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module Haskell.Ide.Engine.PluginsIdeMonads
, PublishDiagnosticsParams(..)
, List(..)
, FormattingOptions(..)
, FormatTextCmdParams(..)
)
where

Expand Down Expand Up @@ -208,24 +207,21 @@ type HoverProvider = Uri -> Position -> IdeM (IdeResult [Hover])

type SymbolProvider = Uri -> IdeDeferM (IdeResult [DocumentSymbol])

-- | Format Paramaters for Cmd.
-- Can be used to send messages to formatters
data FormatTextCmdParams = FormatTextCmdParams
{ fmtText :: T.Text -- ^ Text to format
, fmtResultRange :: Range -- ^ Range where the text will be inserted.
, fmtTextOptions :: FormattingOptions -- ^ Options for the formatter
}
deriving (Eq, Show, Generic, FromJSON, ToJSON)


-- | Format the document either as a whole or only a given Range of it.
data FormattingType = FormatDocument
| FormatRange Range

-- | Formats the given Uri with the given options.
-- | Formats the given Text associated with the given Uri.
-- Should, but might not, honor the provided formatting options (e.g. Floskell does not).
-- A formatting type can be given to either format the whole document or only a Range.
--
-- Text to format, may or may not, be from the associated Uri.
-- E.g. it is ok, to modify the text and then reformat it through this API.
--
-- The Uri is mainly used to discover formatting configurations in the file's path.
--
-- Fails if the formatter can not parse the source.
-- Failing menas here that a IdeResultFail is returned.
-- Failing means here that a IdeResultFail is returned.
-- This can be used to display errors to the user, unless the error is an Internal one.
-- The record 'IdeError' and 'IdeErrorCode' can be used to determine the type of error.
type FormattingProvider = T.Text -- ^ Text to format
Expand Down
8 changes: 1 addition & 7 deletions src/Haskell/Ide/Engine/Plugin/Brittany.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Haskell.Ide.Engine.Plugin.Brittany where

Expand All @@ -11,7 +9,6 @@ import Data.Coerce
import Data.Semigroup
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.PluginUtils
import Language.Haskell.Brittany
Expand All @@ -20,15 +17,12 @@ import qualified Language.Haskell.LSP.Types.Lens as J
import System.FilePath (FilePath, takeDirectory)
import Data.Maybe (maybeToList)

data FormatParams = FormatParams Int Uri (Maybe Range)
deriving (Eq, Show, Generic, FromJSON, ToJSON)

brittanyDescriptor :: PluginId -> PluginDescriptor
brittanyDescriptor plId = PluginDescriptor
{ pluginId = plId
, pluginName = "Brittany"
, pluginDesc = "Brittany is a tool to format source code."
, pluginCommands = [ ]
, pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
Expand Down
2 changes: 1 addition & 1 deletion src/Haskell/Ide/Engine/Plugin/Floskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ floskellDescriptor plId = PluginDescriptor
{ pluginId = plId
, pluginName = "Floskell"
, pluginDesc = "A flexible Haskell source code pretty printer."
, pluginCommands = []
, pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
Expand Down
23 changes: 17 additions & 6 deletions src/Haskell/Ide/Engine/Transport/LspStdio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,13 @@ reactor inp diagIn = do

-- ---------------------------------------------------------------------

-- | Execute a function in the current request with an Uri.
-- Reads the content of the file specified by the Uri and invokes
-- the function on it.
--
-- If the Uri can not be mapped to a real file, the function will
-- not be executed and an error message will be sent to the client.
-- Error message is associated with the request id and, thus, identifiable.
withDocumentContents :: J.LspId -> J.Uri -> (T.Text -> R ()) -> R ()
withDocumentContents reqId uri f = do
vfsFunc <- asksLspFuncs Core.getVirtualFileFunc
Expand All @@ -821,15 +828,19 @@ withDocumentContents reqId uri f = do
"Document was not open"
Just (VFS.VirtualFile _ txt) -> f (Yi.toText txt)

-- | Get the currently configured formatter provider.
-- The currently configured formatter provider is defined in @Config@ by PluginId.
--
-- It is possible that formatter configured by the user is not present.
-- In this case, a nop (No-Operation) formatter is returned and a message will
-- be sent to the user.
getFormattingProvider :: R FormattingProvider
getFormattingProvider = do
plugins <- asks idePlugins
lf <- asks lspFuncs
mc <- liftIO $ Core.config lf
let config = fromMaybe def mc
-- LL: Is this overengineered? Do we need a pluginFormattingProvider
-- or should we just call plugins straight from here based on the providerType?
providerName = formattingProvider config
config <- getClientConfig
-- LL: Is this overengineered? Do we need a pluginFormattingProvider
-- or should we just call plugins straight from here based on the providerType?
let providerName = formattingProvider config
mprovider = Hie.getFormattingPlugin config plugins
case mprovider of
Nothing -> do
Expand Down

0 comments on commit 70baa51

Please sign in to comment.