diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index a6ab03194d..5bddbd349e 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -49,7 +49,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v29 + - uses: cachix/install-nix-action@v30 with: extra_nix_config: | experimental-features = nix-command flakes diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a9469851d3..40d79afbf2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -53,7 +53,7 @@ jobs: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}- ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}- - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v3 - uses: pre-commit/action@v3.0.1 with: extra_args: --files ${{ needs.file-diff.outputs.git-diff }} diff --git a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs index 1a086dbc85..c7569bff72 100644 --- a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs +++ b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs @@ -278,6 +278,8 @@ getDependencyEdit recorder env cabalFilePath buildTarget dependency = do pure edit -- | Given a path to a haskell file, returns the closest cabal file. +-- If a package.yaml is present in same directory as the .cabal file, returns nothing, because adding a dependency to a generated cabal file +-- will break propagation of changes from package.yaml to cabal files in stack projects. -- If cabal file wasn't found, gives Nothing. findResponsibleCabalFile :: FilePath -> IO (Maybe FilePath) findResponsibleCabalFile haskellFilePath = do @@ -293,7 +295,12 @@ findResponsibleCabalFile haskellFilePath = do cabalFiles <- filterM (\c -> doesFileExist c) objectsCabalExtension case safeHead cabalFiles of Nothing -> go ps - Just cabalFile -> pure $ Just cabalFile + Just cabalFile -> guardAgainstHpack path cabalFile + where + guardAgainstHpack :: FilePath -> FilePath -> IO (Maybe FilePath) + guardAgainstHpack path cabalFile = do + exists <- doesFileExist $ path "package.yaml" + if exists then pure Nothing else pure $ Just cabalFile -- | Gives cabal file's contents or throws error. -- Inspired by @readCabalFile@ in cabal-add, diff --git a/plugins/hls-cabal-plugin/test/CabalAdd.hs b/plugins/hls-cabal-plugin/test/CabalAdd.hs index d2804b481c..2f9b16d1b3 100644 --- a/plugins/hls-cabal-plugin/test/CabalAdd.hs +++ b/plugins/hls-cabal-plugin/test/CabalAdd.hs @@ -29,6 +29,8 @@ cabalAddTests = "CabalAdd Tests" [ runHaskellTestCaseSession "Code Actions - Can add hidden package" ("cabal-add-testdata" "cabal-add-exe") (generateAddDependencyTestSession "cabal-add-exe.cabal" ("src" "Main.hs") "split" [253]) + , runHaskellTestCaseSession "Code Actions - Guard against HPack" ("cabal-add-testdata" "cabal-add-packageYaml") + (generatePackageYAMLTestSession ("src" "Main.hs")) , runHaskellTestCaseSession "Code Actions - Can add hidden package to a library" ("cabal-add-testdata" "cabal-add-lib") (generateAddDependencyTestSession "cabal-add-lib.cabal" ("src" "MyLib.hs") "split" [348]) , runHaskellTestCaseSession "Code Actions - Can add hidden package to a test" ("cabal-add-testdata" "cabal-add-tests") @@ -139,3 +141,12 @@ cabalAddTests = , _codeDescription = Nothing , _data_ = Nothing } + + + generatePackageYAMLTestSession :: FilePath -> Session () + generatePackageYAMLTestSession haskellFile = do + hsdoc <- openDoc haskellFile "haskell" + _ <- waitForDiagnosticsFrom hsdoc + cas <- Maybe.mapMaybe (^? _R) <$> getAllCodeActions hsdoc + let selectedCas = filter (\ca -> "Add dependency" `T.isPrefixOf` (ca ^. L.title)) cas + liftIO $ assertEqual "PackageYAML" [] selectedCas diff --git a/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/cabal-add-packageYaml.cabal b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/cabal-add-packageYaml.cabal new file mode 100644 index 0000000000..3ac549aa60 --- /dev/null +++ b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/cabal-add-packageYaml.cabal @@ -0,0 +1,17 @@ +cabal-version: 2.4 +name: cabal-add-packageYaml +version: 0.1.0.0 +license: NONE +author: George Gerasev +maintainer: george30032002@gmail.com +build-type: Simple + +common warnings + ghc-options: -Wall + +benchmark benchmark-packageYaml + type: exitcode-stdio-1.0 + ghc-options: -threaded + main-is: Main.hs + hs-source-dirs: bench + build-depends: base diff --git a/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/package.yaml b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/package.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/src/Main.hs b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/src/Main.hs new file mode 100644 index 0000000000..e5c42398f2 --- /dev/null +++ b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal-add-packageYaml/src/Main.hs @@ -0,0 +1,6 @@ +module Main (main) where + +import Data.List.Split + +main :: IO () +main = putStrLn "Test suite not yet implemented." diff --git a/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal.project b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal.project index dfa2feed39..786cb592de 100644 --- a/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal.project +++ b/plugins/hls-cabal-plugin/test/testdata/cabal-add-testdata/cabal.project @@ -2,3 +2,4 @@ packages: cabal-add-exe cabal-add-lib cabal-add-tests cabal-add-bench + cabal-add-packageYaml