packages feed

hls-ormolu-plugin 1.0.3.0 → 1.0.4.0

raw patch · 8 files changed

+55/−13 lines, 8 filesdep ~ghcidedep ~hls-test-utilsdep ~ormoluPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: ghcide, hls-test-utils, ormolu

API changes (from Hackage documentation)

Files

hls-ormolu-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-ormolu-plugin-version:            1.0.3.0+version:            1.0.4.0 synopsis:           Integration with the Ormolu code formatter description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -15,16 +15,16 @@ extra-source-files:   LICENSE   test/testdata/**/*.hs+  test/testdata/.ormolu+  test/testdata/test.cabal  source-repository head     type:     git     location: https://github.com/haskell/haskell-language-server.git  library-  if impl(ghc >= 9.3)+  if impl(ghc >= 9.5)     buildable: False-  else-    buildable: True   exposed-modules:  Ide.Plugin.Ormolu   hs-source-dirs:   src   build-depends:@@ -32,7 +32,7 @@     , filepath     , ghc     , ghc-boot-th-    , ghcide          ^>=1.6 || ^>=1.7 || ^>= 1.8 || ^>= 1.9+    , ghcide          ^>=1.6 || ^>=1.7 || ^>= 1.8 || ^>= 1.9 || ^>= 1.10     , hls-plugin-api  ^>=1.3 || ^>=1.4 || ^>= 1.5 || ^>= 1.6     , lens     , lsp@@ -42,10 +42,8 @@   default-language: Haskell2010  test-suite tests-  if impl(ghc >= 9.3)+  if impl(ghc >= 9.5)     buildable: False-  else-    buildable: True   type:             exitcode-stdio-1.0   default-language: Haskell2010   hs-source-dirs:   test@@ -57,3 +55,4 @@     , hls-ormolu-plugin     , hls-test-utils     ^>=1.5     , lsp-types+    , ormolu
src/Ide/Plugin/Ormolu.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP               #-}+{-# LANGUAGE LambdaCase        #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications  #-} @@ -7,8 +9,10 @@   ) where -import           Control.Exception               (try)+import           Control.Exception               (Handler (..), IOException,+                                                  SomeException (..), catches) import           Control.Monad.IO.Class          (liftIO)+import           Data.Functor                    ((<&>)) import qualified Data.Text                       as T import           Development.IDE                 hiding (pluginHandlers) import           Development.IDE.GHC.Compat      (hsc_dflags, moduleNameString)@@ -43,9 +47,26 @@     fullRegion = RegionIndices Nothing Nothing     rangeRegion s e = RegionIndices (Just $ s + 1) (Just $ e + 1)     mkConf o region = defaultConfig { cfgDynOptions = o, cfgRegion = region }-    fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text)-    fmt cont conf =-      try @OrmoluException $ ormolu conf (fromNormalizedFilePath fp) $ T.unpack cont+    fmt :: T.Text -> Config RegionIndices -> IO (Either SomeException T.Text)+    fmt cont conf = flip catches handlers $ do+      let fp' = fromNormalizedFilePath fp+#if MIN_VERSION_ormolu(0,5,3)+      cabalInfo <- getCabalInfoForSourceFile fp' <&> \case+        CabalNotFound                -> Nothing+        CabalDidNotMention cabalInfo -> Just cabalInfo+        CabalFound cabalInfo         -> Just cabalInfo+      fixityOverrides <- traverse getFixityOverridesForSourceFile cabalInfo+      let conf' = refineConfig ModuleSource cabalInfo fixityOverrides conf+          cont' = cont+#else+      let conf' = conf+          cont' = T.unpack cont+#endif+      Right <$> ormolu conf' fp' cont'+    handlers =+      [ Handler $ pure . Left . SomeException @OrmoluException+      , Handler $ pure . Left . SomeException @IOException+      ]    case typ of     FormatText -> ret <$> fmt contents (mkConf fileOpts fullRegion)@@ -54,7 +75,7 @@  where    title = T.pack $ "Formatting " <> takeFileName (fromNormalizedFilePath fp) -   ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit)+   ret :: Either SomeException T.Text -> Either ResponseError (List TextEdit)    ret (Left err)  = Left . responseError . T.pack $ "ormoluCmd: " ++ show err    ret (Right new) = Right $ makeDiffTextEdit contents new 
test/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP               #-} {-# LANGUAGE OverloadedStrings #-} module Main   ( main@@ -20,6 +21,10 @@       formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)   , goldenWithOrmolu "formats imports correctly" "Ormolu2" "formatted" $ \doc -> do       formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)+#if MIN_VERSION_ormolu(0,5,3)+  , goldenWithOrmolu "formats operators correctly" "Ormolu3" "formatted" $ \doc -> do+      formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)+#endif   ]  goldenWithOrmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
+ test/testdata/.ormolu view
@@ -0,0 +1,1 @@+infixl 7 .=?
+ test/testdata/Ormolu3.expected.hs view
@@ -0,0 +1,5 @@+foo :: String+foo =+  "a" .=? "b"+    <> "c" .=? "d"+    <> "e" .=? "f"
+ test/testdata/Ormolu3.formatted.hs view
@@ -0,0 +1,5 @@+foo :: String+foo =+  "a" .=? "b"+    <> "c" .=? "d"+    <> "e" .=? "f"
+ test/testdata/Ormolu3.hs view
@@ -0,0 +1,3 @@+foo :: String+foo = "a" .=? "b"+    <> "c" .=? "d" <> "e" .=? "f"
+ test/testdata/test.cabal view
@@ -0,0 +1,3 @@+cabal-version: 3.0+name: test+version: 0