From 8d1bcfe8e662b122eba3d8748e2e4ccdb5c0ac4b Mon Sep 17 00:00:00 2001 From: Fendor Date: Wed, 28 Feb 2024 21:41:08 +0100 Subject: [PATCH 1/3] Add cabal-gild as a cabal file formatter plugin --- .github/workflows/test.yml | 79 ++++++++++--------- CODEOWNERS | 7 +- haskell-language-server.cabal | 51 ++++++++++++ hls-plugin-api/src/Ide/Types.hs | 3 +- .../src/Ide/Plugin/CabalGild.hs | 78 ++++++++++++++++++ plugins/hls-cabal-gild-plugin/test/Main.hs | 58 ++++++++++++++ .../test/testdata/commented_testdata.cabal | 12 +++ ...ommented_testdata.formatted_document.cabal | 15 ++++ .../test/testdata/hie.yaml | 3 + .../test/testdata/lib_testdata.cabal | 19 +++++ .../lib_testdata.formatted_document.cabal | 20 +++++ .../test/testdata/simple_testdata.cabal | 36 +++++++++ .../simple_testdata.formatted_document.cabal | 28 +++++++ .../test/testdata/src/MyLib.hs | 4 + .../test/testdata/src/MyOtherLib.hs | 3 + src/HlsPlugins.hs | 11 ++- 16 files changed, 385 insertions(+), 42 deletions(-) create mode 100644 plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs create mode 100644 plugins/hls-cabal-gild-plugin/test/Main.hs create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.formatted_document.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/hie.yaml create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.formatted_document.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.formatted_document.cabal create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/src/MyLib.hs create mode 100644 plugins/hls-cabal-gild-plugin/test/testdata/src/MyOtherLib.hs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2163ad98b6..67b8d200dd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,7 +74,7 @@ jobs: - ubuntu-latest - macOS-latest - windows-latest - test: + test: - true - false exclude: @@ -112,139 +112,144 @@ jobs: - if: matrix.test name: Test hls-graph - run: cabal test hls-graph + run: cabal test hls-graph - if: needs.pre_job.outputs.should_skip_ghcide != 'true' && matrix.test name: Test ghcide # run the tests without parallelism to avoid running out of memory - run: cabal test ghcide || cabal test ghcide + run: cabal test ghcide || cabal test ghcide - if: matrix.test name: Test hls-plugin-api - run: cabal test hls-plugin-api || cabal test hls-plugin-api + run: cabal test hls-plugin-api || cabal test hls-plugin-api - if: matrix.test name: Test func-test suite env: HLS_TEST_EXE: hls HLS_WRAPPER_TEST_EXE: hls-wrapper - run: cabal test func-test || cabal test func-test + run: cabal test func-test || cabal test func-test - if: matrix.test name: Test wrapper-test suite env: HLS_TEST_EXE: hls HLS_WRAPPER_TEST_EXE: hls-wrapper - run: cabal test wrapper-test + run: cabal test wrapper-test - if: matrix.test name: Test hls-refactor-plugin - run: cabal test hls-refactor-plugin-tests || cabal test hls-refactor-plugin-tests + run: cabal test hls-refactor-plugin-tests || cabal test hls-refactor-plugin-tests - - if: matrix.test + - if: matrix.test name: Test hls-floskell-plugin - run: cabal test hls-floskell-plugin-tests || cabal test hls-floskell-plugin-tests + run: cabal test hls-floskell-plugin-tests || cabal test hls-floskell-plugin-tests - if: matrix.test name: Test hls-class-plugin - run: cabal test hls-class-plugin-tests || cabal test hls-class-plugin-tests + run: cabal test hls-class-plugin-tests || cabal test hls-class-plugin-tests - if: matrix.test name: Test hls-pragmas-plugin - run: cabal test hls-pragmas-plugin-tests || cabal test hls-pragmas-plugin-tests + run: cabal test hls-pragmas-plugin-tests || cabal test hls-pragmas-plugin-tests - if: matrix.test name: Test hls-eval-plugin - run: cabal test hls-eval-plugin-tests || cabal test hls-eval-plugin-tests + run: cabal test hls-eval-plugin-tests || cabal test hls-eval-plugin-tests - if: matrix.test name: Test hls-splice-plugin - run: cabal test hls-splice-plugin-tests || cabal test hls-splice-plugin-tests + run: cabal test hls-splice-plugin-tests || cabal test hls-splice-plugin-tests - if: matrix.test && matrix.ghc != '9.2' name: Test hls-stan-plugin - run: cabal test hls-stan-plugin-tests || cabal test hls-stan-plugin-tests + run: cabal test hls-stan-plugin-tests || cabal test hls-stan-plugin-tests - if: matrix.test name: Test hls-stylish-haskell-plugin - run: cabal test hls-stylish-haskell-plugin-tests || cabal test hls-stylish-haskell-plugin-tests + run: cabal test hls-stylish-haskell-plugin-tests || cabal test hls-stylish-haskell-plugin-tests - - if: matrix.test + - if: matrix.test name: Test hls-ormolu-plugin - run: cabal test hls-ormolu-plugin-tests || cabal test hls-ormolu-plugin-tests + run: cabal test hls-ormolu-plugin-tests || cabal test hls-ormolu-plugin-tests - - if: matrix.test + - if: matrix.test name: Test hls-fourmolu-plugin - run: cabal test hls-fourmolu-plugin-tests || cabal test hls-fourmolu-plugin-tests + run: cabal test hls-fourmolu-plugin-tests || cabal test hls-fourmolu-plugin-tests - if: matrix.test name: Test hls-explicit-imports-plugin test suite - run: cabal test hls-explicit-imports-plugin-tests || cabal test hls-explicit-imports-plugin-tests + run: cabal test hls-explicit-imports-plugin-tests || cabal test hls-explicit-imports-plugin-tests - if: matrix.test name: Test hls-call-hierarchy-plugin test suite - run: cabal test hls-call-hierarchy-plugin-tests || cabal test hls-call-hierarchy-plugin-tests + run: cabal test hls-call-hierarchy-plugin-tests || cabal test hls-call-hierarchy-plugin-tests - if: matrix.test && matrix.os != 'windows-latest' name: Test hls-rename-plugin test suite - run: cabal test hls-rename-plugin-tests || cabal test hls-rename-plugin-tests + run: cabal test hls-rename-plugin-tests || cabal test hls-rename-plugin-tests - - if: matrix.test + - if: matrix.test name: Test hls-hlint-plugin test suite - run: cabal test hls-hlint-plugin-tests || cabal test hls-hlint-plugin-tests + run: cabal test hls-hlint-plugin-tests || cabal test hls-hlint-plugin-tests - if: matrix.test name: Test hls-module-name-plugin test suite - run: cabal test hls-module-name-plugin-tests || cabal test hls-module-name-plugin-tests + run: cabal test hls-module-name-plugin-tests || cabal test hls-module-name-plugin-tests - if: matrix.test name: Test hls-alternate-number-format-plugin test suite - run: cabal test hls-alternate-number-format-plugin-tests || cabal test hls-alternate-number-format-plugin-tests + run: cabal test hls-alternate-number-format-plugin-tests || cabal test hls-alternate-number-format-plugin-tests - if: matrix.test name: Test hls-qualify-imported-names-plugin test suite - run: cabal test hls-qualify-imported-names-plugin-tests || cabal test hls-qualify-imported-names-plugin-tests + run: cabal test hls-qualify-imported-names-plugin-tests || cabal test hls-qualify-imported-names-plugin-tests - if: matrix.test name: Test hls-code-range-plugin test suite - run: cabal test hls-code-range-plugin-tests || cabal test hls-code-range-plugin-tests + run: cabal test hls-code-range-plugin-tests || cabal test hls-code-range-plugin-tests - if: matrix.test name: Test hls-change-type-signature test suite - run: cabal test hls-change-type-signature-plugin-tests || cabal test hls-change-type-signature-plugin-tests + run: cabal test hls-change-type-signature-plugin-tests || cabal test hls-change-type-signature-plugin-tests - if: matrix.test name: Test hls-gadt-plugin test suit - run: cabal test hls-gadt-plugin-tests || cabal test hls-gadt-plugin-tests + run: cabal test hls-gadt-plugin-tests || cabal test hls-gadt-plugin-tests - if: matrix.test name: Test hls-explicit-fixity-plugin test suite - run: cabal test hls-explicit-fixity-plugin-tests || cabal test hls-explicit-fixity-plugin-tests + run: cabal test hls-explicit-fixity-plugin-tests || cabal test hls-explicit-fixity-plugin-tests - if: matrix.test name: Test hls-explicit-record-fields-plugin test suite - run: cabal test hls-explicit-record-fields-plugin-tests || cabal test hls-explicit-record-fields-plugin-tests + run: cabal test hls-explicit-record-fields-plugin-tests || cabal test hls-explicit-record-fields-plugin-tests ## version needs to be limited since the tests depend on cabal-fmt which only builds using specific ghc versions - if: matrix.test && matrix.ghc == '9.2' name: Test hls-cabal-fmt-plugin test suite - run: cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests || cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests + run: cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests || cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests + + ## version needs to be limited since the tests depend on cabal-gild which only builds using specific ghc versions + - if: matrix.test + name: Test hls-cabal-gild-plugin test suite + run: cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests || cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests - if: matrix.test name: Test hls-cabal-plugin test suite - run: cabal test hls-cabal-plugin-tests || cabal test hls-cabal-plugin-tests + run: cabal test hls-cabal-plugin-tests || cabal test hls-cabal-plugin-tests - if: matrix.test name: Test hls-retrie-plugin test suite - run: cabal test hls-retrie-plugin-tests || cabal test hls-retrie-plugin-tests + run: cabal test hls-retrie-plugin-tests || cabal test hls-retrie-plugin-tests - if: matrix.test name: Test hls-overloaded-record-dot-plugin test suite - run: cabal test hls-overloaded-record-dot-plugin-tests || cabal test hls-overloaded-record-dot-plugin-tests + run: cabal test hls-overloaded-record-dot-plugin-tests || cabal test hls-overloaded-record-dot-plugin-tests - if: matrix.test name: Test hls-semantic-tokens-plugin test suite - run: cabal test hls-semantic-tokens-plugin-tests || cabal test hls-semantic-tokens-plugin-tests + run: cabal test hls-semantic-tokens-plugin-tests || cabal test hls-semantic-tokens-plugin-tests test_post_job: diff --git a/CODEOWNERS b/CODEOWNERS index 9c1f09495a..8d3c8404fa 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -14,10 +14,11 @@ # Plugins /plugins/hls-alternate-number-format-plugin @drsooch /plugins/hls-cabal-fmt-plugin @VeryMilkyJoe @fendor +/plugins/hls-cabal-gild-plugin @fendor /plugins/hls-cabal-plugin @fendor /plugins/hls-call-hierarchy-plugin @July541 /plugins/hls-change-type-signature-plugin -/plugins/hls-class-plugin +/plugins/hls-class-plugin /plugins/hls-code-range-plugin @kokobd /plugins/hls-eval-plugin /plugins/hls-explicit-fixity-plugin @@ -33,7 +34,7 @@ /plugins/hls-pragmas-plugin @eddiemundo /plugins/hls-qualify-imported-names-plugin @eddiemundo /plugins/hls-refactor-plugin @santiweight -/plugins/hls-rename-plugin +/plugins/hls-rename-plugin /plugins/hls-retrie-plugin @pepeiborra /plugins/hls-semantic-tokens-plugin @soulomoon /plugins/hls-splice-plugin @konn @@ -48,7 +49,7 @@ /docs @michaelpj # CI -/.circleci +/.circleci /.github @michaelpj @fendor # Build diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 613323b361..d0d5b58248 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -145,6 +145,56 @@ test-suite hls-cabal-fmt-plugin-tests if flag(isolateCabalfmtTests) build-tool-depends: cabal-fmt:cabal-fmt ^>=0.1.6 +----------------------------- +-- cabal-gild plugin +----------------------------- + +flag cabalgild + description: Enable cabal-gild plugin + default: True + manual: True + +common cabalgild + if flag(cabalgild) + build-depends: haskell-language-server:hls-cabal-gild-plugin + cpp-options: -Dhls_cabalgild + +flag isolateCabalGildTests + description: Should tests search for 'cabal-gild' on the $PATH or shall we install it via build-tool-depends? + -- By default, search on the PATH + default: False + manual: True + +library hls-cabal-gild-plugin + import: defaults, pedantic, warnings + exposed-modules: Ide.Plugin.CabalGild + hs-source-dirs: plugins/hls-cabal-gild-plugin/src + build-depends: + , base >=4.12 && <5 + , directory + , filepath + , ghcide == 2.7.0.0 + , hls-plugin-api == 2.7.0.0 + , lsp-types + , text + , mtl + , process-extras + +test-suite hls-cabal-gild-plugin-tests + import: defaults, pedantic, test-defaults, warnings + type: exitcode-stdio-1.0 + hs-source-dirs: plugins/hls-cabal-gild-plugin/test + main-is: Main.hs + build-depends: + , base + , directory + , filepath + , haskell-language-server:hls-cabal-gild-plugin + , hls-test-utils == 2.7.0.0 + + if flag(isolateCabalGildTests) + build-tool-depends: cabal-gild:cabal-gild ^>=1.1 + ----------------------------- -- cabal plugin ----------------------------- @@ -1642,6 +1692,7 @@ library , cabal , callHierarchy , cabalfmt + , cabalgild , changeTypeSignature , class , eval diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index bd8f134716..578ba303b2 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -189,7 +189,8 @@ instance Default Config where , formattingProvider = "ormolu" -- , formattingProvider = "floskell" -- , formattingProvider = "stylish-haskell" - , cabalFormattingProvider = "cabal-fmt" + , cabalFormattingProvider = "gild" + -- , cabalFormattingProvider = "cabal-fmt" -- this string value needs to kept in sync with the value provided in HlsPlugins , maxCompletions = 40 , plugins = mempty diff --git a/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs b/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs new file mode 100644 index 0000000000..567822536d --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs @@ -0,0 +1,78 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} + +module Ide.Plugin.CabalGild where + +import Control.Monad.Except (throwError) +import Control.Monad.IO.Class +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.Protocol.Types +import Prelude hiding (log) +import System.Directory +import System.Exit +import System.FilePath +import System.Process.ListLike +import qualified System.Process.Text as Process + +data Log + = LogProcessInvocationFailure Int T.Text + | LogReadCreateProcessInfo [String] + | LogInvalidInvocationInfo + | LogFormatterBinNotFound + deriving (Show) + +instance Pretty Log where + pretty = \case + LogProcessInvocationFailure exitCode err -> + vcat + [ "Invocation of cabal-gild failed with code" <+> pretty exitCode + , "Stderr:" <+> pretty err + ] + LogReadCreateProcessInfo args -> + "Formatter invocation: cabal-gild " <+> pretty args + LogInvalidInvocationInfo -> "Invocation of cabal-gild with range was called but is not supported." + LogFormatterBinNotFound -> "Couldn't find executable 'cabal-gild'" + +descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState +descriptor recorder plId = + (defaultCabalPluginDescriptor plId "Provides formatting of cabal files with cabal-gild") + { pluginHandlers = mkFormattingHandlers (provider recorder) + } + +-- | Formatter provider of cabal gild. +-- 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 :: Recorder (WithPriority Log) -> FormattingHandler IdeState +provider recorder _ _ (FormatRange _) _ _ _ = do + logWith recorder Info LogInvalidInvocationInfo + throwError $ PluginInvalidParams "You cannot format a text-range using cabal-gild." +provider recorder _ide _ FormatText contents nfp _ = do + let cabalGildArgs = ["--stdin=" <> fp, "--input=-"] -- < Read from stdin + x <- liftIO $ findExecutable "cabal-gild" + case x of + Just _ -> do + log Debug $ LogReadCreateProcessInfo cabalGildArgs + (exitCode, out, err) <- + liftIO $ Process.readCreateProcessWithExitCode + ( proc "cabal-gild" cabalGildArgs + ) + { cwd = Just $ takeDirectory fp + } + contents + case exitCode of + ExitFailure code -> do + log Error $ LogProcessInvocationFailure code err + throwError (PluginInternalError "Failed to invoke cabal-gild") + ExitSuccess -> do + let fmtDiff = makeDiffTextEdit contents out + pure $ InL fmtDiff + Nothing -> do + log Error LogFormatterBinNotFound + throwError (PluginInternalError "No installation of cabal-gild could be found. Please install it into your global environment.") + where + fp = fromNormalizedFilePath nfp + log = logWith recorder diff --git a/plugins/hls-cabal-gild-plugin/test/Main.hs b/plugins/hls-cabal-gild-plugin/test/Main.hs new file mode 100644 index 0000000000..5fd6b11967 --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/Main.hs @@ -0,0 +1,58 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where + +import qualified Ide.Plugin.CabalGild as CabalGild +import System.Directory (findExecutable) +import System.FilePath +import Test.Hls + +data CabalGildFound = Found | NotFound + +isTestIsolated :: Bool +#if isolateTests +isTestIsolated = True +#else +isTestIsolated = False +#endif + +isCabalFmtFound :: IO CabalGildFound +isCabalFmtFound = case isTestIsolated of + True -> pure Found + False-> do + cabalGild <- findExecutable "cabal-gild" + pure $ maybe NotFound (const Found) cabalGild + +main :: IO () +main = do + foundCabalFmt <- isCabalFmtFound + defaultTestRunner (tests foundCabalFmt) + +cabalGildPlugin :: PluginTestDescriptor CabalGild.Log +cabalGildPlugin = mkPluginTestDescriptor CabalGild.descriptor "cabal-gild" + +tests :: CabalGildFound -> TestTree +tests found = testGroup "cabal-gild" + [ cabalGildGolden found "formats a simple document" "simple_testdata" "formatted_document" $ \doc -> do + formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) + + , cabalGildGolden found "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do + formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) + + , cabalGildGolden found "formats a document with lib information" "lib_testdata" "formatted_document" $ \doc -> do + formatDoc doc (FormattingOptions 10 True Nothing Nothing Nothing) + ] + +cabalGildGolden :: CabalGildFound -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +cabalGildGolden NotFound title _ _ _ = + testCase title $ + assertFailure $ "Couldn't find cabal-gild on PATH or this is not an isolated run. " + <> "Use cabal flag 'isolateTests' to make it isolated or install cabal-gild locally." +cabalGildGolden Found title path desc act = goldenWithCabalDocFormatter def cabalGildPlugin "cabal-gild" conf title testDataDir path desc "cabal" act + where + conf = def + +testDataDir :: FilePath +testDataDir = "plugins" "hls-cabal-gild-plugin" "test" "testdata" diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.cabal new file mode 100644 index 0000000000..ed2f1d701e --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.cabal @@ -0,0 +1,12 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 +author: Banana +extra-source-files: CHANGELOG.md + +library + -- cabal-gild: discover src + exposed-modules: MyLib + build-depends: base ^>=4.14.1.0 + hs-source-dirs: src + default-language: Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.formatted_document.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.formatted_document.cabal new file mode 100644 index 0000000000..3c88b4a823 --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/commented_testdata.formatted_document.cabal @@ -0,0 +1,15 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 +author: Banana +extra-source-files: CHANGELOG.md + +library + -- cabal-gild: discover src + exposed-modules: + MyLib + MyOtherLib + + build-depends: base ^>=4.14.1.0 + hs-source-dirs: src + default-language: Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/hie.yaml b/plugins/hls-cabal-gild-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..824558147d --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/hie.yaml @@ -0,0 +1,3 @@ +cradle: + direct: + arguments: [] diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.cabal new file mode 100644 index 0000000000..0f07af1d70 --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.cabal @@ -0,0 +1,19 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 +author: Gregg +extra-source-files: CHANGELOG.md + +library + exposed-modules: MyLib + build-depends: base ^>=4.14.1.0 + hs-source-dirs: src + default-language: Haskell2010 + +executable testdata + main-is: Main.hs + build-depends: + base ^>=4.14.1.0,testdata + hs-source-dirs: app + default-language: + Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.formatted_document.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.formatted_document.cabal new file mode 100644 index 0000000000..f8ca530630 --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/lib_testdata.formatted_document.cabal @@ -0,0 +1,20 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 +author: Gregg +extra-source-files: CHANGELOG.md + +library + exposed-modules: MyLib + build-depends: base ^>=4.14.1.0 + hs-source-dirs: src + default-language: Haskell2010 + +executable testdata + main-is: Main.hs + build-depends: + base ^>=4.14.1.0, + testdata, + + hs-source-dirs: app + default-language: Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.cabal new file mode 100644 index 0000000000..0421a27ddb --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.cabal @@ -0,0 +1,36 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- A URL where users can report bugs. +-- bug-reports: + +-- The license under which the package is released. +-- license: +author: Milky + +-- An email address to which users can send suggestions, bug reports, and patches. +-- maintainer: + +-- A copyright notice. +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +executable testdata + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + build-depends: base ^>=4.14.1.0 + hs-source-dirs: app + default-language: Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.formatted_document.cabal b/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.formatted_document.cabal new file mode 100644 index 0000000000..f79cba396e --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/simple_testdata.formatted_document.cabal @@ -0,0 +1,28 @@ +cabal-version: 2.4 +name: testdata +version: 0.1.0.0 +-- A short (one-line) description of the package. +-- synopsis: +-- A longer description of the package. +-- description: +-- A URL where users can report bugs. +-- bug-reports: +-- The license under which the package is released. +-- license: +author: Milky +-- An email address to which users can send suggestions, bug reports, and patches. +-- maintainer: +-- A copyright notice. +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +executable testdata + main-is: Main.hs + -- Modules included in this executable, other than Main. + -- other-modules: + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + build-depends: base ^>=4.14.1.0 + hs-source-dirs: app + default-language: Haskell2010 diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/src/MyLib.hs b/plugins/hls-cabal-gild-plugin/test/testdata/src/MyLib.hs new file mode 100644 index 0000000000..e657c4403f --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib (someFunc) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/plugins/hls-cabal-gild-plugin/test/testdata/src/MyOtherLib.hs b/plugins/hls-cabal-gild-plugin/test/testdata/src/MyOtherLib.hs new file mode 100644 index 0000000000..15450b43b3 --- /dev/null +++ b/plugins/hls-cabal-gild-plugin/test/testdata/src/MyOtherLib.hs @@ -0,0 +1,3 @@ +module MyOtherLib where + +bar = 2 diff --git a/src/HlsPlugins.hs b/src/HlsPlugins.hs index 90db332b6c..677dda3750 100644 --- a/src/HlsPlugins.hs +++ b/src/HlsPlugins.hs @@ -107,6 +107,10 @@ import qualified Ide.Plugin.Fourmolu as Fourmolu import qualified Ide.Plugin.CabalFmt as CabalFmt #endif +#if hls_cabalgild +import qualified Ide.Plugin.CabalGild as CabalGild +#endif + #if hls_ormolu import qualified Ide.Plugin.Ormolu as Ormolu #endif @@ -157,11 +161,16 @@ idePlugins recorder = pluginDescToIdePlugins allPlugins let pId = "fourmolu" in Fourmolu.descriptor (pluginRecorder pId) pId: #endif #if hls_cabalfmt + let pId = "cabal-fmt" in CabalFmt.descriptor (pluginRecorder pId) pId: +#endif +#if hls_cabalgild -- this pId needs to be kept in sync with the hardcoded -- cabalFormattingProvider in the Default Config - let pId = "cabal-fmt" in CabalFmt.descriptor (pluginRecorder pId) pId: + let pId = "cabal-gild" in CabalGild.descriptor (pluginRecorder pId) pId: #endif #if hls_ormolu + -- this pId needs to be kept in sync with the hardcoded + -- haskellFormattingProvider in the Default Config let pId = "ormolu" in Ormolu.descriptor (pluginRecorder pId) pId : #endif #if hls_stylishHaskell From ee4170c7cba65168909251f8fae69a5af89e9477 Mon Sep 17 00:00:00 2001 From: Fendor Date: Sun, 10 Mar 2024 15:47:16 +0100 Subject: [PATCH 2/3] Add support for multiple cabal formatters In addition, allow different cabal file formatter provider to specify an explicit file path, instead of searching only on $PATH. --- hls-plugin-api/src/Ide/Types.hs | 3 +- .../src/Ide/Plugin/CabalFmt.hs | 33 ++++++++++++------ .../src/Ide/Plugin/CabalGild.hs | 34 +++++++++++++------ .../schema/ghc92/default-config.golden.json | 11 ++++++ .../ghc92/vscode-extension-schema.golden.json | 12 +++++++ .../schema/ghc94/default-config.golden.json | 11 ++++++ .../ghc94/vscode-extension-schema.golden.json | 12 +++++++ .../schema/ghc96/default-config.golden.json | 11 ++++++ .../ghc96/vscode-extension-schema.golden.json | 12 +++++++ .../schema/ghc98/default-config.golden.json | 11 ++++++ .../ghc98/vscode-extension-schema.golden.json | 12 +++++++ 11 files changed, 141 insertions(+), 21 deletions(-) diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index 578ba303b2..3a592cf1ed 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -178,6 +178,7 @@ instance ToJSON Config where object [ "checkParents" .= checkParents , "checkProject" .= checkProject , "formattingProvider" .= formattingProvider + , "cabalFormattingProvider" .= cabalFormattingProvider , "maxCompletions" .= maxCompletions , "plugin" .= Map.mapKeysMonotonic (\(PluginId p) -> p) plugins ] @@ -189,7 +190,7 @@ instance Default Config where , formattingProvider = "ormolu" -- , formattingProvider = "floskell" -- , formattingProvider = "stylish-haskell" - , cabalFormattingProvider = "gild" + , cabalFormattingProvider = "cabal-gild" -- , cabalFormattingProvider = "cabal-fmt" -- this string value needs to kept in sync with the value provided in HlsPlugins , maxCompletions = 40 diff --git a/plugins/hls-cabal-fmt-plugin/src/Ide/Plugin/CabalFmt.hs b/plugins/hls-cabal-fmt-plugin/src/Ide/Plugin/CabalFmt.hs index 367898fa21..1af405e124 100644 --- a/plugins/hls-cabal-fmt-plugin/src/Ide/Plugin/CabalFmt.hs +++ b/plugins/hls-cabal-fmt-plugin/src/Ide/Plugin/CabalFmt.hs @@ -1,4 +1,6 @@ +{-# LANGUAGE DataKinds #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} module Ide.Plugin.CabalFmt where @@ -9,6 +11,7 @@ import Control.Monad.IO.Class import qualified Data.Text as T import Development.IDE hiding (pluginHandlers) import Ide.Plugin.Error (PluginError (PluginInternalError, PluginInvalidParams)) +import Ide.Plugin.Properties import Ide.PluginUtils import Ide.Types import qualified Language.LSP.Protocol.Lens as L @@ -24,7 +27,7 @@ data Log = LogProcessInvocationFailure Int | LogReadCreateProcessInfo T.Text [String] | LogInvalidInvocationInfo - | LogCabalFmtNotFound + | LogFormatterBinNotFound FilePath deriving (Show) instance Pretty Log where @@ -35,29 +38,39 @@ instance Pretty Log where ["Invocation of cabal-fmt with arguments" <+> pretty args] ++ ["failed with standard error:" <+> pretty stdErrorOut | not (T.null stdErrorOut)] LogInvalidInvocationInfo -> "Invocation of cabal-fmt with range was called but is not supported." - LogCabalFmtNotFound -> "Couldn't find executable 'cabal-fmt'" + LogFormatterBinNotFound fp -> "Couldn't find formatter executable 'cabal-fmt' at:" <+> pretty fp descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState descriptor recorder plId = (defaultCabalPluginDescriptor plId "Provides formatting of cabal files with cabal-fmt") - { pluginHandlers = mkFormattingHandlers (provider recorder) + { pluginHandlers = mkFormattingHandlers (provider recorder plId) + , pluginConfigDescriptor = defaultConfigDescriptor{configCustomConfig = mkCustomConfig properties} } +properties :: Properties '[ 'PropertyKey "path" 'TString] +properties = + emptyProperties + & defineStringProperty + #path + "Set path to 'cabal-fmt' executable" + "cabal-fmt" + -- | Formatter provider of cabal fmt. -- 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 :: Recorder (WithPriority Log) -> FormattingHandler IdeState -provider recorder _ _ (FormatRange _) _ _ _ = do +provider :: Recorder (WithPriority Log) -> PluginId -> FormattingHandler IdeState +provider recorder _ _ _ (FormatRange _) _ _ _ = do logWith recorder Info LogInvalidInvocationInfo throwError $ PluginInvalidParams "You cannot format a text-range using cabal-fmt." -provider recorder _ide _ FormatText contents nfp opts = do +provider recorder plId ideState _ FormatText contents nfp opts = do let cabalFmtArgs = [ "--indent", show tabularSize] - x <- liftIO $ findExecutable "cabal-fmt" + cabalFmtExePath <- fmap T.unpack $ liftIO $ runAction "cabal-gild" ideState $ usePropertyAction #path plId properties + x <- liftIO $ findExecutable cabalFmtExePath case x of Just _ -> do (exitCode, out, err) <- liftIO $ Process.readCreateProcessWithExitCode - ( proc "cabal-fmt" cabalFmtArgs + ( proc cabalFmtExePath cabalFmtArgs ) { cwd = Just $ takeDirectory fp } @@ -71,8 +84,8 @@ provider recorder _ide _ FormatText contents nfp opts = do let fmtDiff = makeDiffTextEdit contents out pure $ InL fmtDiff Nothing -> do - log Error LogCabalFmtNotFound - throwError (PluginInternalError "No installation of cabal-fmt could be found. Please install it into your global environment.") + log Error $ LogFormatterBinNotFound cabalFmtExePath + throwError (PluginInternalError "No installation of cabal-gild could be found. Please install it globally, or provide the full path to the executable") where fp = fromNormalizedFilePath nfp tabularSize = opts ^. L.tabSize diff --git a/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs b/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs index 567822536d..d0b220e6d0 100644 --- a/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs +++ b/plugins/hls-cabal-gild-plugin/src/Ide/Plugin/CabalGild.hs @@ -1,4 +1,6 @@ +{-# LANGUAGE DataKinds #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} module Ide.Plugin.CabalGild where @@ -8,6 +10,7 @@ import Control.Monad.IO.Class import qualified Data.Text as T import Development.IDE hiding (pluginHandlers) import Ide.Plugin.Error (PluginError (PluginInternalError, PluginInvalidParams)) +import Ide.Plugin.Properties import Ide.PluginUtils import Ide.Types import Language.LSP.Protocol.Types @@ -22,7 +25,7 @@ data Log = LogProcessInvocationFailure Int T.Text | LogReadCreateProcessInfo [String] | LogInvalidInvocationInfo - | LogFormatterBinNotFound + | LogFormatterBinNotFound FilePath deriving (Show) instance Pretty Log where @@ -35,30 +38,41 @@ instance Pretty Log where LogReadCreateProcessInfo args -> "Formatter invocation: cabal-gild " <+> pretty args LogInvalidInvocationInfo -> "Invocation of cabal-gild with range was called but is not supported." - LogFormatterBinNotFound -> "Couldn't find executable 'cabal-gild'" + LogFormatterBinNotFound fp -> "Couldn't find formatter executable 'cabal-gild' at:" <+> pretty fp descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState descriptor recorder plId = (defaultCabalPluginDescriptor plId "Provides formatting of cabal files with cabal-gild") - { pluginHandlers = mkFormattingHandlers (provider recorder) + { pluginHandlers = mkFormattingHandlers (provider recorder plId) + , pluginConfigDescriptor = defaultConfigDescriptor{configCustomConfig = mkCustomConfig properties} } +properties :: Properties '[ 'PropertyKey "path" 'TString] +properties = + emptyProperties + & defineStringProperty + #path + "Set path to 'cabal-gild' executable" + "cabal-gild" + -- | Formatter provider of cabal gild. -- 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 :: Recorder (WithPriority Log) -> FormattingHandler IdeState -provider recorder _ _ (FormatRange _) _ _ _ = do +provider :: Recorder (WithPriority Log) -> PluginId -> FormattingHandler IdeState +provider recorder _ _ _ (FormatRange _) _ _ _ = do logWith recorder Info LogInvalidInvocationInfo throwError $ PluginInvalidParams "You cannot format a text-range using cabal-gild." -provider recorder _ide _ FormatText contents nfp _ = do +provider recorder plId ideState _ FormatText contents nfp _ = do let cabalGildArgs = ["--stdin=" <> fp, "--input=-"] -- < Read from stdin - x <- liftIO $ findExecutable "cabal-gild" + + cabalGildExePath <- fmap T.unpack $ liftIO $ runAction "cabal-gild" ideState $ usePropertyAction #path plId properties + x <- liftIO $ findExecutable cabalGildExePath case x of Just _ -> do log Debug $ LogReadCreateProcessInfo cabalGildArgs (exitCode, out, err) <- liftIO $ Process.readCreateProcessWithExitCode - ( proc "cabal-gild" cabalGildArgs + ( proc cabalGildExePath cabalGildArgs ) { cwd = Just $ takeDirectory fp } @@ -71,8 +85,8 @@ provider recorder _ide _ FormatText contents nfp _ = do let fmtDiff = makeDiffTextEdit contents out pure $ InL fmtDiff Nothing -> do - log Error LogFormatterBinNotFound - throwError (PluginInternalError "No installation of cabal-gild could be found. Please install it into your global environment.") + log Error $ LogFormatterBinNotFound cabalGildExePath + throwError (PluginInternalError "No installation of cabal-gild could be found. Please install it globally, or provide the full path to the executable.") where fp = fromNormalizedFilePath nfp log = logWith recorder diff --git a/test/testdata/schema/ghc92/default-config.golden.json b/test/testdata/schema/ghc92/default-config.golden.json index 5ffe094772..5b1fbef11a 100644 --- a/test/testdata/schema/ghc92/default-config.golden.json +++ b/test/testdata/schema/ghc92/default-config.golden.json @@ -1,4 +1,5 @@ { + "cabalFormattingProvider": "cabal-gild", "checkParents": "CheckOnSave", "checkProject": true, "formattingProvider": "ormolu", @@ -12,6 +13,16 @@ "completionOn": true, "diagnosticsOn": true }, + "cabal-fmt": { + "config": { + "path": "cabal-fmt" + } + }, + "cabal-gild": { + "config": { + "path": "cabal-gild" + } + }, "callHierarchy": { "globalOn": true }, diff --git a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json index f5c4680d5e..027fe77b5a 100644 --- a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json @@ -5,6 +5,18 @@ "scope": "resource", "type": "boolean" }, + "haskell.plugin.cabal-fmt.config.path": { + "default": "cabal-fmt", + "markdownDescription": "Set path to 'cabal-fmt' executable", + "scope": "resource", + "type": "string" + }, + "haskell.plugin.cabal-gild.config.path": { + "default": "cabal-gild", + "markdownDescription": "Set path to 'cabal-gild' executable", + "scope": "resource", + "type": "string" + }, "haskell.plugin.cabal.codeActionsOn": { "default": true, "description": "Enables cabal code actions", diff --git a/test/testdata/schema/ghc94/default-config.golden.json b/test/testdata/schema/ghc94/default-config.golden.json index a214839857..a5a77c9619 100644 --- a/test/testdata/schema/ghc94/default-config.golden.json +++ b/test/testdata/schema/ghc94/default-config.golden.json @@ -1,4 +1,5 @@ { + "cabalFormattingProvider": "cabal-gild", "checkParents": "CheckOnSave", "checkProject": true, "formattingProvider": "ormolu", @@ -12,6 +13,16 @@ "completionOn": true, "diagnosticsOn": true }, + "cabal-fmt": { + "config": { + "path": "cabal-fmt" + } + }, + "cabal-gild": { + "config": { + "path": "cabal-gild" + } + }, "callHierarchy": { "globalOn": true }, diff --git a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json index 9bf9808fa6..d113264901 100644 --- a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json @@ -5,6 +5,18 @@ "scope": "resource", "type": "boolean" }, + "haskell.plugin.cabal-fmt.config.path": { + "default": "cabal-fmt", + "markdownDescription": "Set path to 'cabal-fmt' executable", + "scope": "resource", + "type": "string" + }, + "haskell.plugin.cabal-gild.config.path": { + "default": "cabal-gild", + "markdownDescription": "Set path to 'cabal-gild' executable", + "scope": "resource", + "type": "string" + }, "haskell.plugin.cabal.codeActionsOn": { "default": true, "description": "Enables cabal code actions", diff --git a/test/testdata/schema/ghc96/default-config.golden.json b/test/testdata/schema/ghc96/default-config.golden.json index a214839857..a5a77c9619 100644 --- a/test/testdata/schema/ghc96/default-config.golden.json +++ b/test/testdata/schema/ghc96/default-config.golden.json @@ -1,4 +1,5 @@ { + "cabalFormattingProvider": "cabal-gild", "checkParents": "CheckOnSave", "checkProject": true, "formattingProvider": "ormolu", @@ -12,6 +13,16 @@ "completionOn": true, "diagnosticsOn": true }, + "cabal-fmt": { + "config": { + "path": "cabal-fmt" + } + }, + "cabal-gild": { + "config": { + "path": "cabal-gild" + } + }, "callHierarchy": { "globalOn": true }, diff --git a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json index 9bf9808fa6..d113264901 100644 --- a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json @@ -5,6 +5,18 @@ "scope": "resource", "type": "boolean" }, + "haskell.plugin.cabal-fmt.config.path": { + "default": "cabal-fmt", + "markdownDescription": "Set path to 'cabal-fmt' executable", + "scope": "resource", + "type": "string" + }, + "haskell.plugin.cabal-gild.config.path": { + "default": "cabal-gild", + "markdownDescription": "Set path to 'cabal-gild' executable", + "scope": "resource", + "type": "string" + }, "haskell.plugin.cabal.codeActionsOn": { "default": true, "description": "Enables cabal code actions", diff --git a/test/testdata/schema/ghc98/default-config.golden.json b/test/testdata/schema/ghc98/default-config.golden.json index a214839857..a5a77c9619 100644 --- a/test/testdata/schema/ghc98/default-config.golden.json +++ b/test/testdata/schema/ghc98/default-config.golden.json @@ -1,4 +1,5 @@ { + "cabalFormattingProvider": "cabal-gild", "checkParents": "CheckOnSave", "checkProject": true, "formattingProvider": "ormolu", @@ -12,6 +13,16 @@ "completionOn": true, "diagnosticsOn": true }, + "cabal-fmt": { + "config": { + "path": "cabal-fmt" + } + }, + "cabal-gild": { + "config": { + "path": "cabal-gild" + } + }, "callHierarchy": { "globalOn": true }, diff --git a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json index 9bf9808fa6..d113264901 100644 --- a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json @@ -5,6 +5,18 @@ "scope": "resource", "type": "boolean" }, + "haskell.plugin.cabal-fmt.config.path": { + "default": "cabal-fmt", + "markdownDescription": "Set path to 'cabal-fmt' executable", + "scope": "resource", + "type": "string" + }, + "haskell.plugin.cabal-gild.config.path": { + "default": "cabal-gild", + "markdownDescription": "Set path to 'cabal-gild' executable", + "scope": "resource", + "type": "string" + }, "haskell.plugin.cabal.codeActionsOn": { "default": true, "description": "Enables cabal code actions", From 77a440938abf1061e3ebff009dbd9e696c09f563 Mon Sep 17 00:00:00 2001 From: Fendor Date: Sun, 10 Mar 2024 15:53:47 +0100 Subject: [PATCH 3/3] Fix cabal formatter test flags --- .github/workflows/test.yml | 1 - haskell-language-server.cabal | 2 ++ plugins/hls-cabal-fmt-plugin/test/Main.hs | 6 +++--- plugins/hls-cabal-gild-plugin/test/Main.hs | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67b8d200dd..3586125e57 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -230,7 +230,6 @@ jobs: name: Test hls-cabal-fmt-plugin test suite run: cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests || cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests - ## version needs to be limited since the tests depend on cabal-gild which only builds using specific ghc versions - if: matrix.test name: Test hls-cabal-gild-plugin test suite run: cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests || cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index d0d5b58248..593c9ebe51 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -144,6 +144,7 @@ test-suite hls-cabal-fmt-plugin-tests if flag(isolateCabalfmtTests) build-tool-depends: cabal-fmt:cabal-fmt ^>=0.1.6 + cpp-options: -Dhls_isolate_cabalfmt_tests ----------------------------- -- cabal-gild plugin @@ -194,6 +195,7 @@ test-suite hls-cabal-gild-plugin-tests if flag(isolateCabalGildTests) build-tool-depends: cabal-gild:cabal-gild ^>=1.1 + cpp-options: -Dhls_isolate_cabalgild_tests ----------------------------- -- cabal plugin diff --git a/plugins/hls-cabal-fmt-plugin/test/Main.hs b/plugins/hls-cabal-fmt-plugin/test/Main.hs index 9ad0498f0f..5069a9d153 100644 --- a/plugins/hls-cabal-fmt-plugin/test/Main.hs +++ b/plugins/hls-cabal-fmt-plugin/test/Main.hs @@ -12,7 +12,7 @@ import Test.Hls data CabalFmtFound = Found | NotFound isTestIsolated :: Bool -#if isolateTests +#if hls_isolate_cabalfmt_tests isTestIsolated = True #else isTestIsolated = False @@ -21,7 +21,7 @@ isTestIsolated = False isCabalFmtFound :: IO CabalFmtFound isCabalFmtFound = case isTestIsolated of True -> pure Found - False-> do + False -> do cabalFmt <- findExecutable "cabal-fmt" pure $ maybe NotFound (const Found) cabalFmt @@ -51,7 +51,7 @@ cabalFmtGolden :: CabalFmtFound -> TestName -> FilePath -> FilePath -> (TextDocu cabalFmtGolden NotFound title _ _ _ = testCase title $ assertFailure $ "Couldn't find cabal-fmt on PATH or this is not an isolated run. " - <> "Use cabal flag 'isolateTests' to make it isolated or install cabal-fmt locally." + <> "Use cabal flag 'isolateCabalFmtTests' to make it isolated or install cabal-fmt locally." cabalFmtGolden Found title path desc act = goldenWithCabalDocFormatter def cabalFmtPlugin "cabal-fmt" conf title testDataDir path desc "cabal" act where conf = def diff --git a/plugins/hls-cabal-gild-plugin/test/Main.hs b/plugins/hls-cabal-gild-plugin/test/Main.hs index 5fd6b11967..5bf519c69a 100644 --- a/plugins/hls-cabal-gild-plugin/test/Main.hs +++ b/plugins/hls-cabal-gild-plugin/test/Main.hs @@ -12,7 +12,7 @@ import Test.Hls data CabalGildFound = Found | NotFound isTestIsolated :: Bool -#if isolateTests +#if hls_isolate_cabalgild_tests isTestIsolated = True #else isTestIsolated = False @@ -21,7 +21,7 @@ isTestIsolated = False isCabalFmtFound :: IO CabalGildFound isCabalFmtFound = case isTestIsolated of True -> pure Found - False-> do + False -> do cabalGild <- findExecutable "cabal-gild" pure $ maybe NotFound (const Found) cabalGild @@ -49,7 +49,7 @@ cabalGildGolden :: CabalGildFound -> TestName -> FilePath -> FilePath -> (TextDo cabalGildGolden NotFound title _ _ _ = testCase title $ assertFailure $ "Couldn't find cabal-gild on PATH or this is not an isolated run. " - <> "Use cabal flag 'isolateTests' to make it isolated or install cabal-gild locally." + <> "Use cabal flag 'isolateCabalGildTests' to make it isolated or install cabal-gild locally." cabalGildGolden Found title path desc act = goldenWithCabalDocFormatter def cabalGildPlugin "cabal-gild" conf title testDataDir path desc "cabal" act where conf = def