This repository was archived by the owner on Oct 7, 2020. It is now read-only.
File tree 3 files changed +24
-3
lines changed
hie-plugin-api/Haskell/Ide/Engine
src/Haskell/Ide/Engine/Plugin
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])
208
208
209
209
type SymbolProvider = Uri -> IdeDeferM (IdeResult [DocumentSymbol ])
210
210
211
+ -- | Format the document either as a whole or only a given Range of it.
211
212
data FormattingType = FormatDocument
212
213
| 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.
214
225
215
226
data PluginDescriptor =
216
227
PluginDescriptor { pluginId :: PluginId
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ brittanyDescriptor plId = PluginDescriptor
36
36
, pluginFormattingProvider = Just provider
37
37
}
38
38
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.
39
42
provider :: FormattingProvider
40
43
provider uri formatType opts = pluginGetFile " brittanyCmd: " uri $ \ file -> do
41
44
confFile <- liftIO $ getConfFile file
@@ -65,6 +68,8 @@ normalize (Range (Position sl _) (Position el _)) =
65
68
-- Extend to the line below to replace newline character, as above
66
69
Range (Position sl 0 ) (Position (el + 1 ) 0 )
67
70
71
+ -- | Recursively search in every directory of the given filepath for brittany.yaml
72
+ -- If no such file has been found, return Nothing.
68
73
getConfFile :: FilePath -> IO (Maybe FilePath )
69
74
getConfFile = findLocalConfigPath . takeDirectory
70
75
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ floskellDescriptor plId = PluginDescriptor
27
27
, pluginFormattingProvider = Just provider
28
28
}
29
29
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.
30
33
provider :: FormattingProvider
31
34
provider uri typ _opts =
32
35
pluginGetFile " Floskell: " uri $ \ file -> do
@@ -43,8 +46,10 @@ provider uri typ _opts =
43
46
Left err -> return $ IdeResultFail (IdeError PluginError (T. pack err) Null )
44
47
Right new -> return $ IdeResultOk [TextEdit range (T. decodeUtf8 (BS. toStrict new))]
45
48
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.
48
53
findConfigOrDefault :: FilePath -> IO AppConfig
49
54
findConfigOrDefault file = do
50
55
mbConf <- findAppConfigIn file
You can’t perform that action at this time.
0 commit comments