This repository was archived by the owner on Oct 7, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed
hie-plugin-api/Haskell/Ide/Engine
src/Haskell/Ide/Engine/Plugin Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -208,9 +208,20 @@ type HoverProvider = Uri -> Position -> IdeM (IdeResult [Hover])
208208
209209type SymbolProvider = Uri -> IdeDeferM (IdeResult [DocumentSymbol ])
210210
211+ -- | Format the document either as a whole or only a given Range of it.
211212data 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 documetn 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
215226data PluginDescriptor =
216227 PluginDescriptor { pluginId :: PluginId
Original file line number Diff line number Diff 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.
3942provider :: FormattingProvider
4043provider 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.
6873getConfFile :: FilePath -> IO (Maybe FilePath )
6974getConfFile = findLocalConfigPath . takeDirectory
7075
Original file line number Diff line number Diff 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.
3033provider :: FormattingProvider
3134provider 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.
4853findConfigOrDefault :: FilePath -> IO AppConfig
4954findConfigOrDefault file = do
5055 mbConf <- findAppConfigIn file
You can’t perform that action at this time.
0 commit comments