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

Commit 7ef6e4b

Browse files
committed
Add more documenation and remove unused records
1 parent e5713e0 commit 7ef6e4b

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ module Haskell.Ide.Engine.PluginsIdeMonads
7474
, PublishDiagnosticsParams(..)
7575
, List(..)
7676
, FormattingOptions(..)
77-
, FormatTextCmdParams(..)
7877
)
7978
where
8079

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

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

211-
-- | Format Paramaters for Cmd.
212-
-- Can be used to send messages to formatters
213-
data FormatTextCmdParams = FormatTextCmdParams
214-
{ fmtText :: T.Text -- ^ Text to format
215-
, fmtResultRange :: Range -- ^ Range where the text will be inserted.
216-
, fmtTextOptions :: FormattingOptions -- ^ Options for the formatter
217-
}
218-
deriving (Eq, Show, Generic, FromJSON, ToJSON)
219-
220-
221210
-- | Format the document either as a whole or only a given Range of it.
222211
data FormattingType = FormatDocument
223212
| FormatRange Range
224213

225-
-- | Formats the given Uri with the given options.
214+
-- | Formats the given Text associated with the given Uri.
215+
-- Should, but might not, honor the provided formatting options (e.g. Floskell does not).
226216
-- A formatting type can be given to either format the whole document or only a Range.
217+
--
218+
-- Text to format, may or may not, originate from the associated Uri.
219+
-- E.g. it is ok, to modify the text and then reformat it through this API.
220+
--
221+
-- The Uri is mainly used to discover formatting configurations in the file's path.
222+
--
227223
-- Fails if the formatter can not parse the source.
228-
-- Failing menas here that a IdeResultFail is returned.
224+
-- Failing means here that a IdeResultFail is returned.
229225
-- This can be used to display errors to the user, unless the error is an Internal one.
230226
-- The record 'IdeError' and 'IdeErrorCode' can be used to determine the type of error.
231227
type FormattingProvider = T.Text -- ^ Text to format

src/Haskell/Ide/Engine/Plugin/Brittany.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE DeriveAnyClass #-}
2-
{-# LANGUAGE DeriveGeneric #-}
31
{-# LANGUAGE OverloadedStrings #-}
42
module Haskell.Ide.Engine.Plugin.Brittany where
53

@@ -11,7 +9,6 @@ import Data.Coerce
119
import Data.Semigroup
1210
import Data.Text (Text)
1311
import qualified Data.Text as T
14-
import GHC.Generics
1512
import Haskell.Ide.Engine.MonadTypes
1613
import Haskell.Ide.Engine.PluginUtils
1714
import Language.Haskell.Brittany
@@ -20,15 +17,12 @@ import qualified Language.Haskell.LSP.Types.Lens as J
2017
import System.FilePath (FilePath, takeDirectory)
2118
import Data.Maybe (maybeToList)
2219

23-
data FormatParams = FormatParams Int Uri (Maybe Range)
24-
deriving (Eq, Show, Generic, FromJSON, ToJSON)
25-
2620
brittanyDescriptor :: PluginId -> PluginDescriptor
2721
brittanyDescriptor plId = PluginDescriptor
2822
{ pluginId = plId
2923
, pluginName = "Brittany"
3024
, pluginDesc = "Brittany is a tool to format source code."
31-
, pluginCommands = [ ]
25+
, pluginCommands = []
3226
, pluginCodeActionProvider = Nothing
3327
, pluginDiagnosticProvider = Nothing
3428
, pluginHoverProvider = Nothing

src/Haskell/Ide/Engine/Plugin/Floskell.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ floskellDescriptor plId = PluginDescriptor
1919
{ pluginId = plId
2020
, pluginName = "Floskell"
2121
, pluginDesc = "A flexible Haskell source code pretty printer."
22-
, pluginCommands = []
22+
, pluginCommands = []
2323
, pluginCodeActionProvider = Nothing
2424
, pluginDiagnosticProvider = Nothing
2525
, pluginHoverProvider = Nothing

src/Haskell/Ide/Engine/Transport/LspStdio.hs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,13 @@ reactor inp diagIn = do
808808

809809
-- ---------------------------------------------------------------------
810810

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

831+
-- | Get the currently configured formatter provider.
832+
-- The currently configured formatter provider is defined in @Config@ by PluginId.
833+
--
834+
-- It is possible that formatter configured by the user is not present.
835+
-- In this case, a nop (No-Operation) formatter is returned and a message will
836+
-- be sent to the user.
824837
getFormattingProvider :: R FormattingProvider
825838
getFormattingProvider = do
826839
plugins <- asks idePlugins
827-
lf <- asks lspFuncs
828-
mc <- liftIO $ Core.config lf
829-
let config = fromMaybe def mc
830-
-- LL: Is this overengineered? Do we need a pluginFormattingProvider
831-
-- or should we just call plugins straight from here based on the providerType?
832-
providerName = formattingProvider config
840+
config <- getClientConfig
841+
-- LL: Is this overengineered? Do we need a pluginFormattingProvider
842+
-- or should we just call plugins straight from here based on the providerType?
843+
let providerName = formattingProvider config
833844
mprovider = Hie.getFormattingPlugin config plugins
834845
case mprovider of
835846
Nothing -> do

0 commit comments

Comments
 (0)