From 7ce758b4ea867631ce6a527dc93fb3925a9ff1ff Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 7 Apr 2019 15:29:23 +0200 Subject: [PATCH 1/2] Add more documentation for formatters --- .../Haskell/Ide/Engine/PluginsIdeMonads.hs | 13 ++++++++++++- src/Haskell/Ide/Engine/Plugin/Brittany.hs | 5 +++++ src/Haskell/Ide/Engine/Plugin/Floskell.hs | 9 +++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs index fa284e624..ac36cc186 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs @@ -208,9 +208,20 @@ type HoverProvider = Uri -> Position -> IdeM (IdeResult [Hover]) type SymbolProvider = Uri -> IdeDeferM (IdeResult [DocumentSymbol]) +-- | Format the document either as a whole or only a given Range of it. data FormattingType = FormatDocument | FormatRange Range -type FormattingProvider = Uri -> FormattingType -> FormattingOptions -> IdeDeferM (IdeResult [TextEdit]) + +-- |Formats the given Uri with the given options. +-- A formatting type can be given to either format the whole documetn or only a Range. +-- Fails if the formatter can not parse the source. +-- Failing menas 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 = Uri -- ^ Uri to the file to format. Can be mapped to a file with `pluginGetFile` + -> FormattingType -- ^ How much to format + -> FormattingOptions -- ^ Options for the formatter + -> IdeDeferM (IdeResult [TextEdit]) -- ^ Result of the formatting or the unchanged text. data PluginDescriptor = PluginDescriptor { pluginId :: PluginId diff --git a/src/Haskell/Ide/Engine/Plugin/Brittany.hs b/src/Haskell/Ide/Engine/Plugin/Brittany.hs index 618fb38ea..6aa3c893f 100644 --- a/src/Haskell/Ide/Engine/Plugin/Brittany.hs +++ b/src/Haskell/Ide/Engine/Plugin/Brittany.hs @@ -36,6 +36,9 @@ brittanyDescriptor plId = PluginDescriptor , pluginFormattingProvider = Just provider } +-- |Formatter provider of Brittany. +-- Formats the given source in either a given Range or the whole Document. +-- If the provider fails an error is returned that can be displayed to the user. provider :: FormattingProvider provider uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \file -> do confFile <- liftIO $ getConfFile file @@ -65,6 +68,8 @@ normalize (Range (Position sl _) (Position el _)) = -- Extend to the line below to replace newline character, as above Range (Position sl 0) (Position (el + 1) 0) +-- |Recursively search in every directory of the given filepath for brittany.yaml +-- If no such file has been found, return Nothing. getConfFile :: FilePath -> IO (Maybe FilePath) getConfFile = findLocalConfigPath . takeDirectory diff --git a/src/Haskell/Ide/Engine/Plugin/Floskell.hs b/src/Haskell/Ide/Engine/Plugin/Floskell.hs index 1c3638d8e..75c67842c 100644 --- a/src/Haskell/Ide/Engine/Plugin/Floskell.hs +++ b/src/Haskell/Ide/Engine/Plugin/Floskell.hs @@ -27,6 +27,9 @@ floskellDescriptor plId = PluginDescriptor , pluginFormattingProvider = Just provider } +-- |Format provider of Floskell. +-- Formats the given source in either a given Range or the whole Document. +-- If the provider fails an error is returned that can be displayed to the user. provider :: FormattingProvider provider uri typ _opts = pluginGetFile "Floskell: " uri $ \file -> do @@ -43,8 +46,10 @@ provider uri typ _opts = Left err -> return $ IdeResultFail (IdeError PluginError (T.pack err) Null) Right new -> return $ IdeResultOk [TextEdit range (T.decodeUtf8 (BS.toStrict new))] - - +-- |Find Floskell Config, user and system wide or provides a default style. +-- Every directory of the filepath will be searched to find a user configuration. +-- Also looks into places such as XDG_CONFIG_DIRECTORY. +-- This function may not throw an exception and returns a default config. findConfigOrDefault :: FilePath -> IO AppConfig findConfigOrDefault file = do mbConf <- findAppConfigIn file From 21f0fdbd570a69386f1697ed98a0db0a45f83fcd Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 7 Apr 2019 21:09:17 +0200 Subject: [PATCH 2/2] Include bubba suggestions Co-Authored-By: bubba --- hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs | 4 ++-- src/Haskell/Ide/Engine/Plugin/Brittany.hs | 4 ++-- src/Haskell/Ide/Engine/Plugin/Floskell.hs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs index ac36cc186..ff7633afe 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs @@ -212,8 +212,8 @@ type SymbolProvider = Uri -> IdeDeferM (IdeResult [DocumentSymbol]) data FormattingType = FormatDocument | FormatRange Range --- |Formats the given Uri with the given options. --- A formatting type can be given to either format the whole documetn or only a Range. +-- | Formats the given Uri with the given options. +-- A formatting type can be given to either format the whole document or only a Range. -- Fails if the formatter can not parse the source. -- Failing menas here that a IdeResultFail is returned. -- This can be used to display errors to the user, unless the error is an Internal one. diff --git a/src/Haskell/Ide/Engine/Plugin/Brittany.hs b/src/Haskell/Ide/Engine/Plugin/Brittany.hs index 6aa3c893f..83a74b527 100644 --- a/src/Haskell/Ide/Engine/Plugin/Brittany.hs +++ b/src/Haskell/Ide/Engine/Plugin/Brittany.hs @@ -36,7 +36,7 @@ brittanyDescriptor plId = PluginDescriptor , pluginFormattingProvider = Just provider } --- |Formatter provider of Brittany. +-- | Formatter provider of Brittany. -- Formats the given source in either a given Range or the whole Document. -- If the provider fails an error is returned that can be displayed to the user. provider :: FormattingProvider @@ -68,7 +68,7 @@ normalize (Range (Position sl _) (Position el _)) = -- Extend to the line below to replace newline character, as above Range (Position sl 0) (Position (el + 1) 0) --- |Recursively search in every directory of the given filepath for brittany.yaml +-- | Recursively search in every directory of the given filepath for brittany.yaml -- If no such file has been found, return Nothing. getConfFile :: FilePath -> IO (Maybe FilePath) getConfFile = findLocalConfigPath . takeDirectory diff --git a/src/Haskell/Ide/Engine/Plugin/Floskell.hs b/src/Haskell/Ide/Engine/Plugin/Floskell.hs index 75c67842c..e66843ad4 100644 --- a/src/Haskell/Ide/Engine/Plugin/Floskell.hs +++ b/src/Haskell/Ide/Engine/Plugin/Floskell.hs @@ -27,7 +27,7 @@ floskellDescriptor plId = PluginDescriptor , pluginFormattingProvider = Just provider } --- |Format provider of Floskell. +-- | Format provider of Floskell. -- Formats the given source in either a given Range or the whole Document. -- If the provider fails an error is returned that can be displayed to the user. provider :: FormattingProvider @@ -46,7 +46,7 @@ provider uri typ _opts = Left err -> return $ IdeResultFail (IdeError PluginError (T.pack err) Null) Right new -> return $ IdeResultOk [TextEdit range (T.decodeUtf8 (BS.toStrict new))] --- |Find Floskell Config, user and system wide or provides a default style. +-- | Find Floskell Config, user and system wide or provides a default style. -- Every directory of the filepath will be searched to find a user configuration. -- Also looks into places such as XDG_CONFIG_DIRECTORY. -- This function may not throw an exception and returns a default config.