hls-cabal-fmt-plugin 2.0.0.1 → 2.1.0.0
raw patch · 2 files changed
+20/−17 lines, 2 filesdep +mtldep ~ghcidedep ~hls-plugin-apidep ~hls-test-utilsPVP ok
version bump matches the API change (PVP)
Dependencies added: mtl
Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils
API changes (from Hackage documentation)
Files
- hls-cabal-fmt-plugin.cabal +5/−4
- src/Ide/Plugin/CabalFmt.hs +15/−13
hls-cabal-fmt-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-cabal-fmt-plugin-version: 2.0.0.1+version: 2.1.0.0 synopsis: Integration with the cabal-fmt code formatter description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -33,10 +33,11 @@ , base >=4.12 && <5 , directory , filepath- , ghcide == 2.0.0.1- , hls-plugin-api == 2.0.0.1+ , ghcide == 2.1.0.0+ , hls-plugin-api == 2.1.0.0 , lens , lsp-types+ , mtl , process , text , transformers@@ -55,7 +56,7 @@ , directory , filepath , hls-cabal-fmt-plugin- , hls-test-utils == 2.0.0.1+ , hls-test-utils == 2.1.0.0 if flag(isolateTests) build-tool-depends: cabal-fmt:cabal-fmt ^>=0.1.6
src/Ide/Plugin/CabalFmt.hs view
@@ -4,14 +4,16 @@ module Ide.Plugin.CabalFmt where import Control.Lens+import Control.Monad.Except (throwError) import Control.Monad.IO.Class-import qualified Data.Text as T-import Development.IDE hiding (pluginHandlers)+import qualified Data.Text as T+import Development.IDE hiding (pluginHandlers)+import Ide.Plugin.Error (PluginError (PluginInternalError, PluginInvalidParams)) import Ide.PluginUtils import Ide.Types-import Language.LSP.Types as J-import qualified Language.LSP.Types.Lens as J-import Prelude hiding (log)+import Language.LSP.Protocol.Lens as L+import Language.LSP.Protocol.Types+import Prelude hiding (log) import System.Directory import System.Exit import System.FilePath@@ -46,14 +48,14 @@ provider :: Recorder (WithPriority Log) -> FormattingHandler IdeState provider recorder _ (FormatRange _) _ _ _ = do logWith recorder Info LogInvalidInvocationInfo- pure $ Left (ResponseError InvalidRequest "You cannot format a text-range using cabal-fmt." Nothing)-provider recorder _ide FormatText contents nfp opts = liftIO $ do+ throwError $ PluginInvalidParams "You cannot format a text-range using cabal-fmt."+provider recorder _ide FormatText contents nfp opts = do let cabalFmtArgs = [fp, "--indent", show tabularSize]- x <- findExecutable "cabal-fmt"+ x <- liftIO $ findExecutable "cabal-fmt" case x of Just _ -> do (exitCode, out, err) <-- readCreateProcessWithExitCode+ liftIO $ readCreateProcessWithExitCode ( proc "cabal-fmt" cabalFmtArgs ) { cwd = Just $ takeDirectory fp@@ -63,14 +65,14 @@ case exitCode of ExitFailure code -> do log Error $ LogProcessInvocationFailure code- pure $ Left (ResponseError UnknownErrorCode "Failed to invoke cabal-fmt" Nothing)+ throwError (PluginInternalError "Failed to invoke cabal-fmt") ExitSuccess -> do let fmtDiff = makeDiffTextEdit contents (T.pack out)- pure $ Right fmtDiff+ pure $ InL fmtDiff Nothing -> do log Error LogCabalFmtNotFound- pure $ Left (ResponseError InvalidRequest "No installation of cabal-fmt could be found. Please install it into your global environment." Nothing)+ throwError (PluginInternalError "No installation of cabal-fmt could be found. Please install it into your global environment.") where fp = fromNormalizedFilePath nfp- tabularSize = opts ^. J.tabSize+ tabularSize = opts ^. L.tabSize log = logWith recorder