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

Commit dad1635

Browse files
authored
Merge pull request #1165 from fendor/document-formatters
Document formatters
2 parents 4c64789 + 21f0fdb commit dad1635

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,20 @@ type HoverProvider = Uri -> Position -> IdeM (IdeResult [Hover])
208208

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

211+
-- | Format the document either as a whole or only a given Range of it.
211212
data FormattingType = FormatDocument
212213
| FormatRange Range
213-
type FormattingProvider = Uri -> FormattingType -> FormattingOptions -> IdeDeferM (IdeResult [TextEdit])
214+
215+
-- | Formats the given Uri with the given options.
216+
-- A formatting type can be given to either format the whole document or only a Range.
217+
-- Fails if the formatter can not parse the source.
218+
-- Failing menas here that a IdeResultFail is returned.
219+
-- This can be used to display errors to the user, unless the error is an Internal one.
220+
-- The record 'IdeError' and 'IdeErrorCode' can be used to determine the type of error.
221+
type FormattingProvider = Uri -- ^ Uri to the file to format. Can be mapped to a file with `pluginGetFile`
222+
-> FormattingType -- ^ How much to format
223+
-> FormattingOptions -- ^ Options for the formatter
224+
-> IdeDeferM (IdeResult [TextEdit]) -- ^ Result of the formatting or the unchanged text.
214225

215226
data PluginDescriptor =
216227
PluginDescriptor { pluginId :: PluginId

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

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ brittanyDescriptor plId = PluginDescriptor
3636
, pluginFormattingProvider = Just provider
3737
}
3838

39+
-- | Formatter provider of Brittany.
40+
-- Formats the given source in either a given Range or the whole Document.
41+
-- If the provider fails an error is returned that can be displayed to the user.
3942
provider :: FormattingProvider
4043
provider uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \file -> do
4144
confFile <- liftIO $ getConfFile file
@@ -65,6 +68,8 @@ normalize (Range (Position sl _) (Position el _)) =
6568
-- Extend to the line below to replace newline character, as above
6669
Range (Position sl 0) (Position (el + 1) 0)
6770

71+
-- | Recursively search in every directory of the given filepath for brittany.yaml
72+
-- If no such file has been found, return Nothing.
6873
getConfFile :: FilePath -> IO (Maybe FilePath)
6974
getConfFile = findLocalConfigPath . takeDirectory
7075

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ floskellDescriptor plId = PluginDescriptor
2727
, pluginFormattingProvider = Just provider
2828
}
2929

30+
-- | Format provider of Floskell.
31+
-- Formats the given source in either a given Range or the whole Document.
32+
-- If the provider fails an error is returned that can be displayed to the user.
3033
provider :: FormattingProvider
3134
provider uri typ _opts =
3235
pluginGetFile "Floskell: " uri $ \file -> do
@@ -43,8 +46,10 @@ provider uri typ _opts =
4346
Left err -> return $ IdeResultFail (IdeError PluginError (T.pack err) Null)
4447
Right new -> return $ IdeResultOk [TextEdit range (T.decodeUtf8 (BS.toStrict new))]
4548

46-
47-
49+
-- | Find Floskell Config, user and system wide or provides a default style.
50+
-- Every directory of the filepath will be searched to find a user configuration.
51+
-- Also looks into places such as XDG_CONFIG_DIRECTORY<https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>.
52+
-- This function may not throw an exception and returns a default config.
4853
findConfigOrDefault :: FilePath -> IO AppConfig
4954
findConfigOrDefault file = do
5055
mbConf <- findAppConfigIn file

0 commit comments

Comments
 (0)